deeply 1.2.0+1
deeply: ^1.2.0+1 copied to clipboard

Modify (update/unset/rename) deeply nested maps by using a keyPath-string to access sub-maps recursively

deeply #

Modify maps

test('update', () {
    Map<dynamic, dynamic> data = {
      "name": {"first": "First", "last": "Last"},
      "birthday": {"day": 11, "month": 2, "year": 1997},
      "config": "test",
    };
    
    data = updateDeeply(["name", "first"], data, (name) => name += " Second");
    data = updateDeeply(["birthday", "month"], data, (month) => ++month);
    data = updateDeeply(["config", "active"], data, (_) => true);
    
    expect(data, {
      "name": {"first": "First Second", "last": "Last"},
      "birthday": {"day": 11, "month": 3, "year": 1997},
      "config": {"active": true},
    });
});

test('remove', () {
    Map<dynamic, dynamic> data = {
      "name": {"first": "First", "last": "Last"},
      "birthday": {"day": 11, "month": 2, "year": 1997},
      "config": "test",
    };
    
    data = removeDeeply(["birthday", "month"], data);
    data = removeDeeply(["name"], data);
    data = removeDeeply(["o", "x"], data);
    
    expect(data, {
      "birthday": {"day": 11, "year": 1997},
      "config": "test",
    });
});

test('rename', () {
    Map<dynamic, dynamic> data = {
      "name": {"first": "First", "last": "Last"},
      "birthday": {"day": 11, "month": 2, "year": 1997},
      "config": "test",
    };
    
    data = renameDeeply(["name"], "Name", data);
    data = renameDeeply(["birthday", "month"], "monat", data);
    data = renameDeeply(["birthday", "month", "toast"], "blub", data);
    data = renameDeeply(["a", "toast"], "o", data);
    
    expect(data, {
      "Name": {"first": "First", "last": "Last"},
      "birthday": {"day": 11, "monat": 2, "year": 1997},
      "config": "test",
    });
});
2
likes
130
pub points
91%
popularity

Modify (update/unset/rename) deeply nested maps by using a keyPath-string to access sub-maps recursively

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

google@marioreggiori.com

License

MIT (LICENSE)

More

Packages that depend on deeply