parsley 0.1.0 parsley: ^0.1.0 copied to clipboard
A simple but powerful parsing engine
parsley #
Is your domain logic littered with parsing?
Parsley is a simple but powerful parsing engine that uses inferences to automatically find the correct parser for the required input / output.
Getting Started #
Simply import the package into your project and forget about parsing forever!
parse(value); // to parse registerHandler(parsingFunction); // registers custom parser
Example #
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
USD convertEuroToUSD(Euro euro){
return USD(euro.value * 1.1);
}
Euro convertUSDToEuro(USD usd){
return Euro(usd.value * 0.85);
}
parsely.registerHandler(convertEuroToUSD);
parsely.registerHandler(convertUSDToEuro);
USD usd = USD(15);
Euro euro = parse(usd);
print(euro);
}
class USD{
final double value;
USD(this.value);
}
class Euro{
final double value;
Euro(this.value);
}