mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Update vendor/underscore.
Former-commit-id: 833a6ca3e5a7f9d4a8b22e535d849c106526171e
This commit is contained in:
2
vendor/underscore/test/objects.js
vendored
2
vendor/underscore/test/objects.js
vendored
@@ -52,7 +52,7 @@ $(document).ready(function() {
|
|||||||
result = _.extend({x:'x'}, {a:'a', x:2}, {a:'b'});
|
result = _.extend({x:'x'}, {a:'a', x:2}, {a:'b'});
|
||||||
ok(_.isEqual(result, {x:2, a:'b'}), 'extending from multiple source objects last property trumps');
|
ok(_.isEqual(result, {x:2, a:'b'}), 'extending from multiple source objects last property trumps');
|
||||||
result = _.extend({}, {a: void 0, b: null});
|
result = _.extend({}, {a: void 0, b: null});
|
||||||
equal(_.keys(result).join(''), 'ab', 'extend does not copy undefined values');
|
equal(_.keys(result).join(''), 'ab', 'extend copies undefined values');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = {};
|
result = {};
|
||||||
|
|||||||
2
vendor/underscore/underscore-min.js
vendored
2
vendor/underscore/underscore-min.js
vendored
File diff suppressed because one or more lines are too long
70
vendor/underscore/underscore.js
vendored
70
vendor/underscore/underscore.js
vendored
@@ -82,10 +82,9 @@
|
|||||||
if (iterator.call(context, obj[i], i, obj) === breaker) return;
|
if (iterator.call(context, obj[i], i, obj) === breaker) return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (var key in obj) {
|
var keys = _.keys(obj);
|
||||||
if (_.has(obj, key)) {
|
for (var i = 0, length = keys.length; i < length; i++) {
|
||||||
if (iterator.call(context, obj[key], key, obj) === breaker) return;
|
if (iterator.call(context, obj[keys[i]], keys[i], obj) === breaker) return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -307,9 +306,9 @@
|
|||||||
var iterator = lookupIterator(value);
|
var iterator = lookupIterator(value);
|
||||||
return _.pluck(_.map(obj, function(value, index, list) {
|
return _.pluck(_.map(obj, function(value, index, list) {
|
||||||
return {
|
return {
|
||||||
value : value,
|
value: value,
|
||||||
index : index,
|
index: index,
|
||||||
criteria : iterator.call(context, value, index, list)
|
criteria: iterator.call(context, value, index, list)
|
||||||
};
|
};
|
||||||
}).sort(function(left, right) {
|
}).sort(function(left, right) {
|
||||||
var a = left.criteria;
|
var a = left.criteria;
|
||||||
@@ -318,46 +317,41 @@
|
|||||||
if (a > b || a === void 0) return 1;
|
if (a > b || a === void 0) return 1;
|
||||||
if (a < b || b === void 0) return -1;
|
if (a < b || b === void 0) return -1;
|
||||||
}
|
}
|
||||||
return left.index < right.index ? -1 : 1;
|
return left.index - right.index;
|
||||||
}), 'value');
|
}), 'value');
|
||||||
};
|
};
|
||||||
|
|
||||||
// An internal function used for aggregate "group by" operations.
|
// An internal function used for aggregate "group by" operations.
|
||||||
var group = function(obj, value, context, behavior) {
|
var group = function(behavior) {
|
||||||
var result = {};
|
return function(obj, value, context) {
|
||||||
var iterator = lookupIterator(value == null ? _.identity : value);
|
var result = {};
|
||||||
each(obj, function(value, index) {
|
var iterator = value == null ? _.identity : lookupIterator(value);
|
||||||
var key = iterator.call(context, value, index, obj);
|
each(obj, function(value, index) {
|
||||||
behavior(result, key, value);
|
var key = iterator.call(context, value, index, obj);
|
||||||
});
|
behavior(result, key, value);
|
||||||
return result;
|
});
|
||||||
|
return result;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Groups the object's values by a criterion. Pass either a string attribute
|
// Groups the object's values by a criterion. Pass either a string attribute
|
||||||
// to group by, or a function that returns the criterion.
|
// to group by, or a function that returns the criterion.
|
||||||
_.groupBy = function(obj, value, context) {
|
_.groupBy = group(function(result, key, value) {
|
||||||
return group(obj, value, context, function(result, key, value) {
|
(_.has(result, key) ? result[key] : (result[key] = [])).push(value);
|
||||||
(_.has(result, key) ? result[key] : (result[key] = [])).push(value);
|
});
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Indexes the object's values by a criterion, similar to `groupBy`, but for
|
// Indexes the object's values by a criterion, similar to `groupBy`, but for
|
||||||
// when you know that your index values will be unique.
|
// when you know that your index values will be unique.
|
||||||
_.indexBy = function(obj, value, context) {
|
_.indexBy = group(function(result, key, value) {
|
||||||
return group(obj, value, context, function(result, key, value) {
|
result[key] = value;
|
||||||
result[key] = value;
|
});
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Counts instances of an object that group by a certain criterion. Pass
|
// Counts instances of an object that group by a certain criterion. Pass
|
||||||
// either a string attribute to count by, or a function that returns the
|
// either a string attribute to count by, or a function that returns the
|
||||||
// criterion.
|
// criterion.
|
||||||
_.countBy = function(obj, value, context) {
|
_.countBy = group(function(result, key, value) {
|
||||||
return group(obj, value, context, function(result, key) {
|
_.has(result, key) ? result[key]++ : result[key] = 1;
|
||||||
if (!_.has(result, key)) result[key] = 0;
|
});
|
||||||
result[key]++;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Use a comparator function to figure out the smallest index at which
|
// 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.
|
// an object should be inserted so as to maintain order. Uses binary search.
|
||||||
@@ -394,7 +388,7 @@
|
|||||||
// allows it to work with `_.map`.
|
// allows it to work with `_.map`.
|
||||||
_.first = _.head = _.take = function(array, n, guard) {
|
_.first = _.head = _.take = function(array, n, guard) {
|
||||||
if (array == null) return void 0;
|
if (array == null) return void 0;
|
||||||
return (n != null) && !guard ? slice.call(array, 0, n) : array[0];
|
return (n == null) || guard ? array[0] : slice.call(array, 0, n);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns everything but the last entry of the array. Especially useful on
|
// Returns everything but the last entry of the array. Especially useful on
|
||||||
@@ -409,10 +403,10 @@
|
|||||||
// values in the array. The **guard** check allows it to work with `_.map`.
|
// values in the array. The **guard** check allows it to work with `_.map`.
|
||||||
_.last = function(array, n, guard) {
|
_.last = function(array, n, guard) {
|
||||||
if (array == null) return void 0;
|
if (array == null) return void 0;
|
||||||
if ((n != null) && !guard) {
|
if ((n == null) || guard) {
|
||||||
return slice.call(array, Math.max(array.length - n, 0));
|
|
||||||
} else {
|
|
||||||
return array[array.length - 1];
|
return array[array.length - 1];
|
||||||
|
} else {
|
||||||
|
return slice.call(array, Math.max(array.length - n, 0));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -444,7 +438,7 @@
|
|||||||
return output;
|
return output;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return a completely flattened version of an array.
|
// Flatten out an array, either recursively (by default), or just one level.
|
||||||
_.flatten = function(array, shallow) {
|
_.flatten = function(array, shallow) {
|
||||||
return flatten(array, shallow, []);
|
return flatten(array, shallow, []);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user