parsley

Simplifies your code by unifying all parsing logic into a single simple call.

Easily extendable by enabling you to register your own custom parsing functions.

import 'package:parsley/parsley.dart';

void main() {
  DateTime date = parse("2020-02-12");
  int textToInt = parse("5");           // 5
  bool textToBool = parse("true");      // true
  int stringToInt = parse("5");         // 5
  String intToString = parse(5);        // "5"
  bool intToBool = parse(1);            // true
  int doubleToInt = parse(5.5);         // 5
  double stringToDouble = parse("5.5"); // 5.5
  List<String> intToStringList = parse([1, 8, 3]); // ['1', '8', '3']
  List<int> StringListToIntList = parse(["1", "8", "3"]);
}

Register Custom Parsers

class USD {
  final double value;
  USD(this.value);
}

class Euro {
  final double value;
  Euro(this.value);
}

// Custom parsing functions
USD convertEuroToUSD(Euro euro){
    return USD(euro.value * 1.1);
}

Euro convertUSDToEuro(USD usd){
    return Euro(usd.value * 0.85);
}

void main() {

    // register the custom parsers
    parsely.registerHandler(convertEuroToUSD);
    parsely.registerHandler(convertUSDToEuro);
    USD usd = USD(15);
    Euro euro = parse(usd);
}

Libraries

parse_bool_to_double
parse_bool_to_int
parse_bool_to_string
parse_datetime_to_string
parse_double_to_bool
parse_double_to_int
parse_double_to_string
parse_int_list_to_string_list
parse_int_to_bool
parse_int_to_double
parse_int_to_list
parse_int_to_string
parse_string_list_to_int_list
parse_string_to_bool
parse_string_to_double
parse_string_to_int
parsely
string_to_date