0 purchases
dot prop
Get, set, or delete a property from a nested object using a dot path.
This is the Dart implementation of dot-prop.
Getting started #
import 'package:dot_prop/dot_prop.dart';
void main() {
final data = {
'user': {'name': 'foo'}
};
getProperty(data, 'user.name'); // => 'foo'
hasProperty(data, 'user.name'); // => true
setProperty(data, 'user.name', 'newname');
getProperty(data, 'user.name'); // => 'newname'
deleteProperty(data, 'user.name');
hasProperty(data, 'user.name'); // => false
getProperty(data, 'user.name'); // => null
}
copied to clipboard
Usage #
If location of path doesn't exist, it will created.
final root = <String, dynamic>{};
const key = 'foo.bar.abc';
setProperty(root, key, 1);
expect(root['foo']['bar']['abc'], equals(1));
expect(getProperty(root, key, defaultValue), equals(1));
copied to clipboard
array #
Arrays can be accessed using [index] notation.
final root = <dynamic>[];
setProperty(root, '[0].foo[0]', true);
expect(root[0]['foo'][0], true);
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.