mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 16:17:50 +00:00
Add deep functionality for _.omit and _.pick. (#2794)
This commit is contained in:
committed by
John-David Dalton
parent
6d951ccc87
commit
9ac729e1bc
@@ -3757,7 +3757,7 @@
|
||||
function basePick(object, props) {
|
||||
object = Object(object);
|
||||
return basePickBy(object, props, function(value, key) {
|
||||
return key in object;
|
||||
return hasIn(object, key);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3777,10 +3777,10 @@
|
||||
|
||||
while (++index < length) {
|
||||
var key = props[index],
|
||||
value = object[key];
|
||||
value = get(object, key);
|
||||
|
||||
if (predicate(value, key)) {
|
||||
baseAssignValue(result, key, value);
|
||||
set(result, key, value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
12
test/test.js
12
test/test.js
@@ -16386,6 +16386,12 @@
|
||||
|
||||
assert.deepEqual(_.omit({ '0': 'a' }, 0), {});
|
||||
});
|
||||
|
||||
QUnit.test('should work with deep properties', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
assert.deepEqual(_.omit({ 'a': 1, 'b': { 'c': 2 } }, 'b.c'), { 'a': 1, 'b': {} });
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@@ -17608,6 +17614,12 @@
|
||||
|
||||
assert.deepEqual(_.pick({ '0': 'a', '1': 'b' }, 0), { '0': 'a' });
|
||||
});
|
||||
|
||||
QUnit.test('should work with deep properties', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
assert.deepEqual(_.pick({ 'a': 1, 'b': { 'c': 2 } }, 'b.c'), { 'b': { 'c': 2 } });
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user