mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 17:07:49 +00:00
Bump to v3.2.0.
This commit is contained in:
@@ -8,14 +8,14 @@ var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
|
||||
* @param {*} value The value to wrap.
|
||||
*/
|
||||
function LazyWrapper(value) {
|
||||
this.actions = null;
|
||||
this.dir = 1;
|
||||
this.dropCount = 0;
|
||||
this.filtered = false;
|
||||
this.iteratees = null;
|
||||
this.takeCount = POSITIVE_INFINITY;
|
||||
this.views = null;
|
||||
this.wrapped = value;
|
||||
this.__wrapped__ = value;
|
||||
this.__actions__ = null;
|
||||
this.__dir__ = 1;
|
||||
this.__dropCount__ = 0;
|
||||
this.__filtered__ = false;
|
||||
this.__iteratees__ = null;
|
||||
this.__takeCount__ = POSITIVE_INFINITY;
|
||||
this.__views__ = null;
|
||||
}
|
||||
|
||||
module.exports = LazyWrapper;
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
* @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
|
||||
*/
|
||||
function LodashWrapper(value, chainAll, actions) {
|
||||
this.__wrapped__ = value;
|
||||
this.__actions__ = actions || [];
|
||||
this.__chain__ = !!chainAll;
|
||||
this.__wrapped__ = value;
|
||||
}
|
||||
|
||||
module.exports = LodashWrapper;
|
||||
|
||||
@@ -17,7 +17,7 @@ function baseAssign(object, source, customizer) {
|
||||
return baseCopy(source, object, props);
|
||||
}
|
||||
var index = -1,
|
||||
length = props.length
|
||||
length = props.length;
|
||||
|
||||
while (++index < length) {
|
||||
var key = props[index],
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
var baseMatches = require('./baseMatches'),
|
||||
baseMatchesProperty = require('./baseMatchesProperty'),
|
||||
baseProperty = require('./baseProperty'),
|
||||
bindCallback = require('./bindCallback'),
|
||||
identity = require('../utility/identity'),
|
||||
@@ -24,10 +25,12 @@ function baseCallback(func, thisArg, argCount) {
|
||||
if (func == null) {
|
||||
return identity;
|
||||
}
|
||||
// Handle "_.property" and "_.matches" style callback shorthands.
|
||||
return type == 'object'
|
||||
? baseMatches(func)
|
||||
: baseProperty(func + '');
|
||||
if (type == 'object') {
|
||||
return baseMatches(func);
|
||||
}
|
||||
return typeof thisArg == 'undefined'
|
||||
? baseProperty(func + '')
|
||||
: baseMatchesProperty(func + '', thisArg);
|
||||
}
|
||||
|
||||
module.exports = baseCallback;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
var baseSlice = require('./baseSlice'),
|
||||
isFunction = require('../lang/isFunction');
|
||||
var baseSlice = require('./baseSlice');
|
||||
|
||||
/** Used as the `TypeError` message for "Functions" methods. */
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
@@ -15,7 +14,7 @@ var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
* @returns {number} Returns the timer id.
|
||||
*/
|
||||
function baseDelay(func, wait, args, fromIndex) {
|
||||
if (!isFunction(func)) {
|
||||
if (typeof func != 'function') {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
return setTimeout(function() { func.apply(undefined, baseSlice(args, fromIndex)); }, wait);
|
||||
|
||||
31
internal/baseFill.js
Normal file
31
internal/baseFill.js
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* The base implementation of `_.fill` without an iteratee call guard.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to fill.
|
||||
* @param {*} value The value to fill `array` with.
|
||||
* @param {number} [start=0] The start position.
|
||||
* @param {number} [end=array.length] The end position.
|
||||
* @returns {Array} Returns `array`.
|
||||
*/
|
||||
function baseFill(array, value, start, end) {
|
||||
var length = array.length;
|
||||
|
||||
start = start == null ? 0 : (+start || 0);
|
||||
if (start < 0) {
|
||||
start = -start > length ? 0 : (length + start);
|
||||
}
|
||||
end = (typeof end == 'undefined' || end > length) ? length : (+end || 0);
|
||||
if (end < 0) {
|
||||
end += length;
|
||||
}
|
||||
length = start > end ? 0 : end >>> 0;
|
||||
start >>>= 0;
|
||||
|
||||
while (start < length) {
|
||||
array[start++] = value;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
module.exports = baseFill;
|
||||
@@ -11,7 +11,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
* shorthands or `this` binding.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} source The object to inspect.
|
||||
* @param {Object} object The object to inspect.
|
||||
* @param {Array} props The source property names to match.
|
||||
* @param {Array} values The source values to match.
|
||||
* @param {Array} strictCompareFlags Strict comparison flags for source values.
|
||||
|
||||
@@ -9,8 +9,7 @@ var objectProto = Object.prototype;
|
||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
|
||||
/**
|
||||
* The base implementation of `_.matches` which supports specifying whether
|
||||
* `source` should be cloned.
|
||||
* The base implementation of `_.matches` which does not clone `source`.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} source The object of property values to match.
|
||||
@@ -26,7 +25,7 @@ function baseMatches(source) {
|
||||
|
||||
if (isStrictComparable(value)) {
|
||||
return function(object) {
|
||||
return object != null && value === object[key] && hasOwnProperty.call(object, key);
|
||||
return object != null && object[key] === value && hasOwnProperty.call(object, key);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
24
internal/baseMatchesProperty.js
Normal file
24
internal/baseMatchesProperty.js
Normal file
@@ -0,0 +1,24 @@
|
||||
var baseIsEqual = require('./baseIsEqual'),
|
||||
isStrictComparable = require('./isStrictComparable');
|
||||
|
||||
/**
|
||||
* The base implementation of `_.matchesProperty` which does not coerce `key`
|
||||
* to a string.
|
||||
*
|
||||
* @private
|
||||
* @param {string} key The key of the property to get.
|
||||
* @param {*} value The value to compare.
|
||||
* @returns {Function} Returns the new function.
|
||||
*/
|
||||
function baseMatchesProperty(key, value) {
|
||||
if (isStrictComparable(value)) {
|
||||
return function(object) {
|
||||
return object != null && object[key] === value;
|
||||
};
|
||||
}
|
||||
return function(object) {
|
||||
return object != null && baseIsEqual(value, object[key], null, true);
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = baseMatchesProperty;
|
||||
@@ -16,7 +16,7 @@ function baseReduce(collection, iteratee, accumulator, initFromCollection, eachF
|
||||
eachFunc(collection, function(value, index, collection) {
|
||||
accumulator = initFromCollection
|
||||
? (initFromCollection = false, value)
|
||||
: iteratee(accumulator, value, index, collection)
|
||||
: iteratee(accumulator, value, index, collection);
|
||||
});
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,7 @@ var baseCallback = require('./baseCallback'),
|
||||
/**
|
||||
* Creates a function that aggregates a collection, creating an accumulator
|
||||
* object composed from the results of running each element in the collection
|
||||
* through an iteratee. The `setter` sets the keys and values of the accumulator
|
||||
* object. If `initializer` is provided initializes the accumulator object.
|
||||
* through an iteratee.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} setter The function to set keys and values of the accumulator object.
|
||||
|
||||
@@ -3,7 +3,6 @@ var baseSetData = require('./baseSetData'),
|
||||
createHybridWrapper = require('./createHybridWrapper'),
|
||||
createPartialWrapper = require('./createPartialWrapper'),
|
||||
getData = require('./getData'),
|
||||
isFunction = require('../lang/isFunction'),
|
||||
mergeData = require('./mergeData'),
|
||||
setData = require('./setData');
|
||||
|
||||
@@ -46,7 +45,7 @@ var nativeMax = Math.max;
|
||||
*/
|
||||
function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
|
||||
var isBindKey = bitmask & BIND_KEY_FLAG;
|
||||
if (!isBindKey && !isFunction(func)) {
|
||||
if (!isBindKey && typeof func != 'function') {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
var length = partials ? partials.length : 0;
|
||||
@@ -76,9 +75,9 @@ function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, a
|
||||
if (bitmask == BIND_FLAG) {
|
||||
var result = createBindWrapper(newData[0], newData[2]);
|
||||
} else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) {
|
||||
result = createPartialWrapper.apply(null, newData);
|
||||
result = createPartialWrapper.apply(undefined, newData);
|
||||
} else {
|
||||
result = createHybridWrapper.apply(null, newData);
|
||||
result = createHybridWrapper.apply(undefined, newData);
|
||||
}
|
||||
var setter = data ? baseSetData : setData;
|
||||
return setter(result, newData);
|
||||
|
||||
@@ -10,18 +10,18 @@ var LazyWrapper = require('./LazyWrapper'),
|
||||
* @returns {Object} Returns the cloned `LazyWrapper` object.
|
||||
*/
|
||||
function lazyClone() {
|
||||
var actions = this.actions,
|
||||
iteratees = this.iteratees,
|
||||
views = this.views,
|
||||
result = new LazyWrapper(this.wrapped);
|
||||
var actions = this.__actions__,
|
||||
iteratees = this.__iteratees__,
|
||||
views = this.__views__,
|
||||
result = new LazyWrapper(this.__wrapped__);
|
||||
|
||||
result.actions = actions ? arrayCopy(actions) : null;
|
||||
result.dir = this.dir;
|
||||
result.dropCount = this.dropCount;
|
||||
result.filtered = this.filtered;
|
||||
result.iteratees = iteratees ? arrayCopy(iteratees) : null;
|
||||
result.takeCount = this.takeCount;
|
||||
result.views = views ? arrayCopy(views) : null;
|
||||
result.__actions__ = actions ? arrayCopy(actions) : null;
|
||||
result.__dir__ = this.__dir__;
|
||||
result.__dropCount__ = this.__dropCount__;
|
||||
result.__filtered__ = this.__filtered__;
|
||||
result.__iteratees__ = iteratees ? arrayCopy(iteratees) : null;
|
||||
result.__takeCount__ = this.__takeCount__;
|
||||
result.__views__ = views ? arrayCopy(views) : null;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@ var LazyWrapper = require('./LazyWrapper');
|
||||
* @returns {Object} Returns the new reversed `LazyWrapper` object.
|
||||
*/
|
||||
function lazyReverse() {
|
||||
if (this.filtered) {
|
||||
if (this.__filtered__) {
|
||||
var result = new LazyWrapper(this);
|
||||
result.dir = -1;
|
||||
result.filtered = true;
|
||||
result.__dir__ = -1;
|
||||
result.__filtered__ = true;
|
||||
} else {
|
||||
result = this.clone();
|
||||
result.dir *= -1;
|
||||
result.__dir__ *= -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -18,20 +18,20 @@ var nativeMin = Math.min;
|
||||
* @returns {*} Returns the unwrapped value.
|
||||
*/
|
||||
function lazyValue() {
|
||||
var array = this.wrapped.value();
|
||||
var array = this.__wrapped__.value();
|
||||
if (!isArray(array)) {
|
||||
return baseWrapperValue(array, this.actions);
|
||||
return baseWrapperValue(array, this.__actions__);
|
||||
}
|
||||
var dir = this.dir,
|
||||
var dir = this.__dir__,
|
||||
isRight = dir < 0,
|
||||
view = getView(0, array.length, this.views),
|
||||
view = getView(0, array.length, this.__views__),
|
||||
start = view.start,
|
||||
end = view.end,
|
||||
length = end - start,
|
||||
dropCount = this.dropCount,
|
||||
takeCount = nativeMin(length, this.takeCount - dropCount),
|
||||
dropCount = this.__dropCount__,
|
||||
takeCount = nativeMin(length, this.__takeCount__),
|
||||
index = isRight ? end : start - 1,
|
||||
iteratees = this.iteratees,
|
||||
iteratees = this.__iteratees__,
|
||||
iterLength = iteratees ? iteratees.length : 0,
|
||||
resIndex = 0,
|
||||
result = [];
|
||||
|
||||
18
internal/wrapperClone.js
Normal file
18
internal/wrapperClone.js
Normal file
@@ -0,0 +1,18 @@
|
||||
var LazyWrapper = require('./LazyWrapper'),
|
||||
LodashWrapper = require('./LodashWrapper'),
|
||||
arrayCopy = require('./arrayCopy');
|
||||
|
||||
/**
|
||||
* Creates a clone of `wrapper`.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} wrapper The wrapper to clone.
|
||||
* @returns {Object} Returns the cloned wrapper.
|
||||
*/
|
||||
function wrapperClone(wrapper) {
|
||||
return wrapper instanceof LazyWrapper
|
||||
? wrapper.clone()
|
||||
: new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__));
|
||||
}
|
||||
|
||||
module.exports = wrapperClone;
|
||||
Reference in New Issue
Block a user