get-or-create
v0.1.2
Published
A simple utility to get or create nested property and element in place.
Downloads
2
Readme
Get or Create
A simple utility to get or create nested property and element in place.
Install
yarn add get-or-create
Usage
import getOrCreate from 'get-or-create';
let data = {};
let entry = getOrCreate(data)
.property('foo', [])
.element(element => element.id === 'abc', {id: 'abc'})
.property('bar', [])
.element(element => element.id === 'def', {id: 'def'})
.exec();
entry.value = 123;
Mutated data
:
{
"foo": [
{
"id": "abc",
"bar": [
{
"id": "def",
"value": 123
}
]
}
]
}
License
MIT License.