vendor/assets/javascripts/lodash.compat.js in lodash-rails-1.2.0 vs vendor/assets/javascripts/lodash.compat.js in lodash-rails-1.2.1
- old
+ new
@@ -1,8 +1,8 @@
/**
* @license
- * Lo-Dash 1.2.0 (Custom Build) <http://lodash.com/>
+ * Lo-Dash 1.2.1 (Custom Build) <http://lodash.com/>
* Build: `lodash -o ./dist/lodash.compat.js`
* Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/>
* Based on Underscore.js 1.4.4 <http://underscorejs.org/>
* Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
* Available under MIT license <http://lodash.com/license>
@@ -54,13 +54,25 @@
var reFlags = /\w*$/;
/** Used to match "interpolate" template delimiters */
var reInterpolate = /<%=([\s\S]+?)%>/g;
- /** Used to match leading zeros to be removed */
- var reLeadingZeros = /^0+(?=.$)/;
+ /** Used to detect and test whitespace */
+ var whitespace = (
+ // whitespace
+ ' \t\x0B\f\xA0\ufeff' +
+ // line terminators
+ '\n\r\u2028\u2029' +
+
+ // unicode category "Zs" space separators
+ '\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000'
+ );
+
+ /** Used to match leading whitespace and zeros to be removed */
+ var reLeadingSpacesAndZeros = RegExp('^[' + whitespace + ']*0+(?=.$)');
+
/** Used to ensure capturing order of template delimiters */
var reNoMatch = /($^)/;
/** Used to match HTML characters */
var reUnescapedHtml = /[&<>"']/g;
@@ -933,10 +945,30 @@
return value ? hasOwnProperty.call(value, 'callee') : false;
};
}
/**
+ * Checks if `value` is an array.
+ *
+ * @static
+ * @memberOf _
+ * @category Objects
+ * @param {Mixed} value The value to check.
+ * @returns {Boolean} Returns `true`, if the `value` is an array, else `false`.
+ * @example
+ *
+ * (function() { return _.isArray(arguments); })();
+ * // => false
+ *
+ * _.isArray([1, 2, 3]);
+ * // => true
+ */
+ var isArray = nativeIsArray || function(value) {
+ return value ? (typeof value == 'object' && toString.call(value) == arrayClass) : false;
+ };
+
+ /**
* A fallback implementation of `Object.keys` which produces an array of the
* given object's own enumerable property names.
*
* @private
* @type Function
@@ -1405,33 +1437,10 @@
}
return result;
}
/**
- * Checks if `value` is an array.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true`, if the `value` is an array, else `false`.
- * @example
- *
- * (function() { return _.isArray(arguments); })();
- * // => false
- *
- * _.isArray([1, 2, 3]);
- * // => true
- */
- function isArray(value) {
- // `instanceof` may cause a memory leak in IE 7 if `value` is a host object
- // http://ajaxian.com/archives/working-aroung-the-instanceof-memory-leak
- return (support.argsObject && value instanceof Array) ||
- (nativeIsArray ? nativeIsArray(value) : toString.call(value) == arrayClass);
- }
-
- /**
* Checks if `value` is a boolean value.
*
* @static
* @memberOf _
* @category Objects
@@ -1458,11 +1467,11 @@
*
* _.isDate(new Date);
* // => true
*/
function isDate(value) {
- return value instanceof Date || toString.call(value) == dateClass;
+ return value ? (typeof value == 'object' && toString.call(value) == dateClass) : false;
}
/**
* Checks if `value` is a DOM element.
*
@@ -1762,11 +1771,11 @@
return typeof value == 'function';
}
// fallback for older versions of Chrome and Safari
if (isFunction(/x/)) {
isFunction = function(value) {
- return value instanceof Function || toString.call(value) == funcClass;
+ return typeof value == 'function' && toString.call(value) == funcClass;
};
}
/**
* Checks if `value` is the language type of Object.
@@ -1912,11 +1921,11 @@
*
* _.isRegExp(/moe/);
* // => true
*/
function isRegExp(value) {
- return value instanceof RegExp || toString.call(value) == regexpClass;
+ return value ? (objectTypes[typeof value] && toString.call(value) == regexpClass) : false;
}
/**
* Checks if `value` is a string.
*
@@ -3428,11 +3437,11 @@
}
/**
* Flattens a nested array (the nesting can be to any depth). If `isShallow`
* is truthy, `array` will only be flattened a single level. If `callback`
- * is passed, each element of `array` is passed through a callback` before
+ * is passed, each element of `array` is passed through a `callback` before
* flattening. The `callback` is bound to `thisArg` and invoked with three
* arguments; (value, index, array).
*
* If a property name is passed for `callback`, the created "_.pluck" style
* callback will return the property value of the given element.
@@ -3987,11 +3996,11 @@
/**
* Creates a duplicate-value-free version of the `array` using strict equality
* for comparisons, i.e. `===`. If the `array` is already sorted, passing `true`
* for `isSorted` will run a faster algorithm. If `callback` is passed, each
- * element of `array` is passed through a callback` before uniqueness is computed.
+ * element of `array` is passed through a `callback` before uniqueness is computed.
* The `callback` is bound to `thisArg` and invoked with three arguments; (value, index, array).
*
* If a property name is passed for `callback`, the created "_.pluck" style
* callback will return the property value of the given element.
*
@@ -4450,10 +4459,14 @@
* `wait` milliseconds have elapsed since the last time it was invoked. Pass
* an `options` object to indicate that `func` should be invoked on the leading
* and/or trailing edge of the `wait` timeout. Subsequent calls to the debounced
* function will return the result of the last `func` call.
*
+ * Note: If `leading` and `trailing` options are `true`, `func` will be called
+ * on the trailing edge of the timeout only if the the debounced function is
+ * invoked more than once during the `wait` timeout.
+ *
* @static
* @memberOf _
* @category Functions
* @param {Function} func The function to debounce.
* @param {Number} wait The number of milliseconds to delay.
@@ -4463,20 +4476,26 @@
* @returns {Function} Returns the new debounced function.
* @example
*
* var lazyLayout = _.debounce(calculateLayout, 300);
* jQuery(window).on('resize', lazyLayout);
+ *
+ * jQuery('#postbox').on('click', _.debounce(sendMail, 200, {
+ * 'leading': true,
+ * 'trailing': false
+ * });
*/
function debounce(func, wait, options) {
var args,
+ inited,
result,
thisArg,
timeoutId,
trailing = true;
function delayed() {
- timeoutId = null;
+ inited = timeoutId = null;
if (trailing) {
result = func.apply(thisArg, args);
}
}
if (options === true) {
@@ -4485,19 +4504,19 @@
} else if (options && objectTypes[typeof options]) {
leading = options.leading;
trailing = 'trailing' in options ? options.trailing : trailing;
}
return function() {
- var isLeading = leading && !timeoutId;
args = arguments;
thisArg = this;
-
clearTimeout(timeoutId);
- timeoutId = setTimeout(delayed, wait);
- if (isLeading) {
+ if (!inited && leading) {
+ inited = true;
result = func.apply(thisArg, args);
+ } else {
+ timeoutId = setTimeout(delayed, wait);
}
return result;
};
}
@@ -4663,17 +4682,19 @@
return createBound(func, nativeSlice.call(arguments, 1), null, indicatorObject);
}
/**
* Creates a function that, when executed, will only call the `func` function
- * at most once per every `wait` milliseconds. If the throttled function is
- * invoked more than once during the `wait` timeout, `func` will also be called
- * on the trailing edge of the timeout. Pass an `options` object to indicate
- * that `func` should be invoked on the leading and/or trailing edge of the
- * `wait` timeout. Subsequent calls to the throttled function will return
- * the result of the last `func` call.
+ * at most once per every `wait` milliseconds. Pass an `options` object to
+ * indicate that `func` should be invoked on the leading and/or trailing edge
+ * of the `wait` timeout. Subsequent calls to the throttled function will
+ * return the result of the last `func` call.
*
+ * Note: If `leading` and `trailing` options are `true`, `func` will be called
+ * on the trailing edge of the timeout only if the the throttled function is
+ * invoked more than once during the `wait` timeout.
+ *
* @static
* @memberOf _
* @category Functions
* @param {Function} func The function to throttle.
* @param {Number} wait The number of milliseconds to throttle executions to.
@@ -4683,10 +4704,14 @@
* @returns {Function} Returns the new throttled function.
* @example
*
* var throttled = _.throttle(updatePosition, 100);
* jQuery(window).on('scroll', throttled);
+ *
+ * jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
+ * 'trailing': false
+ * }));
*/
function throttle(func, wait, options) {
var args,
result,
thisArg,
@@ -4694,14 +4719,13 @@
lastCalled = 0,
leading = true,
trailing = true;
function trailingCall() {
- lastCalled = new Date;
timeoutId = null;
-
if (trailing) {
+ lastCalled = new Date;
result = func.apply(thisArg, args);
}
}
if (options === false) {
leading = false;
@@ -4854,27 +4878,30 @@
return this;
}
/**
* Converts the given `value` into an integer of the specified `radix`.
+ * If `radix` is `undefined` or `0`, a `radix` of `10` is used unless the
+ * `value` is a hexadecimal, in which case a `radix` of `16` is used.
*
* Note: This method avoids differences in native ES3 and ES5 `parseInt`
* implementations. See http://es5.github.com/#E.
*
* @static
* @memberOf _
* @category Utilities
- * @param {Mixed} value The value to parse.
+ * @param {String} value The value to parse.
+ * @param {Number} [radix] The radix used to interpret the value to parse.
* @returns {Number} Returns the new integer value.
* @example
*
* _.parseInt('08');
* // => 8
*/
- var parseInt = nativeParseInt('08') == 8 ? nativeParseInt : function(value, radix) {
+ var parseInt = nativeParseInt(whitespace + '08') == 8 ? nativeParseInt : function(value, radix) {
// Firefox and Opera still follow the ES3 specified implementation of `parseInt`
- return nativeParseInt(isString(value) ? value.replace(reLeadingZeros, '') : value, radix || 0);
+ return nativeParseInt(isString(value) ? value.replace(reLeadingSpacesAndZeros, '') : value, radix || 0);
};
/**
* Produces a random number between `min` and `max` (inclusive). If only one
* argument is passed, a number between `0` and the given number will be returned.
@@ -5423,10 +5450,10 @@
*
* @static
* @memberOf _
* @type String
*/
- lodash.VERSION = '1.2.0';
+ lodash.VERSION = '1.2.1';
// add "Chaining" functions to the wrapper
lodash.prototype.toString = wrapperToString;
lodash.prototype.value = wrapperValueOf;
lodash.prototype.valueOf = wrapperValueOf;