nested-object-mask
v0.1.5
Published
Like object-mask, but nested
Downloads
28
Readme
nested-object-mask (NOM)
Like
object-mask
, but nested
Note: This library contains a rich nested object masking implementation, and
has more complicated semantics than similar libraries for flat object masking.
If you do not specifically need the nesting support from this library, try
object-mask
instead for a simpler mental model.
Although the API is fairly simple, this module is well tested and thoroughly documented.
Installation Instructions
Install the module via npm: npm install --save nested-object-mask
Usage
NB: nested-object-mask
works happily with plain JS, but it is written in coffeescript, and so are the examples below (because it's 2015).
Basic
At its simplest, nested-object-mask
does this:
# the hero of our story
masker = require 'nested-object-mask'
# the source object we'd like to mask
object =
keepThisKey: 'some value'
dontKeepThisKey: 'good bye :<'
# a mask that determines which keys will be kept from the original object. if a
# property has a truthy value in the mask, it is kept from the original object
mask =
keepThisKey: true
# our result should look like this
expected =
keepThisKey: 'some value'
# do the thing!
result = masker.mask object, mask
# looks good :)
assert.deepEqual result, expected
License
This software is licensed under the MIT License. See the LICENSE file for more information.