Comparing version 0.2.1 to 0.3.0
30
index.js
'use strict'; | ||
var isObject = require('is-plain-object'); | ||
var forOwn = require('for-own'); | ||
var omit = require('omit-keys'); | ||
var unset = require('unset-value'); | ||
module.exports = function omitDeep(value, props) { | ||
module.exports = function omitDeep(value, keys) { | ||
if (typeof value === 'undefined') { | ||
@@ -14,3 +13,3 @@ return {}; | ||
for (var i = 0; i < value.length; i++) { | ||
value[i] = omitDeep(value[i], props); | ||
value[i] = omitDeep(value[i], keys); | ||
} | ||
@@ -24,8 +23,21 @@ return value; | ||
var o = {}; | ||
forOwn(value, function(val, key) { | ||
o[key] = omitDeep(val, props); | ||
}); | ||
if (typeof keys === 'string') { | ||
keys = [keys]; | ||
} | ||
return omit(o, props); | ||
if (!Array.isArray(keys)) { | ||
return value; | ||
} | ||
for (var j = 0; j < keys.length; j++) { | ||
unset(value, keys[j]); | ||
} | ||
for (var key in value) { | ||
if (value.hasOwnProperty(key)) { | ||
value[key] = omitDeep(value[key], keys); | ||
} | ||
} | ||
return value; | ||
}; |
{ | ||
"name": "omit-deep", | ||
"description": "Recursively omit the specified key or keys from an object.", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/jonschlinkert/omit-deep", | ||
@@ -23,5 +23,4 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"dependencies": { | ||
"for-own": "^0.1.3", | ||
"is-plain-object": "^2.0.1", | ||
"omit-keys": "^0.1.0" | ||
"unset-value": "^0.1.1" | ||
}, | ||
@@ -28,0 +27,0 @@ "devDependencies": { |
@@ -18,6 +18,19 @@ # omit-deep [![NPM version](https://img.shields.io/npm/v/omit-deep.svg?style=flat)](https://www.npmjs.com/package/omit-deep) [![NPM monthly downloads](https://img.shields.io/npm/dm/omit-deep.svg?style=flat)](https://npmjs.org/package/omit-deep) [![NPM total downloads](https://img.shields.io/npm/dt/omit-deep.svg?style=flat)](https://npmjs.org/package/omit-deep) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/omit-deep.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/omit-deep) | ||
omitDeep({a: 'a', b: 'b', c: {b: 'b', d: {b: 'b', f: 'f'}}}); | ||
var obj = {a: 'a', b: 'b', c: {b: 'b', d: {b: 'b', f: 'f'}}}; | ||
console.log(omitDeep(obj, ['b'])); | ||
//=> {a: 'a', c: {d: {f: 'f'}}} | ||
var obj = {a: 'a', b: 'b', c: {b: 'b', d: {b: 'b', f: 'f'}}}; | ||
console.log(omitDeep(obj, ['b', 'f'])); | ||
//=> {a: 'a', c: {d: {}}} | ||
``` | ||
Also works with dot-notation: | ||
```js | ||
var obj = {a: 'a', b: 'b', c: {b: 'b', d: {b: 'b', f: 'f'}}}; | ||
console.log(omitDeep(obj, ['c.d.b', 'f'])); | ||
//=> { a: 'a', b: 'b', c: { b: 'b', d: {} } } | ||
``` | ||
## About | ||
@@ -33,3 +46,3 @@ | ||
| --- | --- | | ||
| 11 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 18 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 2 | [splodingsocks](https://github.com/splodingsocks) | | ||
@@ -36,0 +49,0 @@ | 1 | [rikukissa](https://github.com/rikukissa) | |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5478
2
32
81
+ Addedunset-value@^0.1.1
+ Addedget-value@2.0.6(transitive)
+ Addedhas-value@0.3.1(transitive)
+ Addedhas-values@0.1.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisobject@2.1.0(transitive)
+ Addedunset-value@0.1.2(transitive)
- Removedfor-own@^0.1.3
- Removedomit-keys@^0.1.0
- Removedarray-difference@0.0.1(transitive)
- Removedfor-in@1.0.2(transitive)
- Removedfor-own@0.1.5(transitive)
- Removedisobject@0.2.0(transitive)
- Removedomit-keys@0.1.0(transitive)