/vendor/assets/javascripts/lodash.js
JavaScript | 1472 lines | 1280 code | 33 blank | 159 comment | 32 complexity | 77ffe574b5fe8c7ce0da0ea4ac322ad5 MD5 | raw file
- /**
- * @license
- * Lo-Dash 1.3.0 (Custom Build) <http://lodash.com/>
- * Build: `lodash minus="template" -d`
- * 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>
- */
- ;(function(window) {
- /** Used as a safe reference for `undefined` in pre ES5 environments */
- var undefined;
- /** Used to pool arrays and objects used internally */
- var arrayPool = [],
- objectPool = [];
- /** Used to generate unique IDs */
- var idCounter = 0;
- /** Used internally to indicate various things */
- var indicatorObject = {};
- /** Used to prefix keys to avoid issues with `__proto__` and properties on `Object.prototype` */
- var keyPrefix = +new Date + '';
- /** Used as the size when optimizations are enabled for large arrays */
- var largeArraySize = 75;
- /** Used as the max size of the `arrayPool` and `objectPool` */
- var maxPoolSize = 10;
- /** Used to match empty string literals in compiled template source */
- var reEmptyStringLeading = /\b__p \+= '';/g,
- reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
- reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
- /** Used to match HTML entities */
- var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g;
- /**
- * Used to match ES6 template delimiters
- * http://people.mozilla.org/~jorendorff/es6-draft.html#sec-7.8.6
- */
- var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
- /** Used to match regexp flags from their coerced string values */
- var reFlags = /\w*$/;
- /** Used to match "interpolate" template delimiters */
- var reInterpolate = /<%=([\s\S]+?)%>/g;
- /** Used to detect functions containing a `this` reference */
- var reThis = (reThis = /\bthis\b/) && reThis.test(runInContext) && reThis;
- /** 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;
- /** Used to match unescaped characters in compiled string literals */
- var reUnescapedString = /['\n\r\t\u2028\u2029\\]/g;
- /** Used to assign default `context` object properties */
- var contextProps = [
- 'Array', 'Boolean', 'Date', 'Error', 'Function', 'Math', 'Number', 'Object',
- 'RegExp', 'String', '_', 'attachEvent', 'clearTimeout', 'isFinite', 'isNaN',
- 'parseInt', 'setImmediate', 'setTimeout'
- ];
- /** Used to fix the JScript [[DontEnum]] bug */
- var shadowedProps = [
- 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',
- 'toLocaleString', 'toString', 'valueOf'
- ];
- /** Used to make template sourceURLs easier to identify */
- var templateCounter = 0;
- /** `Object#toString` result shortcuts */
- var argsClass = '[object Arguments]',
- arrayClass = '[object Array]',
- boolClass = '[object Boolean]',
- dateClass = '[object Date]',
- errorClass = '[object Error]',
- funcClass = '[object Function]',
- numberClass = '[object Number]',
- objectClass = '[object Object]',
- regexpClass = '[object RegExp]',
- stringClass = '[object String]';
- /** Used to identify object classifications that `_.clone` supports */
- var cloneableClasses = {};
- cloneableClasses[funcClass] = false;
- cloneableClasses[argsClass] = cloneableClasses[arrayClass] =
- cloneableClasses[boolClass] = cloneableClasses[dateClass] =
- cloneableClasses[numberClass] = cloneableClasses[objectClass] =
- cloneableClasses[regexpClass] = cloneableClasses[stringClass] = true;
- /** Used to determine if values are of the language type Object */
- var objectTypes = {
- 'boolean': false,
- 'function': true,
- 'object': true,
- 'number': false,
- 'string': false,
- 'undefined': false
- };
- /** Used to escape characters for inclusion in compiled string literals */
- var stringEscapes = {
- '\\': '\\',
- "'": "'",
- '\n': 'n',
- '\r': 'r',
- '\t': 't',
- '\u2028': 'u2028',
- '\u2029': 'u2029'
- };
- /** Detect free variable `exports` */
- var freeExports = objectTypes[typeof exports] && exports;
- /** Detect free variable `module` */
- var freeModule = objectTypes[typeof module] && module && module.exports == freeExports && module;
- /** Detect free variable `global`, from Node.js or Browserified code, and use it as `window` */
- var freeGlobal = objectTypes[typeof global] && global;
- if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal)) {
- window = freeGlobal;
- }
- /*--------------------------------------------------------------------------*/
- /**
- * A basic implementation of `_.indexOf` without support for binary searches
- * or `fromIndex` constraints.
- *
- * @private
- * @param {Array} array The array to search.
- * @param {Mixed} value The value to search for.
- * @param {Number} [fromIndex=0] The index to search from.
- * @returns {Number} Returns the index of the matched value or `-1`.
- */
- function basicIndexOf(array, value, fromIndex) {
- var index = (fromIndex || 0) - 1,
- length = array.length;
- while (++index < length) {
- if (array[index] === value) {
- return index;
- }
- }
- return -1;
- }
- /**
- * An implementation of `_.contains` for cache objects that mimics the return
- * signature of `_.indexOf` by returning `0` if the value is found, else `-1`.
- *
- * @private
- * @param {Object} cache The cache object to inspect.
- * @param {Mixed} value The value to search for.
- * @returns {Number} Returns `0` if `value` is found, else `-1`.
- */
- function cacheIndexOf(cache, value) {
- var type = typeof value;
- cache = cache.cache;
- if (type == 'boolean' || value == null) {
- return cache[value];
- }
- if (type != 'number' && type != 'string') {
- type = 'object';
- }
- var key = type == 'number' ? value : keyPrefix + value;
- cache = cache[type] || (cache[type] = {});
- return type == 'object'
- ? (cache[key] && basicIndexOf(cache[key], value) > -1 ? 0 : -1)
- : (cache[key] ? 0 : -1);
- }
- /**
- * Adds a given `value` to the corresponding cache object.
- *
- * @private
- * @param {Mixed} value The value to add to the cache.
- */
- function cachePush(value) {
- var cache = this.cache,
- type = typeof value;
- if (type == 'boolean' || value == null) {
- cache[value] = true;
- } else {
- if (type != 'number' && type != 'string') {
- type = 'object';
- }
- var key = type == 'number' ? value : keyPrefix + value,
- typeCache = cache[type] || (cache[type] = {});
- if (type == 'object') {
- if ((typeCache[key] || (typeCache[key] = [])).push(value) == this.array.length) {
- cache[type] = false;
- }
- } else {
- typeCache[key] = true;
- }
- }
- }
- /**
- * Used by `_.max` and `_.min` as the default `callback` when a given
- * `collection` is a string value.
- *
- * @private
- * @param {String} value The character to inspect.
- * @returns {Number} Returns the code unit of given character.
- */
- function charAtCallback(value) {
- return value.charCodeAt(0);
- }
- /**
- * Used by `sortBy` to compare transformed `collection` values, stable sorting
- * them in ascending order.
- *
- * @private
- * @param {Object} a The object to compare to `b`.
- * @param {Object} b The object to compare to `a`.
- * @returns {Number} Returns the sort order indicator of `1` or `-1`.
- */
- function compareAscending(a, b) {
- var ai = a.index,
- bi = b.index;
- a = a.criteria;
- b = b.criteria;
- // ensure a stable sort in V8 and other engines
- // http://code.google.com/p/v8/issues/detail?id=90
- if (a !== b) {
- if (a > b || typeof a == 'undefined') {
- return 1;
- }
- if (a < b || typeof b == 'undefined') {
- return -1;
- }
- }
- return ai < bi ? -1 : 1;
- }
- /**
- * Creates a cache object to optimize linear searches of large arrays.
- *
- * @private
- * @param {Array} [array=[]] The array to search.
- * @returns {Null|Object} Returns the cache object or `null` if caching should not be used.
- */
- function createCache(array) {
- var index = -1,
- length = array.length;
- var cache = getObject();
- cache['false'] = cache['null'] = cache['true'] = cache['undefined'] = false;
- var result = getObject();
- result.array = array;
- result.cache = cache;
- result.push = cachePush;
- while (++index < length) {
- result.push(array[index]);
- }
- return cache.object === false
- ? (releaseObject(result), null)
- : result;
- }
- /**
- * Used by `template` to escape characters for inclusion in compiled
- * string literals.
- *
- * @private
- * @param {String} match The matched character to escape.
- * @returns {String} Returns the escaped character.
- */
- function escapeStringChar(match) {
- return '\\' + stringEscapes[match];
- }
- /**
- * Gets an array from the array pool or creates a new one if the pool is empty.
- *
- * @private
- * @returns {Array} The array from the pool.
- */
- function getArray() {
- return arrayPool.pop() || [];
- }
- /**
- * Gets an object from the object pool or creates a new one if the pool is empty.
- *
- * @private
- * @returns {Object} The object from the pool.
- */
- function getObject() {
- return objectPool.pop() || {
- 'args': '',
- 'array': null,
- 'bottom': '',
- 'criteria': null,
- 'false': false,
- 'firstArg': '',
- 'index': 0,
- 'init': '',
- 'leading': false,
- 'loop': '',
- 'maxWait': 0,
- 'null': false,
- 'number': null,
- 'object': null,
- 'push': null,
- 'shadowedProps': null,
- 'string': null,
- 'top': '',
- 'trailing': false,
- 'true': false,
- 'undefined': false,
- 'useHas': false,
- 'useKeys': false,
- 'value': null
- };
- }
- /**
- * Checks if `value` is a DOM node in IE < 9.
- *
- * @private
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true` if the `value` is a DOM node, else `false`.
- */
- function isNode(value) {
- // IE < 9 presents DOM nodes as `Object` objects except they have `toString`
- // methods that are `typeof` "string" and still can coerce nodes to strings
- return typeof value.toString != 'function' && typeof (value + '') == 'string';
- }
- /**
- * A no-operation function.
- *
- * @private
- */
- function noop() {
- // no operation performed
- }
- /**
- * Releases the given `array` back to the array pool.
- *
- * @private
- * @param {Array} [array] The array to release.
- */
- function releaseArray(array) {
- if (arrayPool.length == maxPoolSize) {
- arrayPool.length = maxPoolSize - 1;
- }
- array.length = 0;
- arrayPool.push(array);
- }
- /**
- * Releases the given `object` back to the object pool.
- *
- * @private
- * @param {Object} [object] The object to release.
- */
- function releaseObject(object) {
- var cache = object.cache;
- if (cache) {
- releaseObject(cache);
- }
- if (objectPool.length == maxPoolSize) {
- objectPool.length = maxPoolSize - 1;
- }
- object.array = object.cache = object.criteria = object.object = object.number = object.string = object.value = null;
- objectPool.push(object);
- }
- /**
- * Slices the `collection` from the `start` index up to, but not including,
- * the `end` index.
- *
- * Note: This function is used, instead of `Array#slice`, to support node lists
- * in IE < 9 and to ensure dense arrays are returned.
- *
- * @private
- * @param {Array|Object|String} collection The collection to slice.
- * @param {Number} start The start index.
- * @param {Number} end The end index.
- * @returns {Array} Returns the new array.
- */
- function slice(array, start, end) {
- start || (start = 0);
- if (typeof end == 'undefined') {
- end = array ? array.length : 0;
- }
- var index = -1,
- length = end - start || 0,
- result = Array(length < 0 ? 0 : length);
- while (++index < length) {
- result[index] = array[start + index];
- }
- return result;
- }
- /*--------------------------------------------------------------------------*/
- /**
- * Create a new `lodash` function using the given `context` object.
- *
- * @static
- * @memberOf _
- * @category Utilities
- * @param {Object} [context=window] The context object.
- * @returns {Function} Returns the `lodash` function.
- */
- function runInContext(context) {
- // Avoid issues with some ES3 environments that attempt to use values, named
- // after built-in constructors like `Object`, for the creation of literals.
- // ES5 clears this up by stating that literals must use built-in constructors.
- // See http://es5.github.com/#x11.1.5.
- context = context ? _.defaults(window.Object(), context, _.pick(window, contextProps)) : window;
- /** Native constructor references */
- var Array = context.Array,
- Boolean = context.Boolean,
- Date = context.Date,
- Error = context.Error,
- Function = context.Function,
- Math = context.Math,
- Number = context.Number,
- Object = context.Object,
- RegExp = context.RegExp,
- String = context.String,
- TypeError = context.TypeError;
- /**
- * Used for `Array` method references.
- *
- * Normally `Array.prototype` would suffice, however, using an array literal
- * avoids issues in Narwhal.
- */
- var arrayRef = [];
- /** Used for native method references */
- var errorProto = Error.prototype,
- objectProto = Object.prototype,
- stringProto = String.prototype;
- /** Used to restore the original `_` reference in `noConflict` */
- var oldDash = context._;
- /** Used to detect if a method is native */
- var reNative = RegExp('^' +
- String(objectProto.valueOf)
- .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
- .replace(/valueOf|for [^\]]+/g, '.+?') + '$'
- );
- /** Native method shortcuts */
- var ceil = Math.ceil,
- clearTimeout = context.clearTimeout,
- concat = arrayRef.concat,
- floor = Math.floor,
- fnToString = Function.prototype.toString,
- getPrototypeOf = reNative.test(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
- hasOwnProperty = objectProto.hasOwnProperty,
- push = arrayRef.push,
- propertyIsEnumerable = objectProto.propertyIsEnumerable,
- setImmediate = context.setImmediate,
- setTimeout = context.setTimeout,
- toString = objectProto.toString;
- /* Native method shortcuts for methods with the same name as other `lodash` methods */
- var nativeBind = reNative.test(nativeBind = toString.bind) && nativeBind,
- nativeCreate = reNative.test(nativeCreate = Object.create) && nativeCreate,
- nativeIsArray = reNative.test(nativeIsArray = Array.isArray) && nativeIsArray,
- nativeIsFinite = context.isFinite,
- nativeIsNaN = context.isNaN,
- nativeKeys = reNative.test(nativeKeys = Object.keys) && nativeKeys,
- nativeMax = Math.max,
- nativeMin = Math.min,
- nativeParseInt = context.parseInt,
- nativeRandom = Math.random,
- nativeSlice = arrayRef.slice;
- /** Detect various environments */
- var isIeOpera = reNative.test(context.attachEvent),
- isV8 = nativeBind && !/\n|true/.test(nativeBind + isIeOpera);
- /** Used to lookup a built-in constructor by [[Class]] */
- var ctorByClass = {};
- ctorByClass[arrayClass] = Array;
- ctorByClass[boolClass] = Boolean;
- ctorByClass[dateClass] = Date;
- ctorByClass[funcClass] = Function;
- ctorByClass[objectClass] = Object;
- ctorByClass[numberClass] = Number;
- ctorByClass[regexpClass] = RegExp;
- ctorByClass[stringClass] = String;
- /** Used to avoid iterating non-enumerable properties in IE < 9 */
- var nonEnumProps = {};
- nonEnumProps[arrayClass] = nonEnumProps[dateClass] = nonEnumProps[numberClass] = { 'constructor': true, 'toLocaleString': true, 'toString': true, 'valueOf': true };
- nonEnumProps[boolClass] = nonEnumProps[stringClass] = { 'constructor': true, 'toString': true, 'valueOf': true };
- nonEnumProps[errorClass] = nonEnumProps[funcClass] = nonEnumProps[regexpClass] = { 'constructor': true, 'toString': true };
- nonEnumProps[objectClass] = { 'constructor': true };
- (function() {
- var length = shadowedProps.length;
- while (length--) {
- var prop = shadowedProps[length];
- for (var className in nonEnumProps) {
- if (hasOwnProperty.call(nonEnumProps, className) && !hasOwnProperty.call(nonEnumProps[className], prop)) {
- nonEnumProps[className][prop] = false;
- }
- }
- }
- }());
- /*--------------------------------------------------------------------------*/
- /**
- * Creates a `lodash` object, which wraps the given `value`, to enable method
- * chaining.
- *
- * In addition to Lo-Dash methods, wrappers also have the following `Array` methods:
- * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`,
- * and `unshift`
- *
- * Chaining is supported in custom builds as long as the `value` method is
- * implicitly or explicitly included in the build.
- *
- * The chainable wrapper functions are:
- * `after`, `assign`, `bind`, `bindAll`, `bindKey`, `chain`, `compact`,
- * `compose`, `concat`, `countBy`, `createCallback`, `debounce`, `defaults`,
- * `defer`, `delay`, `difference`, `filter`, `flatten`, `forEach`, `forIn`,
- * `forOwn`, `functions`, `groupBy`, `initial`, `intersection`, `invert`,
- * `invoke`, `keys`, `map`, `max`, `memoize`, `merge`, `min`, `object`, `omit`,
- * `once`, `pairs`, `partial`, `partialRight`, `pick`, `pluck`, `push`, `range`,
- * `reject`, `rest`, `reverse`, `shuffle`, `slice`, `sort`, `sortBy`, `splice`,
- * `tap`, `throttle`, `times`, `toArray`, `transform`, `union`, `uniq`, `unshift`,
- * `unzip`, `values`, `where`, `without`, `wrap`, and `zip`
- *
- * The non-chainable wrapper functions are:
- * `clone`, `cloneDeep`, `contains`, `escape`, `every`, `find`, `has`,
- * `identity`, `indexOf`, `isArguments`, `isArray`, `isBoolean`, `isDate`,
- * `isElement`, `isEmpty`, `isEqual`, `isFinite`, `isFunction`, `isNaN`,
- * `isNull`, `isNumber`, `isObject`, `isPlainObject`, `isRegExp`, `isString`,
- * `isUndefined`, `join`, `lastIndexOf`, `mixin`, `noConflict`, `parseInt`,
- * `pop`, `random`, `reduce`, `reduceRight`, `result`, `shift`, `size`, `some`,
- * `sortedIndex`, `runInContext`, `template`, `unescape`, `uniqueId`, and `value`
- *
- * The wrapper functions `first` and `last` return wrapped values when `n` is
- * passed, otherwise they return unwrapped values.
- *
- * @name _
- * @constructor
- * @alias chain
- * @category Chaining
- * @param {Mixed} value The value to wrap in a `lodash` instance.
- * @returns {Object} Returns a `lodash` instance.
- * @example
- *
- * var wrapped = _([1, 2, 3]);
- *
- * // returns an unwrapped value
- * wrapped.reduce(function(sum, num) {
- * return sum + num;
- * });
- * // => 6
- *
- * // returns a wrapped value
- * var squares = wrapped.map(function(num) {
- * return num * num;
- * });
- *
- * _.isArray(squares);
- * // => false
- *
- * _.isArray(squares.value());
- * // => true
- */
- function lodash(value) {
- // don't wrap if already wrapped, even if wrapped by a different `lodash` constructor
- return (value && typeof value == 'object' && !isArray(value) && hasOwnProperty.call(value, '__wrapped__'))
- ? value
- : new lodashWrapper(value);
- }
- /**
- * A fast path for creating `lodash` wrapper objects.
- *
- * @private
- * @param {Mixed} value The value to wrap in a `lodash` instance.
- * @returns {Object} Returns a `lodash` instance.
- */
- function lodashWrapper(value) {
- this.__wrapped__ = value;
- }
- // ensure `new lodashWrapper` is an instance of `lodash`
- lodashWrapper.prototype = lodash.prototype;
- /**
- * An object used to flag environments features.
- *
- * @static
- * @memberOf _
- * @type Object
- */
- var support = lodash.support = {};
- (function() {
- var ctor = function() { this.x = 1; },
- object = { '0': 1, 'length': 1 },
- props = [];
- ctor.prototype = { 'valueOf': 1, 'y': 1 };
- for (var prop in new ctor) { props.push(prop); }
- for (prop in arguments) { }
- /**
- * Detect if `arguments` objects are `Object` objects (all but Narwhal and Opera < 10.5).
- *
- * @memberOf _.support
- * @type Boolean
- */
- support.argsObject = arguments.constructor == Object && !(arguments instanceof Array);
- /**
- * Detect if an `arguments` object's [[Class]] is resolvable (all but Firefox < 4, IE < 9).
- *
- * @memberOf _.support
- * @type Boolean
- */
- support.argsClass = isArguments(arguments);
- /**
- * Detect if `name` or `message` properties of `Error.prototype` are
- * enumerable by default. (IE < 9, Safari < 5.1)
- *
- * @memberOf _.support
- * @type Boolean
- */
- support.enumErrorProps = propertyIsEnumerable.call(errorProto, 'message') || propertyIsEnumerable.call(errorProto, 'name');
- /**
- * Detect if `prototype` properties are enumerable by default.
- *
- * Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1
- * (if the prototype or a property on the prototype has been set)
- * incorrectly sets a function's `prototype` property [[Enumerable]]
- * value to `true`.
- *
- * @memberOf _.support
- * @type Boolean
- */
- support.enumPrototypes = propertyIsEnumerable.call(ctor, 'prototype');
- /**
- * Detect if `Function#bind` exists and is inferred to be fast (all but V8).
- *
- * @memberOf _.support
- * @type Boolean
- */
- support.fastBind = nativeBind && !isV8;
- /**
- * Detect if own properties are iterated after inherited properties (all but IE < 9).
- *
- * @memberOf _.support
- * @type Boolean
- */
- support.ownLast = props[0] != 'x';
- /**
- * Detect if `arguments` object indexes are non-enumerable
- * (Firefox < 4, IE < 9, PhantomJS, Safari < 5.1).
- *
- * @memberOf _.support
- * @type Boolean
- */
- support.nonEnumArgs = prop != 0;
- /**
- * Detect if properties shadowing those on `Object.prototype` are non-enumerable.
- *
- * In IE < 9 an objects own properties, shadowing non-enumerable ones, are
- * made non-enumerable as well (a.k.a the JScript [[DontEnum]] bug).
- *
- * @memberOf _.support
- * @type Boolean
- */
- support.nonEnumShadows = !/valueOf/.test(props);
- /**
- * Detect if `Array#shift` and `Array#splice` augment array-like objects correctly.
- *
- * Firefox < 10, IE compatibility mode, and IE < 9 have buggy Array `shift()`
- * and `splice()` functions that fail to remove the last element, `value[0]`,
- * of array-like objects even though the `length` property is set to `0`.
- * The `shift()` method is buggy in IE 8 compatibility mode, while `splice()`
- * is buggy regardless of mode in IE < 9 and buggy in compatibility mode in IE 9.
- *
- * @memberOf _.support
- * @type Boolean
- */
- support.spliceObjects = (arrayRef.splice.call(object, 0, 1), !object[0]);
- /**
- * Detect lack of support for accessing string characters by index.
- *
- * IE < 8 can't access characters by index and IE 8 can only access
- * characters by index on string literals.
- *
- * @memberOf _.support
- * @type Boolean
- */
- support.unindexedChars = ('x'[0] + Object('x')[0]) != 'xx';
- /**
- * Detect if a DOM node's [[Class]] is resolvable (all but IE < 9)
- * and that the JS engine errors when attempting to coerce an object to
- * a string without a `toString` function.
- *
- * @memberOf _.support
- * @type Boolean
- */
- try {
- support.nodeClass = !(toString.call(document) == objectClass && !({ 'toString': 0 } + ''));
- } catch(e) {
- support.nodeClass = true;
- }
- }(1));
- /*--------------------------------------------------------------------------*/
- /**
- * The template used to create iterator functions.
- *
- * @private
- * @param {Object} data The data object used to populate the text.
- * @returns {String} Returns the interpolated text.
- */
- var iteratorTemplate = function(obj) {
- var __p = 'var index, iterable = ' +
- (obj.firstArg) +
- ', result = ' +
- (obj.init) +
- ';\nif (!iterable) return result;\n' +
- (obj.top) +
- ';';
- if (obj.array) {
- __p += '\nvar length = iterable.length; index = -1;\nif (' +
- (obj.array) +
- ') { ';
- if (support.unindexedChars) {
- __p += '\n if (isString(iterable)) {\n iterable = iterable.split(\'\')\n } ';
- }
- __p += '\n while (++index < length) {\n ' +
- (obj.loop) +
- ';\n }\n}\nelse { ';
- } else if (support.nonEnumArgs) {
- __p += '\n var length = iterable.length; index = -1;\n if (length && isArguments(iterable)) {\n while (++index < length) {\n index += \'\';\n ' +
- (obj.loop) +
- ';\n }\n } else { ';
- }
- if (support.enumPrototypes) {
- __p += '\n var skipProto = typeof iterable == \'function\';\n ';
- }
- if (support.enumErrorProps) {
- __p += '\n var skipErrorProps = iterable === errorProto || iterable instanceof Error;\n ';
- }
- var conditions = []; if (support.enumPrototypes) { conditions.push('!(skipProto && index == "prototype")'); } if (support.enumErrorProps) { conditions.push('!(skipErrorProps && (index == "message" || index == "name"))'); }
- if (obj.useHas && obj.useKeys) {
- __p += '\n var ownIndex = -1,\n ownProps = objectTypes[typeof iterable] && keys(iterable),\n length = ownProps ? ownProps.length : 0;\n\n while (++ownIndex < length) {\n index = ownProps[ownIndex];\n';
- if (conditions.length) {
- __p += ' if (' +
- (conditions.join(' && ')) +
- ') {\n ';
- }
- __p +=
- (obj.loop) +
- '; ';
- if (conditions.length) {
- __p += '\n }';
- }
- __p += '\n } ';
- } else {
- __p += '\n for (index in iterable) {\n';
- if (obj.useHas) { conditions.push("hasOwnProperty.call(iterable, index)"); } if (conditions.length) {
- __p += ' if (' +
- (conditions.join(' && ')) +
- ') {\n ';
- }
- __p +=
- (obj.loop) +
- '; ';
- if (conditions.length) {
- __p += '\n }';
- }
- __p += '\n } ';
- if (support.nonEnumShadows) {
- __p += '\n\n if (iterable !== objectProto) {\n var ctor = iterable.constructor,\n isProto = iterable === (ctor && ctor.prototype),\n className = iterable === stringProto ? stringClass : iterable === errorProto ? errorClass : toString.call(iterable),\n nonEnum = nonEnumProps[className];\n ';
- for (k = 0; k < 7; k++) {
- __p += '\n index = \'' +
- (obj.shadowedProps[k]) +
- '\';\n if ((!(isProto && nonEnum[index]) && hasOwnProperty.call(iterable, index))';
- if (!obj.useHas) {
- __p += ' || (!nonEnum[index] && iterable[index] !== objectProto[index])';
- }
- __p += ') {\n ' +
- (obj.loop) +
- ';\n } ';
- }
- __p += '\n } ';
- }
- }
- if (obj.array || support.nonEnumArgs) {
- __p += '\n}';
- }
- __p +=
- (obj.bottom) +
- ';\nreturn result';
- return __p
- };
- /** Reusable iterator options for `assign` and `defaults` */
- var defaultsIteratorOptions = {
- 'args': 'object, source, guard',
- 'top':
- 'var args = arguments,\n' +
- ' argsIndex = 0,\n' +
- " argsLength = typeof guard == 'number' ? 2 : args.length;\n" +
- 'while (++argsIndex < argsLength) {\n' +
- ' iterable = args[argsIndex];\n' +
- ' if (iterable && objectTypes[typeof iterable]) {',
- 'loop': "if (typeof result[index] == 'undefined') result[index] = iterable[index]",
- 'bottom': ' }\n}'
- };
- /** Reusable iterator options shared by `each`, `forIn`, and `forOwn` */
- var eachIteratorOptions = {
- 'args': 'collection, callback, thisArg',
- 'top': "callback = callback && typeof thisArg == 'undefined' ? callback : lodash.createCallback(callback, thisArg)",
- 'array': "typeof length == 'number'",
- 'loop': 'if (callback(iterable[index], index, collection) === false) return result'
- };
- /** Reusable iterator options for `forIn` and `forOwn` */
- var forOwnIteratorOptions = {
- 'top': 'if (!objectTypes[typeof iterable]) return result;\n' + eachIteratorOptions.top,
- 'array': false
- };
- /*--------------------------------------------------------------------------*/
- /**
- * Creates a function that, when called, invokes `func` with the `this` binding
- * of `thisArg` and prepends any `partialArgs` to the arguments passed to the
- * bound function.
- *
- * @private
- * @param {Function|String} func The function to bind or the method name.
- * @param {Mixed} [thisArg] The `this` binding of `func`.
- * @param {Array} partialArgs An array of arguments to be partially applied.
- * @param {Object} [idicator] Used to indicate binding by key or partially
- * applying arguments from the right.
- * @returns {Function} Returns the new bound function.
- */
- function createBound(func, thisArg, partialArgs, indicator) {
- var isFunc = isFunction(func),
- isPartial = !partialArgs,
- key = thisArg;
- // juggle arguments
- if (isPartial) {
- var rightIndicator = indicator;
- partialArgs = thisArg;
- }
- else if (!isFunc) {
- if (!indicator) {
- throw new TypeError;
- }
- thisArg = func;
- }
- function bound() {
- // `Function#bind` spec
- // http://es5.github.com/#x15.3.4.5
- var args = arguments,
- thisBinding = isPartial ? this : thisArg;
- if (!isFunc) {
- func = thisArg[key];
- }
- if (partialArgs.length) {
- args = args.length
- ? (args = nativeSlice.call(args), rightIndicator ? args.concat(partialArgs) : partialArgs.concat(args))
- : partialArgs;
- }
- if (this instanceof bound) {
- // ensure `new bound` is an instance of `func`
- thisBinding = createObject(func.prototype);
- // mimic the constructor's `return` behavior
- // http://es5.github.com/#x13.2.2
- var result = func.apply(thisBinding, args);
- return isObject(result) ? result : thisBinding;
- }
- return func.apply(thisBinding, args);
- }
- return bound;
- }
- /**
- * Creates compiled iteration functions.
- *
- * @private
- * @param {Object} [options1, options2, ...] The compile options object(s).
- * array - A string of code to determine if the iterable is an array or array-like.
- * useHas - A boolean to specify using `hasOwnProperty` checks in the object loop.
- * useKeys - A boolean to specify using `_.keys` for own property iteration.
- * args - A string of comma separated arguments the iteration function will accept.
- * top - A string of code to execute before the iteration branches.
- * loop - A string of code to execute in the object loop.
- * bottom - A string of code to execute after the iteration branches.
- * @returns {Function} Returns the compiled function.
- */
- function createIterator() {
- var data = getObject();
- // data properties
- data.shadowedProps = shadowedProps;
- // iterator options
- data.array = data.bottom = data.loop = data.top = '';
- data.init = 'iterable';
- data.useHas = true;
- data.useKeys = !!keys;
- // merge options into a template data object
- for (var object, index = 0; object = arguments[index]; index++) {
- for (var key in object) {
- data[key] = object[key];
- }
- }
- var args = data.args;
- data.firstArg = /^[^,]+/.exec(args)[0];
- // create the function factory
- var factory = Function(
- 'errorClass, errorProto, hasOwnProperty, isArguments, isArray, ' +
- 'isString, keys, lodash, objectProto, objectTypes, nonEnumProps, ' +
- 'stringClass, stringProto, toString',
- 'return function(' + args + ') {\n' + iteratorTemplate(data) + '\n}'
- );
- releaseObject(data);
- // return the compiled function
- return factory(
- errorClass, errorProto, hasOwnProperty, isArguments, isArray,
- isString, keys, lodash, objectProto, objectTypes, nonEnumProps,
- stringClass, stringProto, toString
- );
- }
- /**
- * Creates a new object with the specified `prototype`.
- *
- * @private
- * @param {Object} prototype The prototype object.
- * @returns {Object} Returns the new object.
- */
- function createObject(prototype) {
- return isObject(prototype) ? nativeCreate(prototype) : {};
- }
- // fallback for browsers without `Object.create`
- if (!nativeCreate) {
- var createObject = function(prototype) {
- if (isObject(prototype)) {
- noop.prototype = prototype;
- var result = new noop;
- noop.prototype = null;
- }
- return result || {};
- };
- }
- /**
- * Used by `escape` to convert characters to HTML entities.
- *
- * @private
- * @param {String} match The matched character to escape.
- * @returns {String} Returns the escaped character.
- */
- function escapeHtmlChar(match) {
- return htmlEscapes[match];
- }
- /**
- * Gets the appropriate "indexOf" function. If the `_.indexOf` method is
- * customized, this method returns the custom method, otherwise it returns
- * the `basicIndexOf` function.
- *
- * @private
- * @returns {Function} Returns the "indexOf" function.
- */
- function getIndexOf(array, value, fromIndex) {
- var result = (result = lodash.indexOf) === indexOf ? basicIndexOf : result;
- return result;
- }
- /**
- * Creates a function that juggles arguments, allowing argument overloading
- * for `_.flatten` and `_.uniq`, before passing them to the given `func`.
- *
- * @private
- * @param {Function} func The function to wrap.
- * @returns {Function} Returns the new function.
- */
- function overloadWrapper(func) {
- return function(array, flag, callback, thisArg) {
- // juggle arguments
- if (typeof flag != 'boolean' && flag != null) {
- thisArg = callback;
- callback = !(thisArg && thisArg[flag] === array) ? flag : undefined;
- flag = false;
- }
- if (callback != null) {
- callback = lodash.createCallback(callback, thisArg);
- }
- return func(array, flag, callback, thisArg);
- };
- }
- /**
- * A fallback implementation of `isPlainObject` which checks if a given `value`
- * is an object created by the `Object` constructor, assuming objects created
- * by the `Object` constructor have no inherited enumerable properties and that
- * there are no `Object.prototype` extensions.
- *
- * @private
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true`, if `value` is a plain object, else `false`.
- */
- function shimIsPlainObject(value) {
- var ctor,
- result;
- // avoid non Object objects, `arguments` objects, and DOM elements
- if (!(value && toString.call(value) == objectClass) ||
- (ctor = value.constructor, isFunction(ctor) && !(ctor instanceof ctor)) ||
- (!support.argsClass && isArguments(value)) ||
- (!support.nodeClass && isNode(value))) {
- return false;
- }
- // IE < 9 iterates inherited properties before own properties. If the first
- // iterated property is an object's own property then there are no inherited
- // enumerable properties.
- if (support.ownLast) {
- forIn(value, function(value, key, object) {
- result = hasOwnProperty.call(object, key);
- return false;
- });
- return result !== false;
- }
- // In most environments an object's own properties are iterated before
- // its inherited properties. If the last iterated property is an object's
- // own property then there are no inherited enumerable properties.
- forIn(value, function(value, key) {
- result = key;
- });
- return result === undefined || hasOwnProperty.call(value, result);
- }
- /**
- * Used by `unescape` to convert HTML entities to characters.
- *
- * @private
- * @param {String} match The matched character to unescape.
- * @returns {String} Returns the unescaped character.
- */
- function unescapeHtmlChar(match) {
- return htmlUnescapes[match];
- }
- /*--------------------------------------------------------------------------*/
- /**
- * Checks if `value` is an `arguments` object.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true`, if the `value` is an `arguments` object, else `false`.
- * @example
- *
- * (function() { return _.isArguments(arguments); })(1, 2, 3);
- * // => true
- *
- * _.isArguments([1, 2, 3]);
- * // => false
- */
- function isArguments(value) {
- return toString.call(value) == argsClass;
- }
- // fallback for browsers that can't detect `arguments` objects by [[Class]]
- if (!support.argsClass) {
- isArguments = function(value) {
- 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
- * @param {Object} object The object to inspect.
- * @returns {Array} Returns a new array of property names.
- */
- var shimKeys = createIterator({
- 'args': 'object',
- 'init': '[]',
- 'top': 'if (!(objectTypes[typeof object])) return result',
- 'loop': 'result.push(index)'
- });
- /**
- * Creates an array composed of the own enumerable property names of `object`.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Object} object The object to inspect.
- * @returns {Array} Returns a new array of property names.
- * @example
- *
- * _.keys({ 'one': 1, 'two': 2, 'three': 3 });
- * // => ['one', 'two', 'three'] (order is not guaranteed)
- */
- var keys = !nativeKeys ? shimKeys : function(object) {
- if (!isObject(object)) {
- return [];
- }
- if ((support.enumPrototypes && typeof object == 'function') ||
- (support.nonEnumArgs && object.length && isArguments(object))) {
- return shimKeys(object);
- }
- return nativeKeys(object);
- };
- /**
- * A function compiled to iterate `arguments` objects, arrays, objects, and
- * strings consistenly across environments, executing the `callback` for each
- * element in the `collection`. The `callback` is bound to `thisArg` and invoked
- * with three arguments; (value, index|key, collection). Callbacks may exit
- * iteration early by explicitly returning `false`.
- *
- * @private
- * @type Function
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {Function} [callback=identity] The function called per iteration.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Array|Object|String} Returns `collection`.
- */
- var basicEach = createIterator(eachIteratorOptions);
- /**
- * Used to convert characters to HTML entities:
- *
- * Though the `>` character is escaped for symmetry, characters like `>` and `/`
- * don't require escaping in HTML and have no special meaning unless they're part
- * of a tag or an unquoted attribute value.
- * http://mathiasbynens.be/notes/ambiguous-ampersands (under "semi-related fun fact")
- */
- var htmlEscapes = {
- '&': '&',
- '<': '<',
- '>': '>',
- '"': '"',
- "'": '''
- };
- /** Used to convert HTML entities to characters */
- var htmlUnescapes = invert(htmlEscapes);
- /*--------------------------------------------------------------------------*/
- /**
- * Assigns own enumerable properties of source object(s) to the destination
- * object. Subsequent sources will overwrite property assignments of previous
- * sources. If a `callback` function is passed, it will be executed to produce
- * the assigned values. The `callback` is bound to `thisArg` and invoked with
- * two arguments; (objectValue, sourceValue).
- *
- * @static
- * @memberOf _
- * @type Function
- * @alias extend
- * @category Objects
- * @param {Object} object The destination object.
- * @param {Object} [source1, source2, ...] The source objects.
- * @param {Function} [callback] The function to customize assigning values.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Object} Returns the destination object.
- * @example
- *
- * _.assign({ 'name': 'moe' }, { 'age': 40 });
- * // => { 'name': 'moe', 'age': 40 }
- *
- * var defaults = _.partialRight(_.assign, function(a, b) {
- * return typeof a == 'undefined' ? b : a;
- * });
- *
- * var food = { 'name': 'apple' };
- * defaults(food, { 'name': 'banana', 'type': 'fruit' });
- * // => { 'name': 'apple', 'type': 'fruit' }
- */
- var assign = createIterator(defaultsIteratorOptions, {
- 'top':
- defaultsIteratorOptions.top.replace(';',
- ';\n' +
- "if (argsLength > 3 && typeof args[argsLength - 2] == 'function') {\n" +
- ' var callback = lodash.createCallback(args[--argsLength - 1], args[argsLength--], 2);\n' +
- "} else if (argsLength > 2 && typeof args[argsLength - 1] == 'function') {\n" +
- ' callback = args[--argsLength];\n' +
- '}'
- ),
- 'loop': 'result[index] = callback ? callback(result[index], iterable[index]) : iterable[index]'
- });
- /**
- * Creates a clone of `value`. If `deep` is `true`, nested objects will also
- * be cloned, otherwise they will be assigned by reference. If a `callback`
- * function is passed, it will be executed to produce the cloned values. If
- * `callback` returns `undefined`, cloning will be handled by the method instead.
- * The `callback` is bound to `thisArg` and invoked with one argument; (value).
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} value The value to clone.
- * @param {Boolean} [deep=false] A flag to indicate a deep clone.
- * @param {Function} [callback] The function to customize cloning values.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @param- {Array} [stackA=[]] Tracks traversed source objects.
- * @param- {Array} [stackB=[]] Associates clones with source counterparts.
- * @returns {Mixed} Returns the cloned `value`.
- * @example
- *
- * var stooges = [
- * { 'name': 'moe', 'age': 40 },
- * { 'name': 'larry', 'age': 50 }
- * ];
- *
- * var shallow = _.clone(stooges);
- * shallow[0] === stooges[0];
- * // => true
- *
- * var deep = _.clone(stooges, true);
- * deep[0] === stooges[0];
- * // => false
- *
- * _.mixin({
- * 'clone': _.partialRight(_.clone, function(value) {
- * return _.isElement(value) ? value.cloneNode(false) : undefined;
- * })
- * });
- *
- * var clone = _.clone(document.body);
- * clone.childNodes.length;
- * // => 0
- */
- function clone(value, deep, callback, thisArg, stackA, stackB) {
- var result = value;
- // allows working with "Collections" methods without using their `callback`
- // argument, `index|key`, for this method's `callback`
- if (typeof deep != 'boolean' && deep != null) {
- thisArg = callback;
- callback = deep;
- deep = false;
- }
- if (typeof callback == 'function') {
- callback = (typeof thisArg == 'undefined')
- ? callback
- : lodash.createCallback(callback, thisArg, 1);
- result = callback(result);
- if (typeof result != 'undefined') {
- return result;
- }
- result = value;
- }
- // inspect [[Class]]
- var isObj = isObject(result);
- if (isObj) {
- var className = toString.call(result);
- if (!cloneableClasses[className] || (!support.nodeClass && isNode(result))) {
- return result;
- }
- var isArr = isArray(result);
- }
- // shallow clone
- if (!isObj || !deep) {
- return isObj
- ? (isArr ? slice(result) : assign({}, result))
- : result;
- }
- var ctor = ctorByClass[className];
- switch (className) {
- case boolClass:
- case dateClass:
- return new ctor(+result);
- case numberClass:
- case stringClass:
- return new ctor(result);
- case regexpClass:
- return ctor(result.source, reFlags.exec(result));
- }
- // check for circular references and return corresponding clone
- var initedStack = !stackA;
- stackA || (stackA = getArray());
- stackB || (stackB = getArray());
- var length = stackA.length;
- while (length--) {
- if (stackA[length] == value) {
- return stackB[length];
- }
- }
- // init cloned object
- result = isArr ? ctor(result.length) : {};
- // add array properties assigned by `RegExp#exec`
- if (isArr) {
- if (hasOwnProperty.call(value, 'index')) {
- result.index = value.index;
- }
- if (hasOwnProperty.call(value, 'input')) {
- result.input = value.input;
- }
- }
- // add the source value to the stack of traversed objects
- // and associate it with its clone
- stackA.push(value);
- stackB.push(result);
- // recursively populate clone (susceptible to call stack limits)
- (isArr ? basicEach : forOwn)(value, function(objValue, key) {
- result[key] = clone(objValue, deep, callback, undefined, stackA, stackB);
- });
- if (initedStack) {
- releaseArray(stackA);
- releaseArray(stackB);
- }
- return result;
- }
- /**
- * Creates a deep clone of `value`. If a `callback` function is passed,
- * it will be executed to produce the cloned values. If `callback` returns
- * `undefined`, cloning will be handled by the method instead. The `callback`
- * is bound to `thisArg` and invoked with one argument; (value).
- *
- * Note: This method is loosely based on the structured clone algorithm. Functions
- * and DOM nodes are **not** cloned. The enumerable properties of `arguments` objects and
- * objects created by constructors other than `Object` are cloned to plain `Object` objects.
- * See http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} value The value to deep clone.
- * @param {Function} [callback] The function to customize cloning values.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Mixed} Returns the deep cloned `value`.
- * @example
- *
- * var stooges = [
- * { 'name': 'moe', 'age': 40 },
- * { 'name': 'larry', 'age': 50 }
- * ];
- *
- * var deep = _.cloneDeep(stooges);
- * deep[0] === stooges[0];
- * // => false
- *
- * var view = {
- * 'label': 'docs',
- * 'node': element
- * };
- *
- * var clone = _.cloneDeep(view, function(value) {
- * return _.isElement(value) ? value.cloneNode(true) : undefined;
- * });
- *
- * clone.node == view.node;
- * // => false
- */
- function cloneDeep(value, callback, thisArg) {
- return clone(value, true, callback, thisArg);
- }
- /**
- *