mask-object
Return a copy of an object after applying a key mask.
Last updated 5 years ago by doowb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install mask-object 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 0.2.0                                ...           latest (5 years ago)

3 Versions

  • 0.2.0                                ...           5 years ago
  • 0.1.1                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (1)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |