_.VERSION = '1.8.2';
diff --git a/.travis.yml b/.travis.yml index da6b33043..07d33cc8a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ matrix: - node_js: "0.10" env: BROWSER=true before_install: - - npm install -g npm + - npm install -g npm@2.6 - npm install -g karma-cli before_script: - npm install karma-sauce-launcher diff --git a/bower.json b/bower.json index 2955fd23f..c7b885334 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "underscore", - "version": "1.8.2", + "version": "1.8.3", "main": "underscore.js", "keywords": ["util", "functional", "server", "client", "browser"], - "ignore" : ["docs", "test", "*.yml", "CNAME", "index.html", "favicon.ico", "CONTRIBUTING.md"] + "ignore" : ["docs", "test", "*.yml", "CNAME", "index.html", "favicon.ico", "CONTRIBUTING.md", ".*", "component.json", "package.json", "karma.*"] } diff --git a/component.json b/component.json index e76680c83..8c033f640 100644 --- a/component.json +++ b/component.json @@ -5,6 +5,6 @@ "repo" : "jashkenas/underscore", "main" : "underscore.js", "scripts" : ["underscore.js"], - "version" : "1.8.2", + "version" : "1.8.3", "license" : "MIT" } diff --git a/docs/underscore.html b/docs/underscore.html index d32de5fc9..b74652a4d 100644 --- a/docs/underscore.html +++ b/docs/underscore.html @@ -27,7 +27,7 @@
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.
@@ -217,7 +217,7 @@ Baseline setup
- _.VERSION = '1.8.2';
+ _.VERSION = '1.8.3';
@@ -330,6 +330,12 @@ Baseline setup
var result = new Ctor;
Ctor.prototype = null;
return result;
+ };
+
+ var property = function(key) {
+ return function(obj) {
+ return obj == null ? void 0 : obj[key];
+ };
};
@@ -343,13 +349,15 @@ Baseline setup
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
+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;
};
@@ -651,14 +659,15 @@ Collection Functions
- 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;
};
@@ -1168,7 +1177,7 @@ Array Functions
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))) {
@@ -1248,7 +1257,6 @@ Array Functions
_.uniq = _.unique = function(array, isSorted, iteratee, context) {
- if (array == null) return [];
if (!_.isBoolean(isSorted)) {
context = iteratee;
iteratee = isSorted;
@@ -1257,7 +1265,7 @@ Array Functions
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) {
@@ -1308,10 +1316,9 @@ Array Functions
_.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++) {
@@ -1376,7 +1383,7 @@ Array Functions
_.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++) {
@@ -1402,7 +1409,7 @@ Array Functions
_.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 {
@@ -1421,57 +1428,14 @@ Array Functions
- 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;
@@ -1483,28 +1447,27 @@ Array Functions
-
+
- _.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.
@@ -1514,7 +1477,7 @@ Array Functions
_.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;
@@ -1525,12 +1488,68 @@ Array Functions
+
+
+
+
+ ¶
+
+ 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.
@@ -1538,7 +1557,7 @@ Array Functions
_.range = function(start, stop, step) {
- if (arguments.length <= 1) {
+ if (stop == null) {
stop = start || 0;
start = 0;
}
@@ -1557,11 +1576,11 @@ Array Functions
-
+
Function (ahem) Functions
@@ -1570,11 +1589,11 @@ Function (ahem) Functions
-
+
@@ -1582,11 +1601,11 @@ Function (ahem) Functions
-
+
Determines whether to execute a function as a constructor
or a normal function with the provided arguments
@@ -1604,11 +1623,11 @@ Function (ahem) Functions
-
+
Create a function bound to a given object (assigning this
, and arguments,
optionally). Delegates to ECMAScript 5‘s native Function.bind
if
@@ -1629,11 +1648,11 @@
Function (ahem) Functions
-
+
Partially apply a function by creating a version that has had some of its
arguments pre-filled, without changing its dynamic this
context. _ acts
@@ -1658,11 +1677,11 @@
Function (ahem) Functions
-
+
Bind a number of an object’s methods to that object. Remaining arguments
are the method names to be bound. Useful for ensuring that all callbacks
@@ -1683,11 +1702,11 @@
Function (ahem) Functions
-
+
Memoize an expensive function by storing its results.
@@ -1707,11 +1726,11 @@ Function (ahem) Functions
-
+
Delays a function for the given number of milliseconds, and then calls
it with the arguments supplied.
@@ -1728,11 +1747,11 @@ Function (ahem) Functions
-
+
Defers a function, scheduling it to run after the current call stack has
cleared.
@@ -1744,11 +1763,11 @@ Function (ahem) Functions
-
+
Returns a function, that, when invoked, will only be triggered at most once
during a given window of time. Normally, the throttled function will run
@@ -1793,11 +1812,11 @@
Function (ahem) Functions
-
+
Returns a function, that, as long as it continues to be invoked, will not
be triggered. The function will be called after it stops being called for
@@ -1841,11 +1860,11 @@
Function (ahem) Functions
-
+
Returns the first function passed as an argument to the second,
allowing you to adjust arguments, run code before and after, and
@@ -1860,11 +1879,11 @@
Function (ahem) Functions
-
+
Returns a negated version of the passed-in predicate.
@@ -1879,11 +1898,11 @@ Function (ahem) Functions
-
+
Returns a function that is the composition of a list of functions, each
consuming the return value of the function that follows.
@@ -1904,11 +1923,11 @@ Function (ahem) Functions
-
+
Returns a function that will only be executed on and after the Nth call.
@@ -1925,11 +1944,11 @@ Function (ahem) Functions
-
+
Returns a function that will only be executed up to (but not including) the Nth call.
@@ -1949,11 +1968,11 @@ Function (ahem) Functions
-
+
Returns a function that will be executed at most one time, no matter how
often you call it. Useful for lazy initialization.
@@ -1965,11 +1984,11 @@ Function (ahem) Functions
-
+
Object Functions
@@ -1978,11 +1997,11 @@ Object Functions
-
+
@@ -1990,11 +2009,11 @@ Object Functions
-
+
Keys in IE < 9 that won’t be iterated by for key in ...
and thus missed.
@@ -2012,11 +2031,11 @@ Object Functions
-
+
Constructor is a special case.
@@ -2036,11 +2055,11 @@ Object Functions
-
+
Retrieve the names of an object’s own properties.
Delegates to ECMAScript 5‘s native Object.keys
@@ -2056,11 +2075,11 @@ Object Functions
-
+
Ahem, IE < 9.
@@ -2073,11 +2092,11 @@ Object Functions
-
+
Retrieve all the property names of an object.
@@ -2091,11 +2110,11 @@ Object Functions
-
+
Ahem, IE < 9.
@@ -2108,11 +2127,11 @@ Object Functions
-
+
Retrieve the values of an object’s properties.
@@ -2131,11 +2150,11 @@ Object Functions
-
+
Returns the results of applying the iteratee to each element of the object
In contrast to _.map it returns an object
@@ -2158,11 +2177,11 @@ Object Functions
-
+
Convert an object into a list of [key, value]
pairs.
@@ -2181,11 +2200,11 @@ Object Functions
-
+
Invert the keys and values of an object. The values must be serializable.
@@ -2203,11 +2222,11 @@ Object Functions
-
+
Return a sorted list of the function names available on the object.
Aliased as methods
@@ -2225,11 +2244,11 @@ Object Functions
-
+
Extend a given object with all the properties in passed-in object(s).
@@ -2240,11 +2259,11 @@ Object Functions
-
+
Assigns a given object with all the own properties in the passed-in object(s)
(https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
@@ -2256,11 +2275,11 @@ Object Functions
-
+
Returns the first key on an object that passes a predicate test
@@ -2278,11 +2297,11 @@ Object Functions
-
+
Return a copy of the object only containing the whitelisted properties.
@@ -2310,11 +2329,11 @@ Object Functions
-
+
Return a copy of the object without the blacklisted properties.
@@ -2335,11 +2354,11 @@ Object Functions
-
+
Fill in a given object with default properties.
@@ -2350,11 +2369,32 @@ Object Functions
-
+
+ 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.
@@ -2368,11 +2408,11 @@ Object Functions
-
+
Invokes interceptor with the obj, and then returns obj.
The primary purpose of this method is to “tap into” a method chain, in
@@ -2388,11 +2428,11 @@
Object Functions
-
+
Returns whether an object has a given set of key:value
pairs.
@@ -2412,11 +2452,11 @@ Object Functions
-
+
Internal recursive comparison function for isEqual
.
@@ -2427,11 +2467,11 @@ Object Functions
-
+
Identical objects are equal. 0 === -0
, but they aren’t identical.
See the Harmony egal
proposal.
@@ -2443,11 +2483,11 @@ Object Functions
-
+
A strict comparison is necessary because null == undefined
.
@@ -2458,11 +2498,11 @@ Object Functions
-
+
Unwrap any wrapped objects.
@@ -2474,11 +2514,11 @@ Object Functions
-
+
Compare [[Class]]
names.
@@ -2491,11 +2531,11 @@ Object Functions
-
+
Strings, numbers, regular expressions, dates, and booleans are compared by value.
@@ -2506,11 +2546,11 @@ Object Functions
-
+
RegExps are coerced to strings for comparison (Note: ‘’ + /a/i === ‘/a/i’)
@@ -2521,11 +2561,11 @@ Object Functions
-
+
Primitives and their corresponding object wrappers are equivalent; thus, "5"
is
equivalent to new String("5")
.
@@ -2538,11 +2578,11 @@ Object Functions
-
+
NaN
s are equivalent, but non-reflexive.
Object(NaN) is equivalent to NaN
@@ -2554,11 +2594,11 @@ Object Functions
-
+
An egal
comparison is performed for other numeric values.
@@ -2571,11 +2611,11 @@ Object Functions
-
+
Coerce dates and booleans to numeric primitive values. Dates are compared by their
millisecond representations. Note that invalid dates with millisecond representations
@@ -2593,11 +2633,11 @@
Object Functions
-
+
Objects with different constructors are not equivalent, but Object
s or Array
s
from different frames are.
@@ -2615,11 +2655,11 @@ Object Functions
-
+
Assume equality for cyclic structures. The algorithm for detecting cyclic
structures is adapted from ES 5.1 section 15.12.3, abstract operation JO
.
@@ -2629,11 +2669,11 @@ Object Functions
-
+
Initializing stack of traversed objects.
It’s done here since we only need them for objects and arrays comparison.
@@ -2648,11 +2688,11 @@ Object Functions
-
+
Linear search. Performance is inversely proportional to the number of
unique nested structures.
@@ -2665,11 +2705,11 @@ Object Functions
-
+
Add the first object to the stack of traversed objects.
@@ -2681,11 +2721,11 @@ Object Functions
-
+
Recursively compare objects and arrays.
@@ -2696,11 +2736,11 @@ Object Functions
-
+
Compare array lengths to determine if a deep comparison is necessary.
@@ -2712,11 +2752,11 @@ Object Functions
-
+
Deep compare the contents, ignoring non-numeric properties.
@@ -2730,11 +2770,11 @@ Object Functions
-
+
Deep compare objects.
@@ -2746,11 +2786,11 @@ Object Functions
-
+
Ensure that both objects contain the same number of properties before comparing deep equality.
@@ -2762,11 +2802,11 @@ Object Functions
-
+
Deep compare each member
@@ -2780,11 +2820,11 @@ Object Functions
-
+
Remove the first object from the stack of traversed objects.
@@ -2798,11 +2838,11 @@ Object Functions
-
+
Perform a deep comparison to check if two objects are equal.
@@ -2815,11 +2855,11 @@ Object Functions
-
+
Is a given array, string, or object empty?
An “empty” object has no enumerable own-properties.
@@ -2835,11 +2875,11 @@ Object Functions
-
+
Is a given value a DOM element?
@@ -2852,11 +2892,11 @@ Object Functions
-
+
Is a given value an array?
Delegates to ECMA5’s native Array.isArray
@@ -2870,11 +2910,11 @@ Object Functions
-
+
Is a given variable an object?
@@ -2888,11 +2928,11 @@ Object Functions
-
+
Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp, isError.
@@ -2907,11 +2947,11 @@ Object Functions
-
+
Define a fallback version of the method in browsers (ahem, IE < 9), where
there isn’t any inspectable “Arguments” type.
@@ -2927,11 +2967,11 @@ Object Functions
-
+
Optimize isFunction
if appropriate. Work around some typeof bugs in old v8,
IE 11 (#1621), and in Safari 8 (#1929).
@@ -2947,11 +2987,11 @@ Object Functions
-
+
Is a given object a finite number?
@@ -2964,11 +3004,11 @@ Object Functions
-
+
Is the given value NaN
? (NaN is the only number which does not equal itself).
@@ -2981,11 +3021,11 @@ Object Functions
-
+
Is a given value a boolean?
@@ -2998,11 +3038,11 @@ Object Functions
-
+
Is a given value equal to null?
@@ -3015,11 +3055,11 @@ Object Functions
-
+
Is a given variable undefined?
@@ -3032,11 +3072,11 @@ Object Functions
-
+
Shortcut function for checking if an object has a given property directly
on itself (in other words, not on a prototype).
@@ -3050,11 +3090,11 @@ Object Functions
-
+
Utility Functions
@@ -3063,11 +3103,11 @@ Utility Functions
-
+
@@ -3075,11 +3115,11 @@ Utility Functions
-
+
Run Underscore.js in noConflict mode, returning the _
variable to its
previous owner. Returns a reference to the Underscore object.
@@ -3094,11 +3134,11 @@ Utility Functions
-
+
Keep the identity function around for default iteratees.
@@ -3111,11 +3151,11 @@ Utility Functions
-
+
+ _.property = property;
-
+
Generates a function for a given object that returns a given property.
@@ -3157,13 +3193,13 @@ Utility Functions
-
+
- 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.
@@ -3178,11 +3214,11 @@ Utility Functions
-
+
Run a function n times.
@@ -3198,11 +3234,11 @@ Utility Functions
-
+
Return a random integer between min and max (inclusive).
@@ -3219,11 +3255,11 @@ Utility Functions
-
+
A (possibly faster) way to get the current timestamp as an integer.
@@ -3236,11 +3272,11 @@ Utility Functions
-
+
List of HTML entities for escaping.
@@ -3259,11 +3295,11 @@ Utility Functions
-
+
Functions for escaping and unescaping strings to/from HTML interpolation.
@@ -3277,11 +3313,11 @@ Utility Functions
-
+
Regexes for identifying a key that needs to be escaped
@@ -3301,11 +3337,11 @@ Utility Functions
-
+
If the value of the named property
is a function then invoke it with the
object
as context; otherwise, return it.
@@ -3323,11 +3359,11 @@ Utility Functions
-
+
Generate a unique integer id (unique within the entire client session).
Useful for temporary DOM ids.
@@ -3343,11 +3379,11 @@ Utility Functions
-
+
By default, Underscore uses ERB-style template delimiters, change the
following template settings to use alternative delimiters.
@@ -3363,11 +3399,11 @@ Utility Functions
-
+
When customizing templateSettings
, if you don’t want to define an
interpolation, evaluation or escaping regex, we need one that is
@@ -3380,11 +3416,11 @@
Utility Functions
-
+
Certain characters need to be escaped so that they can be put into a
string literal.
@@ -3409,11 +3445,11 @@ Utility Functions
-
+
JavaScript micro-templating, similar to John Resig’s implementation.
Underscore templating handles arbitrary delimiters, preserves whitespace,
@@ -3429,11 +3465,11 @@
Utility Functions
-
+
Combine delimiters into one regular expression via alternation.
@@ -3448,11 +3484,11 @@ Utility Functions
-
+
Compile the template source, escaping string literals appropriately.
@@ -3475,11 +3511,11 @@ Utility Functions
-
+
Adobe VMs need the match returned to produce the correct offest.
@@ -3492,11 +3528,11 @@ Utility Functions
-
+
If a variable is not specified, place data values in local scope.
@@ -3522,11 +3558,11 @@ Utility Functions
-
+
Provide the compiled source as a convenience for precompilation.
@@ -3541,11 +3577,11 @@ Utility Functions
-
+
Add a “chain” function. Start chaining a wrapped Underscore object.
@@ -3560,11 +3596,11 @@ Utility Functions
-
+
OOP
@@ -3573,11 +3609,11 @@ OOP
-
+
If Underscore is called as a function, it returns a wrapped object that
can be used OO-style. This wrapper holds altered versions of all the
@@ -3588,11 +3624,11 @@
OOP
-
+
Helper function to continue chaining intermediate results.
@@ -3605,11 +3641,11 @@ OOP
-
+
Add your own custom functions to the Underscore object.
@@ -3629,11 +3665,11 @@ OOP
-
+
Add all of the Underscore functions to the wrapper object.
@@ -3644,11 +3680,11 @@ OOP
-
+
Add all mutator Array functions to the wrapper.
@@ -3667,11 +3703,11 @@ OOP
-
+
Add all accessor Array functions to the wrapper.
@@ -3687,11 +3723,11 @@ OOP
-
+
Extracts the result from a wrapped and chained object.
@@ -3704,11 +3740,11 @@ OOP
-
+
Provide unwrapping proxy for some methods used in engine operations
such as arithmetic and JSON stringification.
@@ -3716,7 +3752,7 @@ OOP
_.prototype.valueOf = _.prototype.toJSON = _.prototype.value;
-
+
_.prototype.toString = function() {
return '' + this._wrapped;
};
@@ -3724,11 +3760,11 @@ OOP
-
+