mask-object

0.2.0 • Public • Published

mask-object NPM version Build Status

Return a copy of an object after applying a key mask.

Install with npm

$ npm i mask-object --save

Usage

var mask = require('mask-object');

API

mask

Return only properties specified in an object mask.

Example

Params

  • obj {Object}: Original source object.
  • mask {Object}: Mask object(s) to use to pick properties off the source.
  • returns {Object}: Masked object with only the properties specified in the mask

Example

var contact = {
  name: 'Brian',
  address: {
    street: '123 Main St.',
    city: 'Cincinnati',
    state: 'OH',
    zip: '45241'
  },
  billing_address: {
    street: '567 Main St.',
    street2: 'Suite #1',
    city: 'Cincinnati',
    state: 'OH',
    zip: '45241'
  }
};

// pull the streets out
console.log(mask(contact, [
  'address.street',
  'address.street2',
  'billing_address.street',
  'billing_address.street2'
]));

//=> {
//=>   address: { street: '123 Main St.' },
//=>   billing_address: { street: '567 Main St.', street2: 'Suite #1' }
//=> }

Related projects

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Brian Woodward

License

Copyright © 2015 Brian Woodward Released under the MIT license.


This file was generated by verb-cli on May 22, 2015.

Readme

Keywords

none

Package Sidebar

Install

npm i mask-object

Weekly Downloads

1

Version

0.2.0

License

MIT

Last publish

Collaborators

  • doowb