1.0.0 • Published 4 years ago

unsafe-push v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

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']}}}