mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +00:00
Update vendors.
This commit is contained in:
6
vendor/underscore/test/arrays.js
vendored
6
vendor/underscore/test/arrays.js
vendored
@@ -344,6 +344,9 @@
|
||||
strictEqual(_.indexOf([1, 2, NaN, NaN], NaN), 2, 'Expected [1, 2, NaN] to contain NaN');
|
||||
strictEqual(_.indexOf([1, 2, Infinity], NaN), -1, 'Expected [1, 2, NaN] to contain NaN');
|
||||
|
||||
strictEqual(_.indexOf([1, 2, NaN, NaN], NaN, 1), 2, 'startIndex does not affect result');
|
||||
strictEqual(_.indexOf([1, 2, NaN, NaN], NaN, -2), 2, 'startIndex does not affect result');
|
||||
|
||||
(function() {
|
||||
strictEqual(_.indexOf(arguments, NaN), 2, 'Expected arguments [1, 2, NaN] to contain NaN');
|
||||
}(1, 2, NaN, NaN));
|
||||
@@ -418,6 +421,9 @@
|
||||
strictEqual(_.lastIndexOf([1, 2, NaN, NaN], NaN), 3, 'Expected [1, 2, NaN] to contain NaN');
|
||||
strictEqual(_.lastIndexOf([1, 2, Infinity], NaN), -1, 'Expected [1, 2, NaN] to contain NaN');
|
||||
|
||||
strictEqual(_.lastIndexOf([1, 2, NaN, NaN], NaN, 2), 2, 'fromIndex does not affect result');
|
||||
strictEqual(_.lastIndexOf([1, 2, NaN, NaN], NaN, -2), 2, 'fromIndex does not affect result');
|
||||
|
||||
(function() {
|
||||
strictEqual(_.lastIndexOf(arguments, NaN), 3, 'Expected arguments [1, 2, NaN] to contain NaN');
|
||||
}(1, 2, NaN, NaN));
|
||||
|
||||
22
vendor/underscore/test/collections.js
vendored
22
vendor/underscore/test/collections.js
vendored
@@ -23,6 +23,13 @@
|
||||
deepEqual(answers, ['one', 'two', 'three'], 'iterating over objects works, and ignores the object prototype.');
|
||||
delete obj.constructor.prototype.four;
|
||||
|
||||
// ensure the each function is JITed
|
||||
_(1000).times(function() { _.each([], function(){}); });
|
||||
var count = 0;
|
||||
obj = {1 : 'foo', 2 : 'bar', 3 : 'baz'};
|
||||
_.each(obj, function(value, key){ count++; });
|
||||
equal(count, 3, 'the fun should be called only 3 times');
|
||||
|
||||
var answer = null;
|
||||
_.each([1, 2, 3], function(num, index, arr){ if (_.include(arr, num)) answer = true; });
|
||||
ok(answer, 'can reference the original collection from inside the iterator');
|
||||
@@ -420,12 +427,14 @@
|
||||
strictEqual(_.includes, _.contains, 'alias for includes');
|
||||
|
||||
var numbers = [1, 2, 3, 1, 2, 3, 1, 2, 3];
|
||||
strictEqual(_.includes(numbers, 1, 1), true);
|
||||
strictEqual(_.includes(numbers, 1, -1), false);
|
||||
strictEqual(_.includes(numbers, 1, -2), false);
|
||||
strictEqual(_.includes(numbers, 1, -3), true);
|
||||
strictEqual(_.includes(numbers, 1, 6), true);
|
||||
strictEqual(_.includes(numbers, 1, 7), false);
|
||||
strictEqual(_.includes(numbers, 1, 1), true, 'contains takes a fromIndex');
|
||||
strictEqual(_.includes(numbers, 1, -1), false, 'contains takes a fromIndex');
|
||||
strictEqual(_.includes(numbers, 1, -2), false, 'contains takes a fromIndex');
|
||||
strictEqual(_.includes(numbers, 1, -3), true, 'contains takes a fromIndex');
|
||||
strictEqual(_.includes(numbers, 1, 6), true, 'contains takes a fromIndex');
|
||||
strictEqual(_.includes(numbers, 1, 7), false, 'contains takes a fromIndex');
|
||||
|
||||
ok(_.every([1, 2, 3], _.partial(_.contains, numbers)), 'fromIndex is guarded');
|
||||
});
|
||||
|
||||
test('includes with NaN', function() {
|
||||
@@ -789,6 +798,7 @@
|
||||
equal(_.size(new String('hello')), 5, 'can compute the size of string object');
|
||||
|
||||
equal(_.size(null), 0, 'handles nulls');
|
||||
equal(_.size(0), 0, 'handles numbers');
|
||||
});
|
||||
|
||||
test('partition', function() {
|
||||
|
||||
26
vendor/underscore/test/objects.js
vendored
26
vendor/underscore/test/objects.js
vendored
@@ -282,6 +282,32 @@
|
||||
equal(_.clone(null), null, 'non objects should not be changed by clone');
|
||||
});
|
||||
|
||||
test('create', function() {
|
||||
var Parent = function() {};
|
||||
Parent.prototype = {foo: function() {}, bar: 2};
|
||||
|
||||
_.each(['foo', null, undefined, 1], function(val) {
|
||||
deepEqual(_.create(val), {}, 'should return empty object when a non-object is provided');
|
||||
});
|
||||
|
||||
ok(_.create([]) instanceof Array, 'should return new instance of array when array is provided');
|
||||
|
||||
var Child = function() {};
|
||||
Child.prototype = _.create(Parent.prototype);
|
||||
ok(new Child instanceof Parent, 'object should inherit prototype');
|
||||
|
||||
var func = function() {};
|
||||
Child.prototype = _.create(Parent.prototype, {func: func});
|
||||
strictEqual(Child.prototype.func, func, 'properties should be added to object');
|
||||
|
||||
Child.prototype = _.create(Parent.prototype, {constructor: Child});
|
||||
strictEqual(Child.prototype.constructor, Child);
|
||||
|
||||
Child.prototype.foo = 'foo';
|
||||
var created = _.create(Child.prototype, new Child);
|
||||
ok(!created.hasOwnProperty('foo'), 'should only add own properties');
|
||||
});
|
||||
|
||||
test('isEqual', function() {
|
||||
function First() {
|
||||
this.value = 1;
|
||||
|
||||
4
vendor/underscore/underscore-min.js
vendored
4
vendor/underscore/underscore-min.js
vendored
File diff suppressed because one or more lines are too long
130
vendor/underscore/underscore.js
vendored
130
vendor/underscore/underscore.js
vendored
@@ -1,4 +1,4 @@
|
||||
// Underscore.js 1.8.2
|
||||
// Underscore.js 1.8.3
|
||||
// http://underscorejs.org
|
||||
// (c) 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
||||
// Underscore may be freely distributed under the MIT license.
|
||||
@@ -55,7 +55,7 @@
|
||||
}
|
||||
|
||||
// Current version.
|
||||
_.VERSION = '1.8.2';
|
||||
_.VERSION = '1.8.3';
|
||||
|
||||
// Internal function that returns an efficient (for current engines) version
|
||||
// of the passed-in callback, to be repeatedly applied in other Underscore
|
||||
@@ -122,12 +122,20 @@
|
||||
return result;
|
||||
};
|
||||
|
||||
var property = function(key) {
|
||||
return function(obj) {
|
||||
return obj == null ? void 0 : obj[key];
|
||||
};
|
||||
};
|
||||
|
||||
// Helper for collection methods to determine whether a collection
|
||||
// should be iterated as an array or as an object
|
||||
// Related: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength
|
||||
// Avoids a very nasty iOS 8 JIT bug on ARM-64. #2094
|
||||
var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1;
|
||||
var getLength = property('length');
|
||||
var isArrayLike = function(collection) {
|
||||
var length = collection && collection.length;
|
||||
var length = getLength(collection);
|
||||
return typeof length == 'number' && length >= 0 && length <= MAX_ARRAY_INDEX;
|
||||
};
|
||||
|
||||
@@ -252,11 +260,12 @@
|
||||
return false;
|
||||
};
|
||||
|
||||
// Determine if the array or object contains a given value (using `===`).
|
||||
// Determine if the array or object contains a given item (using `===`).
|
||||
// Aliased as `includes` and `include`.
|
||||
_.contains = _.includes = _.include = function(obj, target, fromIndex) {
|
||||
_.contains = _.includes = _.include = function(obj, item, fromIndex, guard) {
|
||||
if (!isArrayLike(obj)) obj = _.values(obj);
|
||||
return _.indexOf(obj, target, typeof fromIndex == 'number' && fromIndex) >= 0;
|
||||
if (typeof fromIndex != 'number' || guard) fromIndex = 0;
|
||||
return _.indexOf(obj, item, fromIndex) >= 0;
|
||||
};
|
||||
|
||||
// Invoke a method (with arguments) on every item in a collection.
|
||||
@@ -480,7 +489,7 @@
|
||||
// Internal implementation of a recursive `flatten` function.
|
||||
var flatten = function(input, shallow, strict, startIndex) {
|
||||
var output = [], idx = 0;
|
||||
for (var i = startIndex || 0, length = input && input.length; i < length; i++) {
|
||||
for (var i = startIndex || 0, length = getLength(input); i < length; i++) {
|
||||
var value = input[i];
|
||||
if (isArrayLike(value) && (_.isArray(value) || _.isArguments(value))) {
|
||||
//flatten current level of array or arguments object
|
||||
@@ -511,7 +520,6 @@
|
||||
// been sorted, you have the option of using a faster algorithm.
|
||||
// Aliased as `unique`.
|
||||
_.uniq = _.unique = function(array, isSorted, iteratee, context) {
|
||||
if (array == null) return [];
|
||||
if (!_.isBoolean(isSorted)) {
|
||||
context = iteratee;
|
||||
iteratee = isSorted;
|
||||
@@ -520,7 +528,7 @@
|
||||
if (iteratee != null) iteratee = cb(iteratee, context);
|
||||
var result = [];
|
||||
var seen = [];
|
||||
for (var i = 0, length = array.length; i < length; i++) {
|
||||
for (var i = 0, length = getLength(array); i < length; i++) {
|
||||
var value = array[i],
|
||||
computed = iteratee ? iteratee(value, i, array) : value;
|
||||
if (isSorted) {
|
||||
@@ -547,10 +555,9 @@
|
||||
// Produce an array that contains every item shared between all the
|
||||
// passed-in arrays.
|
||||
_.intersection = function(array) {
|
||||
if (array == null) return [];
|
||||
var result = [];
|
||||
var argsLength = arguments.length;
|
||||
for (var i = 0, length = array.length; i < length; i++) {
|
||||
for (var i = 0, length = getLength(array); i < length; i++) {
|
||||
var item = array[i];
|
||||
if (_.contains(result, item)) continue;
|
||||
for (var j = 1; j < argsLength; j++) {
|
||||
@@ -579,7 +586,7 @@
|
||||
// Complement of _.zip. Unzip accepts an array of arrays and groups
|
||||
// each array's elements on shared indices
|
||||
_.unzip = function(array) {
|
||||
var length = array && _.max(array, 'length').length || 0;
|
||||
var length = array && _.max(array, getLength).length || 0;
|
||||
var result = Array(length);
|
||||
|
||||
for (var index = 0; index < length; index++) {
|
||||
@@ -593,7 +600,7 @@
|
||||
// the corresponding values.
|
||||
_.object = function(list, values) {
|
||||
var result = {};
|
||||
for (var i = 0, length = list && list.length; i < length; i++) {
|
||||
for (var i = 0, length = getLength(list); i < length; i++) {
|
||||
if (values) {
|
||||
result[list[i]] = values[i];
|
||||
} else {
|
||||
@@ -603,42 +610,11 @@
|
||||
return result;
|
||||
};
|
||||
|
||||
// Return the position of the first occurrence of an item in an array,
|
||||
// or -1 if the item is not included in the array.
|
||||
// If the array is large and already in sort order, pass `true`
|
||||
// for **isSorted** to use binary search.
|
||||
_.indexOf = function(array, item, isSorted) {
|
||||
var i = 0, length = array && array.length;
|
||||
if (typeof isSorted == 'number') {
|
||||
i = isSorted < 0 ? Math.max(0, length + isSorted) : isSorted;
|
||||
} else if (isSorted && length) {
|
||||
i = _.sortedIndex(array, item);
|
||||
return array[i] === item ? i : -1;
|
||||
}
|
||||
if (item !== item) {
|
||||
return _.findIndex(slice.call(array, i), _.isNaN);
|
||||
}
|
||||
for (; i < length; i++) if (array[i] === item) return i;
|
||||
return -1;
|
||||
};
|
||||
|
||||
_.lastIndexOf = function(array, item, from) {
|
||||
var idx = array ? array.length : 0;
|
||||
if (typeof from == 'number') {
|
||||
idx = from < 0 ? idx + from + 1 : Math.min(idx, from + 1);
|
||||
}
|
||||
if (item !== item) {
|
||||
return _.findLastIndex(slice.call(array, 0, idx), _.isNaN);
|
||||
}
|
||||
while (--idx >= 0) if (array[idx] === item) return idx;
|
||||
return -1;
|
||||
};
|
||||
|
||||
// Generator function to create the findIndex and findLastIndex functions
|
||||
function createIndexFinder(dir) {
|
||||
function createPredicateIndexFinder(dir) {
|
||||
return function(array, predicate, context) {
|
||||
predicate = cb(predicate, context);
|
||||
var length = array != null && array.length;
|
||||
var length = getLength(array);
|
||||
var index = dir > 0 ? 0 : length - 1;
|
||||
for (; index >= 0 && index < length; index += dir) {
|
||||
if (predicate(array[index], index, array)) return index;
|
||||
@@ -648,16 +624,15 @@
|
||||
}
|
||||
|
||||
// Returns the first index on an array-like that passes a predicate test
|
||||
_.findIndex = createIndexFinder(1);
|
||||
|
||||
_.findLastIndex = createIndexFinder(-1);
|
||||
_.findIndex = createPredicateIndexFinder(1);
|
||||
_.findLastIndex = createPredicateIndexFinder(-1);
|
||||
|
||||
// Use a comparator function to figure out the smallest index at which
|
||||
// an object should be inserted so as to maintain order. Uses binary search.
|
||||
_.sortedIndex = function(array, obj, iteratee, context) {
|
||||
iteratee = cb(iteratee, context, 1);
|
||||
var value = iteratee(obj);
|
||||
var low = 0, high = array.length;
|
||||
var low = 0, high = getLength(array);
|
||||
while (low < high) {
|
||||
var mid = Math.floor((low + high) / 2);
|
||||
if (iteratee(array[mid]) < value) low = mid + 1; else high = mid;
|
||||
@@ -665,11 +640,43 @@
|
||||
return low;
|
||||
};
|
||||
|
||||
// Generator function to create the indexOf and lastIndexOf functions
|
||||
function createIndexFinder(dir, predicateFind, sortedIndex) {
|
||||
return function(array, item, idx) {
|
||||
var i = 0, length = getLength(array);
|
||||
if (typeof idx == 'number') {
|
||||
if (dir > 0) {
|
||||
i = idx >= 0 ? idx : Math.max(idx + length, i);
|
||||
} else {
|
||||
length = idx >= 0 ? Math.min(idx + 1, length) : idx + length + 1;
|
||||
}
|
||||
} else if (sortedIndex && idx && length) {
|
||||
idx = sortedIndex(array, item);
|
||||
return array[idx] === item ? idx : -1;
|
||||
}
|
||||
if (item !== item) {
|
||||
idx = predicateFind(slice.call(array, i, length), _.isNaN);
|
||||
return idx >= 0 ? idx + i : -1;
|
||||
}
|
||||
for (idx = dir > 0 ? i : length - 1; idx >= 0 && idx < length; idx += dir) {
|
||||
if (array[idx] === item) return idx;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
}
|
||||
|
||||
// Return the position of the first occurrence of an item in an array,
|
||||
// or -1 if the item is not included in the array.
|
||||
// If the array is large and already in sort order, pass `true`
|
||||
// for **isSorted** to use binary search.
|
||||
_.indexOf = createIndexFinder(1, _.findIndex, _.sortedIndex);
|
||||
_.lastIndexOf = createIndexFinder(-1, _.findLastIndex);
|
||||
|
||||
// Generate an integer Array containing an arithmetic progression. A port of
|
||||
// the native Python `range()` function. See
|
||||
// [the Python documentation](http://docs.python.org/library/functions.html#range).
|
||||
_.range = function(start, stop, step) {
|
||||
if (arguments.length <= 1) {
|
||||
if (stop == null) {
|
||||
stop = start || 0;
|
||||
start = 0;
|
||||
}
|
||||
@@ -1048,6 +1055,15 @@
|
||||
// Fill in a given object with default properties.
|
||||
_.defaults = createAssigner(_.allKeys, true);
|
||||
|
||||
// Creates an object that inherits from the given prototype object.
|
||||
// If additional properties are provided then they will be added to the
|
||||
// created object.
|
||||
_.create = function(prototype, props) {
|
||||
var result = baseCreate(prototype);
|
||||
if (props) _.extendOwn(result, props);
|
||||
return result;
|
||||
};
|
||||
|
||||
// Create a (shallow-cloned) duplicate of an object.
|
||||
_.clone = function(obj) {
|
||||
if (!_.isObject(obj)) return obj;
|
||||
@@ -1125,7 +1141,7 @@
|
||||
}
|
||||
// Assume equality for cyclic structures. The algorithm for detecting cyclic
|
||||
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
|
||||
|
||||
|
||||
// Initializing stack of traversed objects.
|
||||
// It's done here since we only need them for objects and arrays comparison.
|
||||
aStack = aStack || [];
|
||||
@@ -1276,11 +1292,7 @@
|
||||
|
||||
_.noop = function(){};
|
||||
|
||||
_.property = function(key) {
|
||||
return function(obj) {
|
||||
return obj == null ? void 0 : obj[key];
|
||||
};
|
||||
};
|
||||
_.property = property;
|
||||
|
||||
// Generates a function for a given object that returns a given property.
|
||||
_.propertyOf = function(obj) {
|
||||
@@ -1289,7 +1301,7 @@
|
||||
};
|
||||
};
|
||||
|
||||
// Returns a predicate for checking whether an object has a given set of
|
||||
// Returns a predicate for checking whether an object has a given set of
|
||||
// `key:value` pairs.
|
||||
_.matcher = _.matches = function(attrs) {
|
||||
attrs = _.extendOwn({}, attrs);
|
||||
@@ -1516,7 +1528,7 @@
|
||||
// Provide unwrapping proxy for some methods used in engine operations
|
||||
// such as arithmetic and JSON stringification.
|
||||
_.prototype.valueOf = _.prototype.toJSON = _.prototype.value;
|
||||
|
||||
|
||||
_.prototype.toString = function() {
|
||||
return '' + this._wrapped;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user