Last updated:
0 purchases
retriever
To safely and easily retrieve values from a map/json with useful and human friendly error messages. With little to no effort you can parse and guarantee the values type.
Features #
Retriever has 2 main features when parsing values from a map:
1. Automatic error treatment:
// This method will throw an error if the value is invalid
Retriever.getString('key', map);
// This method will return null if the value is invalid
Retriever.getMaybeString('key', map);
copied to clipboard
2. Errors that realy help
RetrieverFormatError: Found invalid format when parsing key.
Key: "name"
Expected: "Integer"
Found: "String", value: "myExampleName".
Object: "{
--> name: myExampleName
^^^^
age: 40
}"
copied to clipboard
With retriever you can safely parse:
String
Integer
Double
Date
Map
Getting started #
Retriever has no dependencies other than dart it self, and all methods are static. This makes easy and performant to use.
Usage #
Giving the following map.
final map = {
'name': 'myExampleName',
'age': 40,
};
copied to clipboard
You can retrieve a string from a Map, just like that.
final string = Retriever.getString('name', map);
print(string); // 'myExampleName'
copied to clipboard
If the key doesn't exist or the value is not a valid, an error will be thrown.
The errors are very helpful and human readable, showing exactly what's going on.
// Using getString on a "int" value will throw the following error
Retriever.getString('age', map); // 'age' is a int. error will be thrown
// RetrieverFormatError: Found invalid format when parsing key.
// Key: "name"
// Expected: "Integer"
// Found: "String", value: "myExampleName".
// Object: "{
// --> name: myExampleName
// ^^^^
// age: 40
// }"
copied to clipboard
Additional information #
Feel free to file an issue if you find a problem or make pull requests.
All contributions are welcome :)
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.