mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
Make _.drop an alias of _.rest and rename _.zipObject to _.object.
Former-commit-id: 08cb9ec2d5009b9a9f959b2341f8b78f6bbd37a0
This commit is contained in:
17
build.js
17
build.js
@@ -81,6 +81,7 @@
|
|||||||
'any': 'some',
|
'any': 'some',
|
||||||
'collect': 'map',
|
'collect': 'map',
|
||||||
'detect': 'find',
|
'detect': 'find',
|
||||||
|
'drop': 'rest',
|
||||||
'each': 'forEach',
|
'each': 'forEach',
|
||||||
'foldl': 'reduce',
|
'foldl': 'reduce',
|
||||||
'foldr': 'reduceRight',
|
'foldr': 'reduceRight',
|
||||||
@@ -88,7 +89,6 @@
|
|||||||
'include': 'contains',
|
'include': 'contains',
|
||||||
'inject': 'reduce',
|
'inject': 'reduce',
|
||||||
'methods': 'functions',
|
'methods': 'functions',
|
||||||
'omit': 'drop',
|
|
||||||
'select': 'filter',
|
'select': 'filter',
|
||||||
'tail': 'rest',
|
'tail': 'rest',
|
||||||
'take': 'first',
|
'take': 'first',
|
||||||
@@ -98,7 +98,6 @@
|
|||||||
/** Used to associate real names with their aliases */
|
/** Used to associate real names with their aliases */
|
||||||
var realToAliasMap = {
|
var realToAliasMap = {
|
||||||
'contains': ['include'],
|
'contains': ['include'],
|
||||||
'drop': ['omit'],
|
|
||||||
'every': ['all'],
|
'every': ['all'],
|
||||||
'filter': ['select'],
|
'filter': ['select'],
|
||||||
'find': ['detect'],
|
'find': ['detect'],
|
||||||
@@ -108,7 +107,7 @@
|
|||||||
'map': ['collect'],
|
'map': ['collect'],
|
||||||
'reduce': ['foldl', 'inject'],
|
'reduce': ['foldl', 'inject'],
|
||||||
'reduceRight': ['foldr'],
|
'reduceRight': ['foldr'],
|
||||||
'rest': ['tail'],
|
'rest': ['drop', 'tail'],
|
||||||
'some': ['any'],
|
'some': ['any'],
|
||||||
'uniq': ['unique']
|
'uniq': ['unique']
|
||||||
};
|
};
|
||||||
@@ -174,7 +173,6 @@
|
|||||||
'defer': [],
|
'defer': [],
|
||||||
'delay': [],
|
'delay': [],
|
||||||
'difference': ['indexOf'],
|
'difference': ['indexOf'],
|
||||||
'drop': ['indexOf', 'isArguments'],
|
|
||||||
'escape': [],
|
'escape': [],
|
||||||
'every': ['identity'],
|
'every': ['identity'],
|
||||||
'extend': ['isArguments'],
|
'extend': ['isArguments'],
|
||||||
@@ -219,6 +217,8 @@
|
|||||||
'min': [],
|
'min': [],
|
||||||
'mixin': ['forEach', 'functions'],
|
'mixin': ['forEach', 'functions'],
|
||||||
'noConflict': [],
|
'noConflict': [],
|
||||||
|
'object': [],
|
||||||
|
'omit': ['indexOf', 'isArguments'],
|
||||||
'once': [],
|
'once': [],
|
||||||
'partial': [],
|
'partial': [],
|
||||||
'pick': [],
|
'pick': [],
|
||||||
@@ -247,8 +247,7 @@
|
|||||||
'where': ['forIn'],
|
'where': ['forIn'],
|
||||||
'without': ['indexOf'],
|
'without': ['indexOf'],
|
||||||
'wrap': [],
|
'wrap': [],
|
||||||
'zip': ['max', 'pluck'],
|
'zip': ['max', 'pluck']
|
||||||
'zipObject': []
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Used to `iteratorTemplate` */
|
/** Used to `iteratorTemplate` */
|
||||||
@@ -281,14 +280,14 @@
|
|||||||
|
|
||||||
var underscoreMethods = lodash.without.apply(lodash, [allMethods].concat([
|
var underscoreMethods = lodash.without.apply(lodash, [allMethods].concat([
|
||||||
'countBy',
|
'countBy',
|
||||||
'drop',
|
|
||||||
'forIn',
|
'forIn',
|
||||||
'forOwn',
|
'forOwn',
|
||||||
'merge',
|
'merge',
|
||||||
|
'object',
|
||||||
|
'omit',
|
||||||
'partial',
|
'partial',
|
||||||
'unescape',
|
'unescape',
|
||||||
'where',
|
'where'
|
||||||
'zipObject'
|
|
||||||
]));
|
]));
|
||||||
|
|
||||||
/** Used to specify whether filtering is for exclusion or inclusion */
|
/** Used to specify whether filtering is for exclusion or inclusion */
|
||||||
|
|||||||
@@ -187,6 +187,7 @@
|
|||||||
'min',
|
'min',
|
||||||
'mixin',
|
'mixin',
|
||||||
'noConflict',
|
'noConflict',
|
||||||
|
'object',
|
||||||
'omit',
|
'omit',
|
||||||
'once',
|
'once',
|
||||||
'opera',
|
'opera',
|
||||||
@@ -227,8 +228,7 @@
|
|||||||
'where',
|
'where',
|
||||||
'without',
|
'without',
|
||||||
'wrap',
|
'wrap',
|
||||||
'zip',
|
'zip'
|
||||||
'zipObject'
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|||||||
186
lodash.js
186
lodash.js
@@ -516,25 +516,6 @@
|
|||||||
'(hasOwnProperty.call(result, prop) ? result[prop]++ : result[prop] = 1)'
|
'(hasOwnProperty.call(result, prop) ? result[prop]++ : result[prop] = 1)'
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Reusable iterator options for `drop` and `pick` */
|
|
||||||
var dropIteratorOptions = {
|
|
||||||
'useHas': false,
|
|
||||||
'args': 'object, callback, thisArg',
|
|
||||||
'init': '{}',
|
|
||||||
'top':
|
|
||||||
'var isFunc = typeof callback == \'function\';\n' +
|
|
||||||
'if (!isFunc) {\n' +
|
|
||||||
' var props = concat.apply(ArrayProto, arguments)\n' +
|
|
||||||
'} else if (thisArg) {\n' +
|
|
||||||
' callback = iteratorBind(callback, thisArg)\n' +
|
|
||||||
'}',
|
|
||||||
'inLoop':
|
|
||||||
'if (isFunc\n' +
|
|
||||||
' ? !callback(value, index, object)\n' +
|
|
||||||
' : indexOf(props, index) < 0\n' +
|
|
||||||
') result[index] = value'
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Reusable iterator options for `every` and `some` */
|
/** Reusable iterator options for `every` and `some` */
|
||||||
var everyIteratorOptions = {
|
var everyIteratorOptions = {
|
||||||
'init': 'true',
|
'init': 'true',
|
||||||
@@ -586,6 +567,25 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Reusable iterator options for `omit` and `pick` */
|
||||||
|
var omitIteratorOptions = {
|
||||||
|
'useHas': false,
|
||||||
|
'args': 'object, callback, thisArg',
|
||||||
|
'init': '{}',
|
||||||
|
'top':
|
||||||
|
'var isFunc = typeof callback == \'function\';\n' +
|
||||||
|
'if (!isFunc) {\n' +
|
||||||
|
' var props = concat.apply(ArrayProto, arguments)\n' +
|
||||||
|
'} else if (thisArg) {\n' +
|
||||||
|
' callback = iteratorBind(callback, thisArg)\n' +
|
||||||
|
'}',
|
||||||
|
'inLoop':
|
||||||
|
'if (isFunc\n' +
|
||||||
|
' ? !callback(value, index, object)\n' +
|
||||||
|
' : indexOf(props, index) < 0\n' +
|
||||||
|
') result[index] = value'
|
||||||
|
};
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1172,34 +1172,6 @@
|
|||||||
'inLoop': 'if (result[index] == null) ' + extendIteratorOptions.inLoop
|
'inLoop': 'if (result[index] == null) ' + extendIteratorOptions.inLoop
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a shallow clone of `object` excluding the specified properties.
|
|
||||||
* Property names may be specified as individual arguments or as arrays of
|
|
||||||
* property names. If `callback` is passed, it will be executed for each property
|
|
||||||
* in the `object`, dropping the properties `callback` returns truthy for. The
|
|
||||||
* `callback` is bound to `thisArg` and invoked with 3 arguments; (value, key, object).
|
|
||||||
*
|
|
||||||
* @static
|
|
||||||
* @memberOf _
|
|
||||||
* @alias omit
|
|
||||||
* @category Objects
|
|
||||||
* @param {Object} object The source object.
|
|
||||||
* @param {Function|String} callback|[prop1, prop2, ...] The properties to drop
|
|
||||||
* or the function called per iteration.
|
|
||||||
* @param {Mixed} [thisArg] The `this` binding for the callback.
|
|
||||||
* @returns {Object} Returns an object without the dropped properties.
|
|
||||||
* @example
|
|
||||||
*
|
|
||||||
* _.drop({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'userid');
|
|
||||||
* // => { 'name': 'moe', 'age': 40 }
|
|
||||||
*
|
|
||||||
* _.drop({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(value, key) {
|
|
||||||
* return key.charAt(0) == '_';
|
|
||||||
* });
|
|
||||||
* // => { 'name': 'moe' }
|
|
||||||
*/
|
|
||||||
var drop = createIterator(dropIteratorOptions);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assigns enumerable properties of the source object(s) to the `destination`
|
* Assigns enumerable properties of the source object(s) to the `destination`
|
||||||
* object. Subsequent sources will overwrite propery assignments of previous
|
* object. Subsequent sources will overwrite propery assignments of previous
|
||||||
@@ -1834,6 +1806,53 @@
|
|||||||
'}'
|
'}'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a shallow clone of `object` excluding the specified properties.
|
||||||
|
* Property names may be specified as individual arguments or as arrays of
|
||||||
|
* property names. If `callback` is passed, it will be executed for each property
|
||||||
|
* in the `object`, omitting the properties `callback` returns truthy for. The
|
||||||
|
* `callback` is bound to `thisArg` and invoked with 3 arguments; (value, key, object).
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf _
|
||||||
|
* @category Objects
|
||||||
|
* @param {Object} object The source object.
|
||||||
|
* @param {Function|String} callback|[prop1, prop2, ...] The properties to omit
|
||||||
|
* or the function called per iteration.
|
||||||
|
* @param {Mixed} [thisArg] The `this` binding for the callback.
|
||||||
|
* @returns {Object} Returns an object without the omitted properties.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* _.omit({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'userid');
|
||||||
|
* // => { 'name': 'moe', 'age': 40 }
|
||||||
|
*
|
||||||
|
* _.omit({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(value, key) {
|
||||||
|
* return key.charAt(0) == '_';
|
||||||
|
* });
|
||||||
|
* // => { 'name': 'moe' }
|
||||||
|
*/
|
||||||
|
var omit = createIterator(omitIteratorOptions);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a two dimensional array of the given object's key-value pairs,
|
||||||
|
* i.e. `[[key1, value1], [key2, value2]]`.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf _
|
||||||
|
* @category Objects
|
||||||
|
* @param {Object} object The object to inspect..
|
||||||
|
* @returns {Array} Returns new array of key-value pairs.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* _.pairs({ 'moe': 30, 'larry': 40, 'curly': 50 });
|
||||||
|
* // => [['moe', 30], ['larry', 40], ['curly', 50]] (order is not guaranteed)
|
||||||
|
*/
|
||||||
|
var pairs = createIterator({
|
||||||
|
'args': 'object',
|
||||||
|
'init':'[]',
|
||||||
|
'inLoop': 'result.push([index, value])'
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a shallow clone of `object` composed of the specified properties.
|
* Creates a shallow clone of `object` composed of the specified properties.
|
||||||
* Property names may be specified as individual arguments or as arrays of
|
* Property names may be specified as individual arguments or as arrays of
|
||||||
@@ -2864,6 +2883,41 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an object composed from arrays of `keys` and `values`. Pass either
|
||||||
|
* a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or
|
||||||
|
* two arrays, one of `keys` and one of corresponding `values`.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf _
|
||||||
|
* @category Arrays
|
||||||
|
* @param {Array} keys The array of keys.
|
||||||
|
* @param {Array} [values=[]] The array of values.
|
||||||
|
* @returns {Object} Returns an object composed of the given keys and
|
||||||
|
* corresponding values.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* _.object(['moe', 'larry', 'curly'], [30, 40, 50]);
|
||||||
|
* // => { 'moe': 30, 'larry': 40, 'curly': 50 }
|
||||||
|
*/
|
||||||
|
function object(keys, values) {
|
||||||
|
if (!keys) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
var index = -1,
|
||||||
|
length = keys.length,
|
||||||
|
result = {};
|
||||||
|
|
||||||
|
while (++index < length) {
|
||||||
|
if (values) {
|
||||||
|
result[keys[index]] = values[index];
|
||||||
|
} else {
|
||||||
|
result[keys[index][0]] = keys[index][1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array of numbers (positive and/or negative) progressing from
|
* Creates an array of numbers (positive and/or negative) progressing from
|
||||||
* `start` up to but not including `stop`. This method is a port of Python's
|
* `start` up to but not including `stop`. This method is a port of Python's
|
||||||
@@ -2920,7 +2974,7 @@
|
|||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @alias tail
|
* @alias drop, tail
|
||||||
* @category Arrays
|
* @category Arrays
|
||||||
* @param {Array} array The array to query.
|
* @param {Array} array The array to query.
|
||||||
* @param {Number} [n] The number of elements to return.
|
* @param {Number} [n] The number of elements to return.
|
||||||
@@ -3186,36 +3240,6 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an object composed from an array of `keys` and an array of `values`.
|
|
||||||
*
|
|
||||||
* @static
|
|
||||||
* @memberOf _
|
|
||||||
* @category Arrays
|
|
||||||
* @param {Array} keys The array of keys.
|
|
||||||
* @param {Array} [values=[]] The array of values.
|
|
||||||
* @returns {Object} Returns an object composed of the given keys and
|
|
||||||
* corresponding values.
|
|
||||||
* @example
|
|
||||||
*
|
|
||||||
* _.zipObject(['moe', 'larry', 'curly'], [30, 40, 50]);
|
|
||||||
* // => { 'moe': 30, 'larry': 40, 'curly': 50 }
|
|
||||||
*/
|
|
||||||
function zipObject(keys, values) {
|
|
||||||
if (!keys) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
var index = -1,
|
|
||||||
length = keys.length,
|
|
||||||
result = {};
|
|
||||||
|
|
||||||
values || (values = []);
|
|
||||||
while (++index < length) {
|
|
||||||
result[keys[index]] = values[index];
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -4185,7 +4209,6 @@
|
|||||||
lodash.defer = defer;
|
lodash.defer = defer;
|
||||||
lodash.delay = delay;
|
lodash.delay = delay;
|
||||||
lodash.difference = difference;
|
lodash.difference = difference;
|
||||||
lodash.drop = drop;
|
|
||||||
lodash.escape = escape;
|
lodash.escape = escape;
|
||||||
lodash.every = every;
|
lodash.every = every;
|
||||||
lodash.extend = extend;
|
lodash.extend = extend;
|
||||||
@@ -4230,6 +4253,8 @@
|
|||||||
lodash.min = min;
|
lodash.min = min;
|
||||||
lodash.mixin = mixin;
|
lodash.mixin = mixin;
|
||||||
lodash.noConflict = noConflict;
|
lodash.noConflict = noConflict;
|
||||||
|
lodash.object = object;
|
||||||
|
lodash.omit = omit;
|
||||||
lodash.once = once;
|
lodash.once = once;
|
||||||
lodash.partial = partial;
|
lodash.partial = partial;
|
||||||
lodash.pick = pick;
|
lodash.pick = pick;
|
||||||
@@ -4259,13 +4284,13 @@
|
|||||||
lodash.without = without;
|
lodash.without = without;
|
||||||
lodash.wrap = wrap;
|
lodash.wrap = wrap;
|
||||||
lodash.zip = zip;
|
lodash.zip = zip;
|
||||||
lodash.zipObject = zipObject;
|
|
||||||
|
|
||||||
// assign aliases
|
// assign aliases
|
||||||
lodash.all = every;
|
lodash.all = every;
|
||||||
lodash.any = some;
|
lodash.any = some;
|
||||||
lodash.collect = map;
|
lodash.collect = map;
|
||||||
lodash.detect = find;
|
lodash.detect = find;
|
||||||
|
lodash.drop = rest;
|
||||||
lodash.each = forEach;
|
lodash.each = forEach;
|
||||||
lodash.foldl = reduce;
|
lodash.foldl = reduce;
|
||||||
lodash.foldr = reduceRight;
|
lodash.foldr = reduceRight;
|
||||||
@@ -4273,7 +4298,6 @@
|
|||||||
lodash.include = contains;
|
lodash.include = contains;
|
||||||
lodash.inject = reduce;
|
lodash.inject = reduce;
|
||||||
lodash.methods = functions;
|
lodash.methods = functions;
|
||||||
lodash.omit = drop;
|
|
||||||
lodash.select = filter;
|
lodash.select = filter;
|
||||||
lodash.tail = rest;
|
lodash.tail = rest;
|
||||||
lodash.take = first;
|
lodash.take = first;
|
||||||
|
|||||||
Reference in New Issue
Block a user