https://github.com/terran-source/dart-extend
A Dart port of classic extend() method from jQuery. Empower `Map` to be `extend()`-ed
https://github.com/terran-source/dart-extend
dart dart-platform flutter
Last synced: 26 days ago
JSON representation
A Dart port of classic extend() method from jQuery. Empower `Map` to be `extend()`-ed
- Host: GitHub
- URL: https://github.com/terran-source/dart-extend
- Owner: Terran-Source
- License: mit
- Created: 2021-08-16T13:18:04.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-09-14T10:06:37.000Z (over 4 years ago)
- Last Synced: 2024-10-31T21:36:19.778Z (over 1 year ago)
- Topics: dart, dart-platform, flutter
- Language: Dart
- Homepage: https://pub.dev/packages/extend
- Size: 139 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# extend [](https://pub.dev/packages/extend) [](LICENSE)
A Dart port of classic `extend()` method from jQuery. It `extend` an existing Mutable Map with another `source`. It can be extended by multiple additional `sources` in a sequence.
***Beware***: the original Map will be modified and will be returned.
Example:
```Dart
// Don't use `const` or `final`. It'll make the Map `Immutable`
var baseObj = {
'dummy': 'x',
'complex': {
'subKey': 'subValue',
'subComplex': {
'deepKey': 'deepValue',
},
'subUndefined': null
},
'baseUndefined': null
};
final result = baseObj.extend({
'complex': {
'subKey': 'subValueOther',
'subComplex': {'deepNewKey': 'deepNewValue'}
},
'newKey': 'newValue'
});
// beware, the original object is also changed
print(baseObj);
// Hence, you may discard using result
print(result);
// in case, if you have one Immutable Map or don't want to change the
// original Map, try to extend an empty Map
final result = {}.extend(baseObj, [
{
'complex': {
'subKey': 'subValueOther',
'subComplex': {'deepNewKey': 'deepNewValue'}
},
'newKey': 'newValue'
}
]);
print(result);
```
Output:
```Json
{
"dummy": "x",
"complex": {
"subKey": "subValueOther", // 👈 is extended
"subComplex": {
"deepKey": "deepValue", // 👈 remains unchanged
"deepNewKey": "deepNewValue" // 👈 is added
},
"subUndefined": null
},
"baseUndefined": null,
"newKey": "newValue" // 👈 is added
}
```
## Features and bugs
Please file feature requests and bugs at the [issue tracker][tracker].
[tracker]: https://github.com/Terran-Source/dart-extend/issues