unsafe-push
v1.0.0
Published
push to an array at property, create intermediate properties if necessary, clobbering anything in it's way
Downloads
2
Maintainers
Readme
unsafe-push
Unsafely push a value at a property, creating intermediate properties if necessary. If one doesn't exist, or exists but isn't an object, it will become an object. The final property will become an array if it isn't one already, otherwise the value gets pushed to the existing array. Does not support intermediate arrays like lodash.set. Returns the original, modified object.
- tiny
- no dependencies
import push from 'unsafe-push';
let obj = {
a: 'gets clobbered'
}
push(obj, 'a.aa.aaa', 'foo');
push(obj, 'a.aa.aaa', 'bar')
//{a: {aa: {aaa: ['foo','bar']}}}