PageRenderTime 28ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/files/lodash/2.4.1/lodash.legacy.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 1515 lines | 811 code | 142 blank | 562 comment | 292 complexity | 2ab3cc84a5f752bab109cadf557ec04c MD5 | raw file
  1. /**
  2. * @license
  3. * Lo-Dash 2.4.1 (Custom Build) <http://lodash.com/>
  4. * Build: `lodash legacy -o ./dist/lodash.legacy.js`
  5. * Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/>
  6. * Based on Underscore.js 1.5.2 <http://underscorejs.org/LICENSE>
  7. * Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  8. * Available under MIT license <http://lodash.com/license>
  9. */
  10. ;(function() {
  11. /** Used as a safe reference for `undefined` in pre ES5 environments */
  12. var undefined;
  13. /** Used to pool arrays and objects used internally */
  14. var arrayPool = [],
  15. objectPool = [];
  16. /** Used to generate unique IDs */
  17. var idCounter = 0;
  18. /** Used internally to indicate various things */
  19. var indicatorObject = {};
  20. /** Used to prefix keys to avoid issues with `__proto__` and properties on `Object.prototype` */
  21. var keyPrefix = +new Date + '';
  22. /** Used as the size when optimizations are enabled for large arrays */
  23. var largeArraySize = 75;
  24. /** Used as the max size of the `arrayPool` and `objectPool` */
  25. var maxPoolSize = 40;
  26. /** Used to detect and test whitespace */
  27. var whitespace = (
  28. // whitespace
  29. ' \t\x0B\f\xA0\ufeff' +
  30. // line terminators
  31. '\n\r\u2028\u2029' +
  32. // unicode category "Zs" space separators
  33. '\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000'
  34. );
  35. /** Used to match empty string literals in compiled template source */
  36. var reEmptyStringLeading = /\b__p \+= '';/g,
  37. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  38. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  39. /**
  40. * Used to match ES6 template delimiters
  41. * http://people.mozilla.org/~jorendorff/es6-draft.html#sec-literals-string-literals
  42. */
  43. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  44. /** Used to match regexp flags from their coerced string values */
  45. var reFlags = /\w*$/;
  46. /** Used to match "interpolate" template delimiters */
  47. var reInterpolate = /<%=([\s\S]+?)%>/g;
  48. /** Used to match leading whitespace and zeros to be removed */
  49. var reLeadingSpacesAndZeros = RegExp('^[' + whitespace + ']*0+(?=.$)');
  50. /** Used to ensure capturing order of template delimiters */
  51. var reNoMatch = /($^)/;
  52. /** Used to match unescaped characters in compiled string literals */
  53. var reUnescapedString = /['\n\r\t\u2028\u2029\\]/g;
  54. /** Used to assign default `context` object properties */
  55. var contextProps = [
  56. 'Array', 'Boolean', 'Date', 'Error', 'Function', 'Math', 'Number', 'Object',
  57. 'RegExp', 'String', '_', 'attachEvent', 'clearTimeout', 'isFinite', 'isNaN',
  58. 'parseInt', 'setTimeout'
  59. ];
  60. /** Used to fix the JScript [[DontEnum]] bug */
  61. var shadowedProps = [
  62. 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',
  63. 'toLocaleString', 'toString', 'valueOf'
  64. ];
  65. /** Used to make template sourceURLs easier to identify */
  66. var templateCounter = 0;
  67. /** `Object#toString` result shortcuts */
  68. var argsClass = '[object Arguments]',
  69. arrayClass = '[object Array]',
  70. boolClass = '[object Boolean]',
  71. dateClass = '[object Date]',
  72. errorClass = '[object Error]',
  73. funcClass = '[object Function]',
  74. numberClass = '[object Number]',
  75. objectClass = '[object Object]',
  76. regexpClass = '[object RegExp]',
  77. stringClass = '[object String]';
  78. /** Used to identify object classifications that `_.clone` supports */
  79. var cloneableClasses = {};
  80. cloneableClasses[funcClass] = false;
  81. cloneableClasses[argsClass] = cloneableClasses[arrayClass] =
  82. cloneableClasses[boolClass] = cloneableClasses[dateClass] =
  83. cloneableClasses[numberClass] = cloneableClasses[objectClass] =
  84. cloneableClasses[regexpClass] = cloneableClasses[stringClass] = true;
  85. /** Used as an internal `_.debounce` options object */
  86. var debounceOptions = {
  87. 'leading': false,
  88. 'maxWait': 0,
  89. 'trailing': false
  90. };
  91. /** Used as the data object for `iteratorTemplate` */
  92. var iteratorData = {
  93. 'args': '',
  94. 'array': null,
  95. 'bottom': '',
  96. 'firstArg': '',
  97. 'init': '',
  98. 'keys': null,
  99. 'loop': '',
  100. 'shadowedProps': null,
  101. 'support': null,
  102. 'top': '',
  103. 'useHas': false
  104. };
  105. /** Used to determine if values are of the language type Object */
  106. var objectTypes = {
  107. 'boolean': false,
  108. 'function': true,
  109. 'object': true,
  110. 'number': false,
  111. 'string': false,
  112. 'undefined': false
  113. };
  114. /** Used to escape characters for inclusion in compiled string literals */
  115. var stringEscapes = {
  116. '\\': '\\',
  117. "'": "'",
  118. '\n': 'n',
  119. '\r': 'r',
  120. '\t': 't',
  121. '\u2028': 'u2028',
  122. '\u2029': 'u2029'
  123. };
  124. /** Used as a reference to the global object */
  125. var root = (objectTypes[typeof window] && window) || this;
  126. /** Detect free variable `exports` */
  127. var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
  128. /** Detect free variable `module` */
  129. var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
  130. /** Detect the popular CommonJS extension `module.exports` */
  131. var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
  132. /** Detect free variable `global` from Node.js or Browserified code and use it as `root` */
  133. var freeGlobal = objectTypes[typeof global] && global;
  134. if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal)) {
  135. root = freeGlobal;
  136. }
  137. /*--------------------------------------------------------------------------*/
  138. /**
  139. * The base implementation of `_.indexOf` without support for binary searches
  140. * or `fromIndex` constraints.
  141. *
  142. * @private
  143. * @param {Array} array The array to search.
  144. * @param {*} value The value to search for.
  145. * @param {number} [fromIndex=0] The index to search from.
  146. * @returns {number} Returns the index of the matched value or `-1`.
  147. */
  148. function baseIndexOf(array, value, fromIndex) {
  149. var index = (fromIndex || 0) - 1,
  150. length = array ? array.length : 0;
  151. while (++index < length) {
  152. if (array[index] === value) {
  153. return index;
  154. }
  155. }
  156. return -1;
  157. }
  158. /**
  159. * An implementation of `_.contains` for cache objects that mimics the return
  160. * signature of `_.indexOf` by returning `0` if the value is found, else `-1`.
  161. *
  162. * @private
  163. * @param {Object} cache The cache object to inspect.
  164. * @param {*} value The value to search for.
  165. * @returns {number} Returns `0` if `value` is found, else `-1`.
  166. */
  167. function cacheIndexOf(cache, value) {
  168. var type = typeof value;
  169. cache = cache.cache;
  170. if (type == 'boolean' || value == null) {
  171. return cache[value] ? 0 : -1;
  172. }
  173. if (type != 'number' && type != 'string') {
  174. type = 'object';
  175. }
  176. var key = type == 'number' ? value : keyPrefix + value;
  177. cache = (cache = cache[type]) && cache[key];
  178. return type == 'object'
  179. ? (cache && baseIndexOf(cache, value) > -1 ? 0 : -1)
  180. : (cache ? 0 : -1);
  181. }
  182. /**
  183. * Adds a given value to the corresponding cache object.
  184. *
  185. * @private
  186. * @param {*} value The value to add to the cache.
  187. */
  188. function cachePush(value) {
  189. var cache = this.cache,
  190. type = typeof value;
  191. if (type == 'boolean' || value == null) {
  192. cache[value] = true;
  193. } else {
  194. if (type != 'number' && type != 'string') {
  195. type = 'object';
  196. }
  197. var key = type == 'number' ? value : keyPrefix + value,
  198. typeCache = cache[type] || (cache[type] = {});
  199. if (type == 'object') {
  200. (typeCache[key] || (typeCache[key] = [])).push(value);
  201. } else {
  202. typeCache[key] = true;
  203. }
  204. }
  205. }
  206. /**
  207. * Used by `_.max` and `_.min` as the default callback when a given
  208. * collection is a string value.
  209. *
  210. * @private
  211. * @param {string} value The character to inspect.
  212. * @returns {number} Returns the code unit of given character.
  213. */
  214. function charAtCallback(value) {
  215. return value.charCodeAt(0);
  216. }
  217. /**
  218. * Used by `sortBy` to compare transformed `collection` elements, stable sorting
  219. * them in ascending order.
  220. *
  221. * @private
  222. * @param {Object} a The object to compare to `b`.
  223. * @param {Object} b The object to compare to `a`.
  224. * @returns {number} Returns the sort order indicator of `1` or `-1`.
  225. */
  226. function compareAscending(a, b) {
  227. var ac = a.criteria,
  228. bc = b.criteria,
  229. index = -1,
  230. length = ac.length;
  231. while (++index < length) {
  232. var value = ac[index],
  233. other = bc[index];
  234. if (value !== other) {
  235. if (value > other || typeof value == 'undefined') {
  236. return 1;
  237. }
  238. if (value < other || typeof other == 'undefined') {
  239. return -1;
  240. }
  241. }
  242. }
  243. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  244. // that causes it, under certain circumstances, to return the same value for
  245. // `a` and `b`. See https://github.com/jashkenas/underscore/pull/1247
  246. //
  247. // This also ensures a stable sort in V8 and other engines.
  248. // See http://code.google.com/p/v8/issues/detail?id=90
  249. return a.index - b.index;
  250. }
  251. /**
  252. * Creates a cache object to optimize linear searches of large arrays.
  253. *
  254. * @private
  255. * @param {Array} [array=[]] The array to search.
  256. * @returns {null|Object} Returns the cache object or `null` if caching should not be used.
  257. */
  258. function createCache(array) {
  259. var index = -1,
  260. length = array.length,
  261. first = array[0],
  262. mid = array[(length / 2) | 0],
  263. last = array[length - 1];
  264. if (first && typeof first == 'object' &&
  265. mid && typeof mid == 'object' && last && typeof last == 'object') {
  266. return false;
  267. }
  268. var cache = getObject();
  269. cache['false'] = cache['null'] = cache['true'] = cache['undefined'] = false;
  270. var result = getObject();
  271. result.array = array;
  272. result.cache = cache;
  273. result.push = cachePush;
  274. while (++index < length) {
  275. result.push(array[index]);
  276. }
  277. return result;
  278. }
  279. /**
  280. * Used by `template` to escape characters for inclusion in compiled
  281. * string literals.
  282. *
  283. * @private
  284. * @param {string} match The matched character to escape.
  285. * @returns {string} Returns the escaped character.
  286. */
  287. function escapeStringChar(match) {
  288. return '\\' + stringEscapes[match];
  289. }
  290. /**
  291. * Gets an array from the array pool or creates a new one if the pool is empty.
  292. *
  293. * @private
  294. * @returns {Array} The array from the pool.
  295. */
  296. function getArray() {
  297. return arrayPool.pop() || [];
  298. }
  299. /**
  300. * Gets an object from the object pool or creates a new one if the pool is empty.
  301. *
  302. * @private
  303. * @returns {Object} The object from the pool.
  304. */
  305. function getObject() {
  306. return objectPool.pop() || {
  307. 'array': null,
  308. 'cache': null,
  309. 'criteria': null,
  310. 'false': false,
  311. 'index': 0,
  312. 'null': false,
  313. 'number': null,
  314. 'object': null,
  315. 'push': null,
  316. 'string': null,
  317. 'true': false,
  318. 'undefined': false,
  319. 'value': null
  320. };
  321. }
  322. /**
  323. * Checks if `value` is a DOM node in IE < 9.
  324. *
  325. * @private
  326. * @param {*} value The value to check.
  327. * @returns {boolean} Returns `true` if the `value` is a DOM node, else `false`.
  328. */
  329. function isNode(value) {
  330. // IE < 9 presents DOM nodes as `Object` objects except they have `toString`
  331. // methods that are `typeof` "string" and still can coerce nodes to strings
  332. return typeof value.toString != 'function' && typeof (value + '') == 'string';
  333. }
  334. /**
  335. * Releases the given array back to the array pool.
  336. *
  337. * @private
  338. * @param {Array} [array] The array to release.
  339. */
  340. function releaseArray(array) {
  341. array.length = 0;
  342. if (arrayPool.length < maxPoolSize) {
  343. arrayPool.push(array);
  344. }
  345. }
  346. /**
  347. * Releases the given object back to the object pool.
  348. *
  349. * @private
  350. * @param {Object} [object] The object to release.
  351. */
  352. function releaseObject(object) {
  353. var cache = object.cache;
  354. if (cache) {
  355. releaseObject(cache);
  356. }
  357. object.array = object.cache = object.criteria = object.object = object.number = object.string = object.value = null;
  358. if (objectPool.length < maxPoolSize) {
  359. objectPool.push(object);
  360. }
  361. }
  362. /**
  363. * Slices the `collection` from the `start` index up to, but not including,
  364. * the `end` index.
  365. *
  366. * Note: This function is used instead of `Array#slice` to support node lists
  367. * in IE < 9 and to ensure dense arrays are returned.
  368. *
  369. * @private
  370. * @param {Array|Object|string} collection The collection to slice.
  371. * @param {number} start The start index.
  372. * @param {number} end The end index.
  373. * @returns {Array} Returns the new array.
  374. */
  375. function slice(array, start, end) {
  376. start || (start = 0);
  377. if (typeof end == 'undefined') {
  378. end = array ? array.length : 0;
  379. }
  380. var index = -1,
  381. length = end - start || 0,
  382. result = Array(length < 0 ? 0 : length);
  383. while (++index < length) {
  384. result[index] = array[start + index];
  385. }
  386. return result;
  387. }
  388. /*--------------------------------------------------------------------------*/
  389. /**
  390. * Create a new `lodash` function using the given context object.
  391. *
  392. * @static
  393. * @memberOf _
  394. * @category Utilities
  395. * @param {Object} [context=root] The context object.
  396. * @returns {Function} Returns the `lodash` function.
  397. */
  398. function runInContext(context) {
  399. // Avoid issues with some ES3 environments that attempt to use values, named
  400. // after built-in constructors like `Object`, for the creation of literals.
  401. // ES5 clears this up by stating that literals must use built-in constructors.
  402. // See http://es5.github.io/#x11.1.5.
  403. context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
  404. /** Native constructor references */
  405. var Array = context.Array,
  406. Boolean = context.Boolean,
  407. Date = context.Date,
  408. Error = context.Error,
  409. Function = context.Function,
  410. Math = context.Math,
  411. Number = context.Number,
  412. Object = context.Object,
  413. RegExp = context.RegExp,
  414. String = context.String,
  415. TypeError = context.TypeError;
  416. /**
  417. * Used for `Array` method references.
  418. *
  419. * Normally `Array.prototype` would suffice, however, using an array literal
  420. * avoids issues in Narwhal.
  421. */
  422. var arrayRef = [];
  423. /** Used for native method references */
  424. var errorProto = Error.prototype,
  425. objectProto = Object.prototype,
  426. stringProto = String.prototype;
  427. /** Used to restore the original `_` reference in `noConflict` */
  428. var oldDash = context._;
  429. /** Used to resolve the internal [[Class]] of values */
  430. var toString = objectProto.toString;
  431. /** Native method shortcuts */
  432. var ceil = Math.ceil,
  433. clearTimeout = context.clearTimeout,
  434. floor = Math.floor,
  435. hasOwnProperty = objectProto.hasOwnProperty,
  436. push = arrayRef.push,
  437. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  438. setTimeout = context.setTimeout,
  439. splice = arrayRef.splice;
  440. /* Native method shortcuts for methods with the same name as other `lodash` methods */
  441. var nativeIsFinite = context.isFinite,
  442. nativeIsNaN = context.isNaN,
  443. nativeMax = Math.max,
  444. nativeMin = Math.min,
  445. nativeParseInt = context.parseInt,
  446. nativeRandom = Math.random;
  447. /** Used to lookup a built-in constructor by [[Class]] */
  448. var ctorByClass = {};
  449. ctorByClass[arrayClass] = Array;
  450. ctorByClass[boolClass] = Boolean;
  451. ctorByClass[dateClass] = Date;
  452. ctorByClass[funcClass] = Function;
  453. ctorByClass[objectClass] = Object;
  454. ctorByClass[numberClass] = Number;
  455. ctorByClass[regexpClass] = RegExp;
  456. ctorByClass[stringClass] = String;
  457. /** Used to avoid iterating non-enumerable properties in IE < 9 */
  458. var nonEnumProps = {};
  459. nonEnumProps[arrayClass] = nonEnumProps[dateClass] = nonEnumProps[numberClass] = { 'constructor': true, 'toLocaleString': true, 'toString': true, 'valueOf': true };
  460. nonEnumProps[boolClass] = nonEnumProps[stringClass] = { 'constructor': true, 'toString': true, 'valueOf': true };
  461. nonEnumProps[errorClass] = nonEnumProps[funcClass] = nonEnumProps[regexpClass] = { 'constructor': true, 'toString': true };
  462. nonEnumProps[objectClass] = { 'constructor': true };
  463. (function() {
  464. var length = shadowedProps.length;
  465. while (length--) {
  466. var key = shadowedProps[length];
  467. for (var className in nonEnumProps) {
  468. if (hasOwnProperty.call(nonEnumProps, className) && !hasOwnProperty.call(nonEnumProps[className], key)) {
  469. nonEnumProps[className][key] = false;
  470. }
  471. }
  472. }
  473. }());
  474. /*--------------------------------------------------------------------------*/
  475. /**
  476. * Creates a `lodash` object which wraps the given value to enable intuitive
  477. * method chaining.
  478. *
  479. * In addition to Lo-Dash methods, wrappers also have the following `Array` methods:
  480. * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`,
  481. * and `unshift`
  482. *
  483. * Chaining is supported in custom builds as long as the `value` method is
  484. * implicitly or explicitly included in the build.
  485. *
  486. * The chainable wrapper functions are:
  487. * `after`, `assign`, `bind`, `bindAll`, `bindKey`, `chain`, `compact`,
  488. * `compose`, `concat`, `countBy`, `create`, `createCallback`, `curry`,
  489. * `debounce`, `defaults`, `defer`, `delay`, `difference`, `filter`, `flatten`,
  490. * `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
  491. * `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
  492. * `invoke`, `keys`, `map`, `max`, `memoize`, `merge`, `min`, `object`, `omit`,
  493. * `once`, `pairs`, `partial`, `partialRight`, `pick`, `pluck`, `pull`, `push`,
  494. * `range`, `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`,
  495. * `sortBy`, `splice`, `tap`, `throttle`, `times`, `toArray`, `transform`,
  496. * `union`, `uniq`, `unshift`, `unzip`, `values`, `where`, `without`, `wrap`,
  497. * and `zip`
  498. *
  499. * The non-chainable wrapper functions are:
  500. * `clone`, `cloneDeep`, `contains`, `escape`, `every`, `find`, `findIndex`,
  501. * `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `has`, `identity`,
  502. * `indexOf`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
  503. * `isEmpty`, `isEqual`, `isFinite`, `isFunction`, `isNaN`, `isNull`, `isNumber`,
  504. * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, `join`,
  505. * `lastIndexOf`, `mixin`, `noConflict`, `parseInt`, `pop`, `random`, `reduce`,
  506. * `reduceRight`, `result`, `shift`, `size`, `some`, `sortedIndex`, `runInContext`,
  507. * `template`, `unescape`, `uniqueId`, and `value`
  508. *
  509. * The wrapper functions `first` and `last` return wrapped values when `n` is
  510. * provided, otherwise they return unwrapped values.
  511. *
  512. * Explicit chaining can be enabled by using the `_.chain` method.
  513. *
  514. * @name _
  515. * @constructor
  516. * @category Chaining
  517. * @param {*} value The value to wrap in a `lodash` instance.
  518. * @returns {Object} Returns a `lodash` instance.
  519. * @example
  520. *
  521. * var wrapped = _([1, 2, 3]);
  522. *
  523. * // returns an unwrapped value
  524. * wrapped.reduce(function(sum, num) {
  525. * return sum + num;
  526. * });
  527. * // => 6
  528. *
  529. * // returns a wrapped value
  530. * var squares = wrapped.map(function(num) {
  531. * return num * num;
  532. * });
  533. *
  534. * _.isArray(squares);
  535. * // => false
  536. *
  537. * _.isArray(squares.value());
  538. * // => true
  539. */
  540. function lodash(value) {
  541. // don't wrap if already wrapped, even if wrapped by a different `lodash` constructor
  542. return (value && typeof value == 'object' && !isArray(value) && hasOwnProperty.call(value, '__wrapped__'))
  543. ? value
  544. : new lodashWrapper(value);
  545. }
  546. /**
  547. * A fast path for creating `lodash` wrapper objects.
  548. *
  549. * @private
  550. * @param {*} value The value to wrap in a `lodash` instance.
  551. * @param {boolean} chainAll A flag to enable chaining for all methods
  552. * @returns {Object} Returns a `lodash` instance.
  553. */
  554. function lodashWrapper(value, chainAll) {
  555. this.__chain__ = !!chainAll;
  556. this.__wrapped__ = value;
  557. }
  558. // ensure `new lodashWrapper` is an instance of `lodash`
  559. lodashWrapper.prototype = lodash.prototype;
  560. /**
  561. * An object used to flag environments features.
  562. *
  563. * @static
  564. * @memberOf _
  565. * @type Object
  566. */
  567. var support = lodash.support = {};
  568. (function() {
  569. var ctor = function() { this.x = 1; },
  570. object = { '0': 1, 'length': 1 },
  571. props = [];
  572. ctor.prototype = { 'valueOf': 1, 'y': 1 };
  573. for (var key in new ctor) { props.push(key); }
  574. for (key in arguments) { }
  575. /**
  576. * Detect if an `arguments` object's [[Class]] is resolvable (all but Firefox < 4, IE < 9).
  577. *
  578. * @memberOf _.support
  579. * @type boolean
  580. */
  581. support.argsClass = false;
  582. /**
  583. * Detect if `arguments` objects are `Object` objects (all but Narwhal and Opera < 10.5).
  584. *
  585. * @memberOf _.support
  586. * @type boolean
  587. */
  588. support.argsObject = arguments.constructor == Object && !(arguments instanceof Array);
  589. /**
  590. * Detect if `name` or `message` properties of `Error.prototype` are
  591. * enumerable by default. (IE < 9, Safari < 5.1)
  592. *
  593. * @memberOf _.support
  594. * @type boolean
  595. */
  596. support.enumErrorProps = propertyIsEnumerable.call(errorProto, 'message') || propertyIsEnumerable.call(errorProto, 'name');
  597. /**
  598. * Detect if `prototype` properties are enumerable by default.
  599. *
  600. * Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1
  601. * (if the prototype or a property on the prototype has been set)
  602. * incorrectly sets a function's `prototype` property [[Enumerable]]
  603. * value to `true`.
  604. *
  605. * @memberOf _.support
  606. * @type boolean
  607. */
  608. support.enumPrototypes = propertyIsEnumerable.call(ctor, 'prototype');
  609. /**
  610. * Detect if `arguments` object indexes are non-enumerable
  611. * (Firefox < 4, IE < 9, PhantomJS, Safari < 5.1).
  612. *
  613. * @memberOf _.support
  614. * @type boolean
  615. */
  616. support.nonEnumArgs = key != 0;
  617. /**
  618. * Detect if properties shadowing those on `Object.prototype` are non-enumerable.
  619. *
  620. * In IE < 9 an objects own properties, shadowing non-enumerable ones, are
  621. * made non-enumerable as well (a.k.a the JScript [[DontEnum]] bug).
  622. *
  623. * @memberOf _.support
  624. * @type boolean
  625. */
  626. support.nonEnumShadows = !/valueOf/.test(props);
  627. /**
  628. * Detect if own properties are iterated after inherited properties (all but IE < 9).
  629. *
  630. * @memberOf _.support
  631. * @type boolean
  632. */
  633. support.ownLast = props[0] != 'x';
  634. /**
  635. * Detect if `Array#shift` and `Array#splice` augment array-like objects correctly.
  636. *
  637. * Firefox < 10, IE compatibility mode, and IE < 9 have buggy Array `shift()`
  638. * and `splice()` functions that fail to remove the last element, `value[0]`,
  639. * of array-like objects even though the `length` property is set to `0`.
  640. * The `shift()` method is buggy in IE 8 compatibility mode, while `splice()`
  641. * is buggy regardless of mode in IE < 9 and buggy in compatibility mode in IE 9.
  642. *
  643. * @memberOf _.support
  644. * @type boolean
  645. */
  646. support.spliceObjects = (arrayRef.splice.call(object, 0, 1), !object[0]);
  647. /**
  648. * Detect lack of support for accessing string characters by index.
  649. *
  650. * IE < 8 can't access characters by index and IE 8 can only access
  651. * characters by index on string literals.
  652. *
  653. * @memberOf _.support
  654. * @type boolean
  655. */
  656. support.unindexedChars = ('x'[0] + Object('x')[0]) != 'xx';
  657. /**
  658. * Detect if a DOM node's [[Class]] is resolvable (all but IE < 9)
  659. * and that the JS engine errors when attempting to coerce an object to
  660. * a string without a `toString` function.
  661. *
  662. * @memberOf _.support
  663. * @type boolean
  664. */
  665. try {
  666. support.nodeClass = !(toString.call(document) == objectClass && !({ 'toString': 0 } + ''));
  667. } catch(e) {
  668. support.nodeClass = true;
  669. }
  670. }(1));
  671. /**
  672. * By default, the template delimiters used by Lo-Dash are similar to those in
  673. * embedded Ruby (ERB). Change the following template settings to use alternative
  674. * delimiters.
  675. *
  676. * @static
  677. * @memberOf _
  678. * @type Object
  679. */
  680. lodash.templateSettings = {
  681. /**
  682. * Used to detect `data` property values to be HTML-escaped.
  683. *
  684. * @memberOf _.templateSettings
  685. * @type RegExp
  686. */
  687. 'escape': /<%-([\s\S]+?)%>/g,
  688. /**
  689. * Used to detect code to be evaluated.
  690. *
  691. * @memberOf _.templateSettings
  692. * @type RegExp
  693. */
  694. 'evaluate': /<%([\s\S]+?)%>/g,
  695. /**
  696. * Used to detect `data` property values to inject.
  697. *
  698. * @memberOf _.templateSettings
  699. * @type RegExp
  700. */
  701. 'interpolate': reInterpolate,
  702. /**
  703. * Used to reference the data object in the template text.
  704. *
  705. * @memberOf _.templateSettings
  706. * @type string
  707. */
  708. 'variable': '',
  709. /**
  710. * Used to import variables into the compiled template.
  711. *
  712. * @memberOf _.templateSettings
  713. * @type Object
  714. */
  715. 'imports': {
  716. /**
  717. * A reference to the `lodash` function.
  718. *
  719. * @memberOf _.templateSettings.imports
  720. * @type Function
  721. */
  722. '_': lodash
  723. }
  724. };
  725. /*--------------------------------------------------------------------------*/
  726. /**
  727. * The template used to create iterator functions.
  728. *
  729. * @private
  730. * @param {Object} data The data object used to populate the text.
  731. * @returns {string} Returns the interpolated text.
  732. */
  733. var iteratorTemplate = function(obj) {
  734. var __p = 'var index, iterable = ' +
  735. (obj.firstArg) +
  736. ', result = ' +
  737. (obj.init) +
  738. ';\nif (!iterable) return result;\n' +
  739. (obj.top) +
  740. ';';
  741. if (obj.array) {
  742. __p += '\nvar length = iterable.length; index = -1;\nif (' +
  743. (obj.array) +
  744. ') { ';
  745. if (support.unindexedChars) {
  746. __p += '\n if (isString(iterable)) {\n iterable = iterable.split(\'\')\n } ';
  747. }
  748. __p += '\n while (++index < length) {\n ' +
  749. (obj.loop) +
  750. ';\n }\n}\nelse { ';
  751. } else if (support.nonEnumArgs) {
  752. __p += '\n var length = iterable.length; index = -1;\n if (length && isArguments(iterable)) {\n while (++index < length) {\n index += \'\';\n ' +
  753. (obj.loop) +
  754. ';\n }\n } else { ';
  755. }
  756. if (support.enumPrototypes) {
  757. __p += '\n var skipProto = typeof iterable == \'function\';\n ';
  758. }
  759. if (support.enumErrorProps) {
  760. __p += '\n var skipErrorProps = iterable === errorProto || iterable instanceof Error;\n ';
  761. }
  762. var conditions = []; if (support.enumPrototypes) { conditions.push('!(skipProto && index == "prototype")'); } if (support.enumErrorProps) { conditions.push('!(skipErrorProps && (index == "message" || index == "name"))'); }
  763. __p += '\n for (index in iterable) {\n';
  764. if (obj.useHas) { conditions.push("hasOwnProperty.call(iterable, index)"); } if (conditions.length) {
  765. __p += ' if (' +
  766. (conditions.join(' && ')) +
  767. ') {\n ';
  768. }
  769. __p +=
  770. (obj.loop) +
  771. '; ';
  772. if (conditions.length) {
  773. __p += '\n }';
  774. }
  775. __p += '\n } ';
  776. if (support.nonEnumShadows) {
  777. __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 ';
  778. for (k = 0; k < 7; k++) {
  779. __p += '\n index = \'' +
  780. (obj.shadowedProps[k]) +
  781. '\';\n if ((!(isProto && nonEnum[index]) && hasOwnProperty.call(iterable, index))';
  782. if (!obj.useHas) {
  783. __p += ' || (!nonEnum[index] && iterable[index] !== objectProto[index])';
  784. }
  785. __p += ') {\n ' +
  786. (obj.loop) +
  787. ';\n } ';
  788. }
  789. __p += '\n } ';
  790. }
  791. if (obj.array || support.nonEnumArgs) {
  792. __p += '\n}';
  793. }
  794. __p +=
  795. (obj.bottom) +
  796. ';\nreturn result';
  797. return __p
  798. };
  799. /*--------------------------------------------------------------------------*/
  800. /**
  801. * The base implementation of `_.bind` that creates the bound function and
  802. * sets its meta data.
  803. *
  804. * @private
  805. * @param {Array} bindData The bind data array.
  806. * @returns {Function} Returns the new bound function.
  807. */
  808. function baseBind(bindData) {
  809. var func = bindData[0],
  810. partialArgs = bindData[2],
  811. thisArg = bindData[4];
  812. function bound() {
  813. // `Function#bind` spec
  814. // http://es5.github.io/#x15.3.4.5
  815. if (partialArgs) {
  816. // avoid `arguments` object deoptimizations by using `slice` instead
  817. // of `Array.prototype.slice.call` and not assigning `arguments` to a
  818. // variable as a ternary expression
  819. var args = slice(partialArgs);
  820. push.apply(args, arguments);
  821. }
  822. // mimic the constructor's `return` behavior
  823. // http://es5.github.io/#x13.2.2
  824. if (this instanceof bound) {
  825. // ensure `new bound` is an instance of `func`
  826. var thisBinding = baseCreate(func.prototype),
  827. result = func.apply(thisBinding, args || arguments);
  828. return isObject(result) ? result : thisBinding;
  829. }
  830. return func.apply(thisArg, args || arguments);
  831. }
  832. return bound;
  833. }
  834. /**
  835. * The base implementation of `_.clone` without argument juggling or support
  836. * for `thisArg` binding.
  837. *
  838. * @private
  839. * @param {*} value The value to clone.
  840. * @param {boolean} [isDeep=false] Specify a deep clone.
  841. * @param {Function} [callback] The function to customize cloning values.
  842. * @param {Array} [stackA=[]] Tracks traversed source objects.
  843. * @param {Array} [stackB=[]] Associates clones with source counterparts.
  844. * @returns {*} Returns the cloned value.
  845. */
  846. function baseClone(value, isDeep, callback, stackA, stackB) {
  847. if (callback) {
  848. var result = callback(value);
  849. if (typeof result != 'undefined') {
  850. return result;
  851. }
  852. }
  853. // inspect [[Class]]
  854. var isObj = isObject(value);
  855. if (isObj) {
  856. var className = toString.call(value);
  857. if (!cloneableClasses[className] || (!support.nodeClass && isNode(value))) {
  858. return value;
  859. }
  860. var ctor = ctorByClass[className];
  861. switch (className) {
  862. case boolClass:
  863. case dateClass:
  864. return new ctor(+value);
  865. case numberClass:
  866. case stringClass:
  867. return new ctor(value);
  868. case regexpClass:
  869. result = ctor(value.source, reFlags.exec(value));
  870. result.lastIndex = value.lastIndex;
  871. return result;
  872. }
  873. } else {
  874. return value;
  875. }
  876. var isArr = isArray(value);
  877. if (isDeep) {
  878. // check for circular references and return corresponding clone
  879. var initedStack = !stackA;
  880. stackA || (stackA = getArray());
  881. stackB || (stackB = getArray());
  882. var length = stackA.length;
  883. while (length--) {
  884. if (stackA[length] == value) {
  885. return stackB[length];
  886. }
  887. }
  888. result = isArr ? ctor(value.length) : {};
  889. }
  890. else {
  891. result = isArr ? slice(value) : assign({}, value);
  892. }
  893. // add array properties assigned by `RegExp#exec`
  894. if (isArr) {
  895. if (hasOwnProperty.call(value, 'index')) {
  896. result.index = value.index;
  897. }
  898. if (hasOwnProperty.call(value, 'input')) {
  899. result.input = value.input;
  900. }
  901. }
  902. // exit for shallow clone
  903. if (!isDeep) {
  904. return result;
  905. }
  906. // add the source value to the stack of traversed objects
  907. // and associate it with its clone
  908. stackA.push(value);
  909. stackB.push(result);
  910. // recursively populate clone (susceptible to call stack limits)
  911. (isArr ? baseEach : forOwn)(value, function(objValue, key) {
  912. result[key] = baseClone(objValue, isDeep, callback, stackA, stackB);
  913. });
  914. if (initedStack) {
  915. releaseArray(stackA);
  916. releaseArray(stackB);
  917. }
  918. return result;
  919. }
  920. /**
  921. * The base implementation of `_.create` without support for assigning
  922. * properties to the created object.
  923. *
  924. * @private
  925. * @param {Object} prototype The object to inherit from.
  926. * @returns {Object} Returns the new object.
  927. */
  928. var baseCreate = (function() {
  929. function Object() {}
  930. return function(prototype) {
  931. if (isObject(prototype)) {
  932. Object.prototype = prototype;
  933. var result = new Object;
  934. Object.prototype = null;
  935. }
  936. return result || context.Object();
  937. };
  938. }());
  939. /**
  940. * The base implementation of `_.createCallback` without support for creating
  941. * "_.pluck" or "_.where" style callbacks.
  942. *
  943. * @private
  944. * @param {*} [func=identity] The value to convert to a callback.
  945. * @param {*} [thisArg] The `this` binding of the created callback.
  946. * @param {number} [argCount] The number of arguments the callback accepts.
  947. * @returns {Function} Returns a callback function.
  948. */
  949. function baseCreateCallback(func, thisArg, argCount) {
  950. if (typeof func != 'function') {
  951. return identity;
  952. }
  953. // exit early for no `thisArg` or already bound by `Function#bind`
  954. if (typeof thisArg == 'undefined' || !('prototype' in func)) {
  955. return func;
  956. }
  957. switch (argCount) {
  958. case 1: return function(value) {
  959. return func.call(thisArg, value);
  960. };
  961. case 2: return function(a, b) {
  962. return func.call(thisArg, a, b);
  963. };
  964. case 3: return function(value, index, collection) {
  965. return func.call(thisArg, value, index, collection);
  966. };
  967. case 4: return function(accumulator, value, index, collection) {
  968. return func.call(thisArg, accumulator, value, index, collection);
  969. };
  970. }
  971. return bind(func, thisArg);
  972. }
  973. /**
  974. * The base implementation of `createWrapper` that creates the wrapper and
  975. * sets its meta data.
  976. *
  977. * @private
  978. * @param {Array} bindData The bind data array.
  979. * @returns {Function} Returns the new function.
  980. */
  981. function baseCreateWrapper(bindData) {
  982. var func = bindData[0],
  983. bitmask = bindData[1],
  984. partialArgs = bindData[2],
  985. partialRightArgs = bindData[3],
  986. thisArg = bindData[4],
  987. arity = bindData[5];
  988. var isBind = bitmask & 1,
  989. isBindKey = bitmask & 2,
  990. isCurry = bitmask & 4,
  991. isCurryBound = bitmask & 8,
  992. key = func;
  993. function bound() {
  994. var thisBinding = isBind ? thisArg : this;
  995. if (partialArgs) {
  996. var args = slice(partialArgs);
  997. push.apply(args, arguments);
  998. }
  999. if (partialRightArgs || isCurry) {
  1000. args || (args = slice(arguments));
  1001. if (partialRightArgs) {
  1002. push.apply(args, partialRightArgs);
  1003. }
  1004. if (isCurry && args.length < arity) {
  1005. bitmask |= 16 & ~32;
  1006. return baseCreateWrapper([func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity]);
  1007. }
  1008. }
  1009. args || (args = arguments);
  1010. if (isBindKey) {
  1011. func = thisBinding[key];
  1012. }
  1013. if (this instanceof bound) {
  1014. thisBinding = baseCreate(func.prototype);
  1015. var result = func.apply(thisBinding, args);
  1016. return isObject(result) ? result : thisBinding;
  1017. }
  1018. return func.apply(thisBinding, args);
  1019. }
  1020. return bound;
  1021. }
  1022. /**
  1023. * The base implementation of `_.difference` that accepts a single array
  1024. * of values to exclude.
  1025. *
  1026. * @private
  1027. * @param {Array} array The array to process.
  1028. * @param {Array} [values] The array of values to exclude.
  1029. * @returns {Array} Returns a new array of filtered values.
  1030. */
  1031. function baseDifference(array, values) {
  1032. var index = -1,
  1033. indexOf = getIndexOf(),
  1034. length = array ? array.length : 0,
  1035. isLarge = length >= largeArraySize && indexOf === baseIndexOf,
  1036. result = [];
  1037. if (isLarge) {
  1038. var cache = createCache(values);
  1039. if (cache) {
  1040. indexOf = cacheIndexOf;
  1041. values = cache;
  1042. } else {
  1043. isLarge = false;
  1044. }
  1045. }
  1046. while (++index < length) {
  1047. var value = array[index];
  1048. if (indexOf(values, value) < 0) {
  1049. result.push(value);
  1050. }
  1051. }
  1052. if (isLarge) {
  1053. releaseObject(values);
  1054. }
  1055. return result;
  1056. }
  1057. /**
  1058. * The base implementation of `_.flatten` without support for callback
  1059. * shorthands or `thisArg` binding.
  1060. *
  1061. * @private
  1062. * @param {Array} array The array to flatten.
  1063. * @param {boolean} [isShallow=false] A flag to restrict flattening to a single level.
  1064. * @param {boolean} [isStrict=false] A flag to restrict flattening to arrays and `arguments` objects.
  1065. * @param {number} [fromIndex=0] The index to start from.
  1066. * @returns {Array} Returns a new flattened array.
  1067. */
  1068. function baseFlatten(array, isShallow, isStrict, fromIndex) {
  1069. var index = (fromIndex || 0) - 1,
  1070. length = array ? array.length : 0,
  1071. result = [];
  1072. while (++index < length) {
  1073. var value = array[index];
  1074. if (value && typeof value == 'object' && typeof value.length == 'number'
  1075. && (isArray(value) || isArguments(value))) {
  1076. // recursively flatten arrays (susceptible to call stack limits)
  1077. if (!isShallow) {
  1078. value = baseFlatten(value, isShallow, isStrict);
  1079. }
  1080. var valIndex = -1,
  1081. valLength = value.length,
  1082. resIndex = result.length;
  1083. result.length += valLength;
  1084. while (++valIndex < valLength) {
  1085. result[resIndex++] = value[valIndex];
  1086. }
  1087. } else if (!isStrict) {
  1088. result.push(value);
  1089. }
  1090. }
  1091. return result;
  1092. }
  1093. /**
  1094. * The base implementation of `_.isEqual`, without support for `thisArg` binding,
  1095. * that allows partial "_.where" style comparisons.
  1096. *
  1097. * @private
  1098. * @param {*} a The value to compare.
  1099. * @param {*} b The other value to compare.
  1100. * @param {Function} [callback] The function to customize comparing values.
  1101. * @param {Function} [isWhere=false] A flag to indicate performing partial comparisons.
  1102. * @param {Array} [stackA=[]] Tracks traversed `a` objects.
  1103. * @param {Array} [stackB=[]] Tracks traversed `b` objects.
  1104. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  1105. */
  1106. function baseIsEqual(a, b, callback, isWhere, stackA, stackB) {
  1107. // used to indicate that when comparing objects, `a` has at least the properties of `b`
  1108. if (callback) {
  1109. var result = callback(a, b);
  1110. if (typeof result != 'undefined') {
  1111. return !!result;
  1112. }
  1113. }
  1114. // exit early for identical values
  1115. if (a === b) {
  1116. // treat `+0` vs. `-0` as not equal
  1117. return a !== 0 || (1 / a == 1 / b);
  1118. }
  1119. var type = typeof a,
  1120. otherType = typeof b;
  1121. // exit early for unlike primitive values
  1122. if (a === a &&
  1123. !(a && objectTypes[type]) &&
  1124. !(b && objectTypes[otherType])) {
  1125. return false;
  1126. }
  1127. // exit early for `null` and `undefined` avoiding ES3's Function#call behavior
  1128. // http://es5.github.io/#x15.3.4.4
  1129. if (a == null || b == null) {
  1130. return a === b;
  1131. }
  1132. // compare [[Class]] names
  1133. var className = toString.call(a),
  1134. otherClass = toString.call(b);
  1135. if (className == argsClass) {
  1136. className = objectClass;
  1137. }
  1138. if (otherClass == argsClass) {
  1139. otherClass = objectClass;
  1140. }
  1141. if (className != otherClass) {
  1142. return false;
  1143. }
  1144. switch (className) {
  1145. case boolClass:
  1146. case dateClass:
  1147. // coerce dates and booleans to numbers, dates to milliseconds and booleans
  1148. // to `1` or `0` treating invalid dates coerced to `NaN` as not equal
  1149. return +a == +b;
  1150. case numberClass:
  1151. // treat `NaN` vs. `NaN` as equal
  1152. return (a != +a)
  1153. ? b != +b
  1154. // but treat `+0` vs. `-0` as not equal
  1155. : (a == 0 ? (1 / a == 1 / b) : a == +b);
  1156. case regexpClass:
  1157. case stringClass:
  1158. // coerce regexes to strings (http://es5.github.io/#x15.10.6.4)
  1159. // treat string primitives and their corresponding object instances as equal
  1160. return a == String(b);
  1161. }
  1162. var isArr = className == arrayClass;
  1163. if (!isArr) {
  1164. // unwrap any `lodash` wrapped values
  1165. var aWrapped = hasOwnProperty.call(a, '__wrapped__'),
  1166. bWrapped = hasOwnProperty.call(b, '__wrapped__');
  1167. if (aWrapped || bWrapped) {
  1168. return baseIsEqual(aWrapped ? a.__wrapped__ : a, bWrapped ? b.__wrapped__ : b, callback, isWhere, stackA, stackB);
  1169. }
  1170. // exit for functions and DOM nodes
  1171. if (className != objectClass || (!support.nodeClass && (isNode(a) || isNode(b)))) {
  1172. return false;
  1173. }
  1174. // in older versions of Opera, `arguments` objects have `Array` constructors
  1175. var ctorA = !support.argsObject && isArguments(a) ? Object : a.constructor,
  1176. ctorB = !support.argsObject && isArguments(b) ? Object : b.constructor;
  1177. // non `Object` object instances with different constructors are not equal
  1178. if (ctorA != ctorB &&
  1179. !(isFunction(ctorA) && ctorA instanceof ctorA && isFunction(ctorB) && ctorB instanceof ctorB) &&
  1180. ('constructor' in a && 'constructor' in b)
  1181. ) {
  1182. return false;
  1183. }
  1184. }
  1185. // assume cyclic structures are equal
  1186. // the algorithm for detecting cyclic structures is adapted from ES 5.1
  1187. // section 15.12.3, abstract operation `JO` (http://es5.github.io/#x15.12.3)
  1188. var initedStack = !stackA;
  1189. stackA || (stackA = getArray());
  1190. stackB || (stackB = getArray());
  1191. var length = stackA.length;
  1192. while (length--) {
  1193. if (stackA[length] == a) {
  1194. return stackB[length] == b;
  1195. }
  1196. }
  1197. var size = 0;
  1198. result = true;
  1199. // add `a` and `b` to the stack of traversed objects
  1200. stackA.push(a);
  1201. stackB.push(b);
  1202. // recursively compare objects and arrays (susceptible to call stack limits)
  1203. if (isArr) {
  1204. // compare lengths to determine if a deep comparison is necessary
  1205. length = a.length;
  1206. size = b.length;
  1207. result = size == length;
  1208. if (result || isWhere) {
  1209. // deep compare the contents, ignoring non-numeric properties
  1210. while (size--) {
  1211. var index = length,
  1212. value = b[size];
  1213. if (isWhere) {
  1214. while (index--) {
  1215. if ((result = baseIsEqual(a[index], value, callback, isWhere, stackA, stackB))) {
  1216. break;
  1217. }
  1218. }
  1219. } else if (!(result = baseIsEqual(a[size], value, callback, isWhere, stackA, stackB))) {
  1220. break;
  1221. }
  1222. }
  1223. }
  1224. }
  1225. else {
  1226. // deep compare objects using `forIn`, instead of `forOwn`, to avoid `Object.keys`
  1227. // which, in this case, is more costly
  1228. forIn(b, function(value, key, b) {
  1229. if (hasOwnProperty.call(b, key)) {
  1230. // count the number of properties.
  1231. size++;
  1232. // deep compare each property value.
  1233. return (result = hasOwnProperty.call(a, key) && baseIsEqual(a[key], value, callback, isWhere, stackA, stackB));
  1234. }
  1235. });
  1236. if (result && !isWhere) {
  1237. // ensure both objects have the same number of properties
  1238. forIn(a, function(value, key, a) {
  1239. if (hasOwnProperty.call(a, key)) {
  1240. // `size` will be `-1` if `a` has more properties than `b`
  1241. return (result = --size > -1);
  1242. }
  1243. });
  1244. }
  1245. }
  1246. stackA.pop();
  1247. stackB.pop();
  1248. if (initedStack) {
  1249. releaseArray(stackA);
  1250. releaseArray(stackB);
  1251. }
  1252. return result;
  1253. }
  1254. /**
  1255. * The base implementation of `_.merge` without argument juggling or support
  1256. * for `thisArg` binding.
  1257. *
  1258. * @private
  1259. * @param {Object} object The destination object.
  1260. * @param {Object} source The source object.
  1261. * @param {Function} [callback] The function to customize merging properties.
  1262. * @param {Array} [stackA=[]] Tracks traversed source objects.
  1263. * @param {Array} [stackB=[]] Associates values with source counterparts.
  1264. */
  1265. function baseMerge(object, source, callback, stackA, stackB) {
  1266. (isArray(source) ? forEach : forOwn)(source, function(source, key) {
  1267. var found,
  1268. isArr,
  1269. result = source,
  1270. value = object[key];
  1271. if (source && ((isArr = isArray(source)) || isPlainObject(source))) {
  1272. // avoid merging previously merged cyclic sources
  1273. var stackLength = stackA.length;
  1274. while (stackLength--) {
  1275. if ((found = stackA[stackLength] == source)) {
  1276. value = stackB[stackLength];
  1277. break;
  1278. }
  1279. }
  1280. if (!found) {
  1281. var isShallow;
  1282. if (callback) {
  1283. result = callback(value, source);
  1284. if ((isShallow = typeof result != 'undefined')) {
  1285. value = result;
  1286. }
  1287. }
  1288. if (!isShallow) {
  1289. value = isArr
  1290. ? (isArray(value) ? value : [])
  1291. : (isPlainObject(value) ? value : {});
  1292. }
  1293. // add `source` and associated `value` to the stack of traversed objects
  1294. stackA.push(source);
  1295. stackB.push(value);
  1296. // recursively merge objects and arrays (susceptible to call stack limits)
  1297. if (!isShallow) {
  1298. baseMerge(value, source, callback, stackA, stackB);
  1299. }
  1300. }
  1301. }
  1302. else {
  1303. if (callback) {
  1304. result = callback(value, source);
  1305. if (typeof result == 'undefined') {
  1306. result = source;
  1307. }
  1308. }
  1309. if (typeof result != 'undefined') {
  1310. value = result;
  1311. }
  1312. }
  1313. object[key] = value;
  1314. });
  1315. }
  1316. /**
  1317. * The base implementation of `_.random` without argument juggling or support
  1318. * for returning floating-point numbers.
  1319. *
  1320. * @private
  1321. * @param {number} min The minimum possible value.
  1322. * @param {number} max The maximum possible value.
  1323. * @returns {number} Returns a random number.
  1324. */
  1325. function baseRandom(min, max) {
  1326. return min + floor(nativeRandom() * (max - min + 1));
  1327. }
  1328. /**
  1329. * The base implementation of `_.uniq` without support for callback shorthands
  1330. * or `thisArg` binding.
  1331. *
  1332. * @private
  1333. * @param {Array} array The array to process.
  1334. * @param {boolean} [isSorted=false] A flag to indicate that `array` is sorted.
  1335. * @param {Function} [callback] The function called per iteration.
  1336. * @returns {Array} Returns a duplicate-value-free array.
  1337. */
  1338. function baseUniq(array, isSorted, callback) {
  1339. var index = -1,
  1340. indexOf = getIndexOf(),
  1341. length = array ? array.length : 0,
  1342. result = [];
  1343. var isLarge = !isSorted && length >= largeArraySize && indexOf === baseIndexOf,
  1344. seen = (callback || isLarge) ? getArray() : result;
  1345. if (isLarge) {
  1346. var cache = createCache(seen);
  1347. indexOf = cacheIndexOf;
  1348. seen = cache;
  1349. }
  1350. while (++index < length) {
  1351. var value = array[index],
  1352. computed = callback ? callback(value, index, array) : value;
  1353. if (isSorted
  1354. ? !index || seen[seen.length - 1] !== computed
  1355. : indexOf(seen, computed) < 0
  1356. ) {
  1357. if (callback || isLarge) {
  1358. seen.push(computed);
  1359. }
  1360. result.push(value);
  1361. }
  1362. }
  1363. if (isLarge) {
  1364. releaseArray(seen.array);
  1365. releaseObject(seen);
  1366. } else if (callback) {
  1367. releaseArray(seen);
  1368. }
  1369. return result;
  1370. }
  1371. /**
  1372. * Creates a function that aggregates a collection, creating an object composed
  1373. * of keys generated from the results of running