Socket
Socket
Sign inDemoInstall

underscore.deep

Package Overview
Dependencies
1
Maintainers
5
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.0 to 0.5.0

test/deepPick.coffee

5

package.json
{
"name": "underscore.deep",
"version": "0.4.0",
"version": "0.5.0",
"description": "Underscore mixins for deeply nested objects",

@@ -22,3 +22,6 @@ "main": "underscore.deep.js",

"mocha": "~1.13.0"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
}
}

31

README.coffee.md

@@ -184,14 +184,14 @@ # underscore.deep

foods =
fruit:
apple: true
orange: true
carrot: true
vegetables:
banana: true
describe '_.deepOmit', ->
obj =
fruit:
apple: true
orange: true
carrot: true
vegetables:
banana: true
it 'returns an object without the given keys', ->
assert.deepEqual _.deepOmit(obj, ['fruit.carrot', 'vegetables']),
assert.deepEqual _.deepOmit(foods, ['fruit.carrot', 'vegetables']),
fruit:

@@ -201,2 +201,15 @@ apple: true

### _.deepPick(obj, keys)
Takes an object and a list of dot-notation keys and returns a new object with only those keys. If you pick a key that has a subobject below it, the entire subobject will be included, regardless of whether its subkeys are also picked.
describe '_.deepPick', ->
it 'returns an object with only the given keys', ->
assert.deepEqual _.deepPick(foods, ['fruit.carrot', 'vegetables']),
fruit:
carrot: true
vegetables:
banana: true
### _.deepExtend(destination, source, mutate = false)

@@ -203,0 +216,0 @@

// Generated by CoffeeScript 1.6.3
var deepClone, deepDelete, deepExtend, deepKeys, deepMapValues, isPlainObject, mapKeys, mapValues, _;
var deepClone, deepDelete, deepExtend, deepFromFlat, deepKeys, deepMapValues, isPlainObject, mapKeys, mapValues, _;

@@ -83,2 +83,31 @@ _ = require('underscore');

},
deepPick: (function() {
var deepGet;
deepGet = function(obj, key) {
var helper;
helper = function(obj, key_arr) {
if (key_arr.length === 1) {
return obj[_.first(key_arr)];
} else {
return helper(obj[_.first(key_arr)], _.rest(key_arr));
}
};
return helper(obj, key.split('.'));
};
return function(obj, keys) {
var flat_new_obj;
if (!isPlainObject(obj)) {
throw new Error("deepPick must be called on an object, not '" + obj + "'");
}
flat_new_obj = _.reduce(keys, function(new_obj, key) {
var val;
val = deepGet(obj, key);
if (val !== void 0) {
new_obj[key] = val;
}
return new_obj;
}, {});
return deepFromFlat(flat_new_obj);
};
})(),
deepDelete: deepDelete = function(obj, key) {

@@ -126,3 +155,3 @@ if ((key == null) || (obj == null)) {

},
deepFromFlat: function(o) {
deepFromFlat: deepFromFlat = function(o) {
var k, key, oo, part, parts, t;

@@ -129,0 +158,0 @@ oo = {};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc