PageRenderTime 62ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/files/lodash/2.2.1/lodash.compat.js

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