mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
Simplify _.omit and _.pick for the lodash underscore build.
Former-commit-id: 9a42c964ce4003bde1b4ce55f0f851141dbc9bb6
This commit is contained in:
39
build.js
39
build.js
@@ -70,7 +70,7 @@
|
|||||||
'clone': ['extend', 'forEach', 'forOwn', 'isArguments', 'isPlainObject'],
|
'clone': ['extend', 'forEach', 'forOwn', 'isArguments', 'isPlainObject'],
|
||||||
'compact': [],
|
'compact': [],
|
||||||
'compose': [],
|
'compose': [],
|
||||||
'contains': ['some'],
|
'contains': ['indexOf', 'some'],
|
||||||
'countBy': ['forEach'],
|
'countBy': ['forEach'],
|
||||||
'debounce': [],
|
'debounce': [],
|
||||||
'defaults': ['isArguments'],
|
'defaults': ['isArguments'],
|
||||||
@@ -975,6 +975,7 @@
|
|||||||
if (isUnderscore) {
|
if (isUnderscore) {
|
||||||
dependencyMap.isEqual = ['isArray', 'isFunction'];
|
dependencyMap.isEqual = ['isArray', 'isFunction'];
|
||||||
dependencyMap.isEmpty = ['isArray', 'isString'];
|
dependencyMap.isEmpty = ['isArray', 'isString'];
|
||||||
|
dependencyMap.pick = [];
|
||||||
|
|
||||||
if (useUnderscoreClone) {
|
if (useUnderscoreClone) {
|
||||||
dependencyMap.clone = ['extend', 'isArray'];
|
dependencyMap.clone = ['extend', 'isArray'];
|
||||||
@@ -1132,6 +1133,39 @@
|
|||||||
' }'
|
' }'
|
||||||
].join('\n'));
|
].join('\n'));
|
||||||
|
|
||||||
|
// replace `_.omit`
|
||||||
|
source = source.replace(/^( +)function omit[\s\S]+?\n\1}/m, [
|
||||||
|
' function omit(object) {',
|
||||||
|
' var props = concat.apply(ArrayProto, arguments),',
|
||||||
|
' result = {};',
|
||||||
|
'',
|
||||||
|
' forIn(object, function(value, key) {',
|
||||||
|
' if (indexOf(props, key, 1) < 0) {',
|
||||||
|
' result[key] = value;',
|
||||||
|
' }',
|
||||||
|
' });',
|
||||||
|
' return result;',
|
||||||
|
' }'
|
||||||
|
].join('\n'));
|
||||||
|
|
||||||
|
// replace `_.pick`
|
||||||
|
source = source.replace(/^( +)function pick[\s\S]+?\n\1}/m, [
|
||||||
|
' function pick(object) {',
|
||||||
|
' var index = 0,',
|
||||||
|
' props = concat.apply(ArrayProto, arguments),',
|
||||||
|
' length = props.length,',
|
||||||
|
' result = {};',
|
||||||
|
'',
|
||||||
|
' while (++index < length) {',
|
||||||
|
' var prop = props[index];',
|
||||||
|
' if (prop in object) {',
|
||||||
|
' result[prop] = object[prop];',
|
||||||
|
' }',
|
||||||
|
' }',
|
||||||
|
' return result;',
|
||||||
|
' }'
|
||||||
|
].join('\n'));
|
||||||
|
|
||||||
// replace `_.without`
|
// replace `_.without`
|
||||||
source = source.replace(/^( +)function without[\s\S]+?\n\1}/m, [
|
source = source.replace(/^( +)function without[\s\S]+?\n\1}/m, [
|
||||||
' function without(array) {',
|
' function without(array) {',
|
||||||
@@ -1149,6 +1183,9 @@
|
|||||||
' }'
|
' }'
|
||||||
].join('\n'));
|
].join('\n'));
|
||||||
|
|
||||||
|
// remove string support from `_.contains`
|
||||||
|
source = source.replace(/return *\(toString\.call.+?stringClass[\s\S]+?;/, 'return indexOf(collection, target) > -1;');
|
||||||
|
|
||||||
// replace `arrayLikeClasses` in `_.isEqual`
|
// replace `arrayLikeClasses` in `_.isEqual`
|
||||||
source = source.replace(/(?: *\/\/.*\n)*( +)var isArr *= *arrayLikeClasses[^}]+}/, '$1var isArr = isArray(a);');
|
source = source.replace(/(?: *\/\/.*\n)*( +)var isArr *= *arrayLikeClasses[^}]+}/, '$1var isArr = isArray(a);');
|
||||||
|
|
||||||
|
|||||||
@@ -639,6 +639,13 @@
|
|||||||
object = { 'fn': lodash.bind(function(x) { return this.x + x; }, { 'x': 1 }, 1) };
|
object = { 'fn': lodash.bind(function(x) { return this.x + x; }, { 'x': 1 }, 1) };
|
||||||
equal(object.fn(), 2, '_.bind: ' + basename);
|
equal(object.fn(), 2, '_.bind: ' + basename);
|
||||||
|
|
||||||
|
object = { 'a': 1, 'b': 2, 'c': 3 };
|
||||||
|
var actual = lodash.omit(object, function(value) { return value == 3; });
|
||||||
|
deepEqual(_.keys(actual).sort(), ['a', 'b', 'c'], '_.omit: ' + basename);
|
||||||
|
|
||||||
|
actual = lodash.pick(object, function(value) { return value != 3; });
|
||||||
|
deepEqual(_.keys(actual), [], '_.pick: ' + basename);
|
||||||
|
|
||||||
ok(lodash.clone(array, true)[0] === array[0], '_.clone: ' + basename);
|
ok(lodash.clone(array, true)[0] === array[0], '_.clone: ' + basename);
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1499,7 +1499,7 @@
|
|||||||
|
|
||||||
equal(compiled(data), '1');
|
equal(compiled(data), '1');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should work when passing `options.variable`', function() {
|
test('should work when passing `options.variable`', function() {
|
||||||
var compiled = _.template(
|
var compiled = _.template(
|
||||||
'<% _.forEach( data.a, function( value ) { %>' +
|
'<% _.forEach( data.a, function( value ) { %>' +
|
||||||
|
|||||||
Reference in New Issue
Block a user