@magic/deep
v0.1.16
Published
manipulate nested objects and arrays
Downloads
1,584
Readme
@magic/deep
Work with deeply nested objects and arrays.
install
npm i --save --save-exact @magic/deep
import
// single function
import { equal, flatten, loop, merge } from '@magic/deep'
// object with all functions
import deep from '@magic/deep'
Currently implemented:
deep.equal
// test equality
deep.equal(['shallow', ['deep']], ['shallow', ['deep']])
// true
// alias
deep.equals, deep.eq
deep.different
// test difference
deep.different(['shallow', ['deep']], ['shallow', ['deep']])
// false
// alias
deep.diff
deep.flatten
// flatten a deeply nested array
deep.flatten(['shallow', ['deep']])
// ['shallow', 'deep']
deep.loop
// apply function add
const add = e => e + 1
// for each item
const items = [1, 2, [3]]
// using a deeply nested array
deep.loop(add, items)
// or
deep.loop(items, add)
// returns [2, 3, [4]]
deep.merge
// merge objects and arrays, with infinite recursion if needed.
// this can be slow...
deep.merge({ obj1Key: { val: 1 } }, { obj2Key: { val: 2 } })
// { obj1Key: { val: 1}, obj2Key: { val: 2 } }
deep.merge({ key: { val: 1, str: 'test' } }, { key: { val: 2, str: 'overwritten' } })
// { key: { val: 2, str: 'overwritten' } }
Changelog
0.1.0
use ecmascript modules instead of commonjs.
0.1.1
- update readme
- also export deep.eq alias for deep.equal
0.1.2
- require node 13.5.0
- use deep.equal and deep.different from @magic/types
0.1.3
bump required node version to 14.2.0
0.1.4
update dependencies
0.1.5
- bump required node version to 14.15.4
- update dependencies
0.1.6
- merge now checks if o2.hasOwnProperty is a function before using it to check if we should overwrite keys of o1 or not.
0.1.7
update @magic/types to avoid circular dependency
0.1.8
- update dependencies
- use @magic/types for all type comparisons
0.1.9
update dependencies
0.1.10
update dependencies
0.1.11
update dependencies
0.1.12
update dependencies
0.0.13
update dependencies
0.0.14
update dependencies
0.0.15
update dependencies
0.0.16
update dependencies
0.0.17 - unreleased
...