npm.io
2.0.0 • Published 3 years ago

strip-keys

Licence
—
Version
2.0.0
Deps
0
Size
6 kB
Vulns
0
Weekly
0
Stars
1

Strip Keys

An utility for removing specific keys from an object.

Install

npm install --save strip-keys

Usage

import stripKeys from 'strip-keys';

const obj = {
  foo: true,
  secret: '1234',
  sub: {
    bar: true,
    secret: 'password'
  }
};

stripKeys ( obj, 'secret' ); // { foo: true, sub: { bar: true } }
stripKeys ( obj, 'secret', false ); // { foo: true, sub: { bar: true, secret: 'password' } }
stripKeys ( obj, ['secret', 'bar'] ); // { foo: true, sub: {} }

API

stripKeys ( obj, keys: string | string[], deep: boolean = true )

Removes a key, or an array of keys, deeply or not, from an object, without mutating the original object.

License

MIT Fabio Spampinato

Keywords