parsley 0.1.5
parsley: ^0.1.5

Dart native js
Flutter Android iOS web

A simple but powerful parsing engine

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);
}
3
likes
70
pub points
46%
popularity

A simple but powerful parsing engine

Homepage

Documentation

API reference

Uploader

jeromesaltmarsh@gmail.com

License

BSD (LICENSE)

More

Packages that depend on parsley