dot_prop 1.0.1 copy "dot_prop: ^1.0.1" to clipboard
dot_prop: ^1.0.1 copied to clipboard

Get, set, or delete a property from a nested object using a dot path.

pub package

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
}

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));

array #

Arrays can be accessed using [index] notation.

final root = <dynamic>[];

setProperty(root, '[0].foo[0]', true);
expect(root[0]['foo'][0], true);
2
likes
160
points
29
downloads

Publisher

unverified uploader

Weekly Downloads

Get, set, or delete a property from a nested object using a dot path.

Repository (GitHub)

Topics

#dot-prop #dot-path #dot-notation

Documentation

API reference

License

MIT (license)

Dependencies

characters

More

Packages that depend on dot_prop