PageRenderTime 75ms CodeModel.GetById 1ms RepoModel.GetById 2ms app.codeStats 0ms

/files/lodash/2.1.0/lodash.compat.js

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