PageRenderTime 25ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/files/lodash/2.3.0/lodash.compat.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 1503 lines | 802 code | 143 blank | 558 comment | 299 complexity | 6082ccff04cdbe1e2b0347392a393ff3 MD5 | raw file
  1. /**
  2. * @license
  3. * Lo-Dash 2.3.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 = /^\s*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. * Releases the given array back to the array pool.
  341. *
  342. * @private
  343. * @param {Array} [array] The array to release.
  344. */
  345. function releaseArray(array) {
  346. array.length = 0;
  347. if (arrayPool.length < maxPoolSize) {
  348. arrayPool.push(array);
  349. }
  350. }
  351. /**
  352. * Releases the given object back to the object pool.
  353. *
  354. * @private
  355. * @param {Object} [object] The object to release.
  356. */
  357. function releaseObject(object) {
  358. var cache = object.cache;
  359. if (cache) {
  360. releaseObject(cache);
  361. }
  362. object.array = object.cache = object.criteria = object.object = object.number = object.string = object.value = null;
  363. if (objectPool.length < maxPoolSize) {
  364. objectPool.push(object);
  365. }
  366. }
  367. /**
  368. * Slices the `collection` from the `start` index up to, but not including,
  369. * the `end` index.
  370. *
  371. * Note: This function is used instead of `Array#slice` to support node lists
  372. * in IE < 9 and to ensure dense arrays are returned.
  373. *
  374. * @private
  375. * @param {Array|Object|string} collection The collection to slice.
  376. * @param {number} start The start index.
  377. * @param {number} end The end index.
  378. * @returns {Array} Returns the new array.
  379. */
  380. function slice(array, start, end) {
  381. start || (start = 0);
  382. if (typeof end == 'undefined') {
  383. end = array ? array.length : 0;
  384. }
  385. var index = -1,
  386. length = end - start || 0,
  387. result = Array(length < 0 ? 0 : length);
  388. while (++index < length) {
  389. result[index] = array[start + index];
  390. }
  391. return result;
  392. }
  393. /*--------------------------------------------------------------------------*/
  394. /**
  395. * Create a new `lodash` function using the given context object.
  396. *
  397. * @static
  398. * @memberOf _
  399. * @category Utilities
  400. * @param {Object} [context=root] The context object.
  401. * @returns {Function} Returns the `lodash` function.
  402. */
  403. function runInContext(context) {
  404. // Avoid issues with some ES3 environments that attempt to use values, named
  405. // after built-in constructors like `Object`, for the creation of literals.
  406. // ES5 clears this up by stating that literals must use built-in constructors.
  407. // See http://es5.github.io/#x11.1.5.
  408. context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
  409. /** Native constructor references */
  410. var Array = context.Array,
  411. Boolean = context.Boolean,
  412. Date = context.Date,
  413. Error = context.Error,
  414. Function = context.Function,
  415. Math = context.Math,
  416. Number = context.Number,
  417. Object = context.Object,
  418. RegExp = context.RegExp,
  419. String = context.String,
  420. TypeError = context.TypeError;
  421. /**
  422. * Used for `Array` method references.
  423. *
  424. * Normally `Array.prototype` would suffice, however, using an array literal
  425. * avoids issues in Narwhal.
  426. */
  427. var arrayRef = [];
  428. /** Used for native method references */
  429. var errorProto = Error.prototype,
  430. objectProto = Object.prototype,
  431. stringProto = String.prototype;
  432. /** Used to restore the original `_` reference in `noConflict` */
  433. var oldDash = context._;
  434. /** Used to resolve the internal [[Class]] of values */
  435. var toString = objectProto.toString;
  436. /** Used to detect if a method is native */
  437. var reNative = RegExp('^' +
  438. String(toString)
  439. .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
  440. .replace(/toString| for [^\]]+/g, '.*?') + '$'
  441. );
  442. /** Native method shortcuts */
  443. var ceil = Math.ceil,
  444. clearTimeout = context.clearTimeout,
  445. floor = Math.floor,
  446. fnToString = Function.prototype.toString,
  447. getPrototypeOf = reNative.test(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
  448. hasOwnProperty = objectProto.hasOwnProperty,
  449. now = reNative.test(now = Date.now) && now || function() { return +new Date; },
  450. push = arrayRef.push,
  451. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  452. setTimeout = context.setTimeout,
  453. splice = arrayRef.splice;
  454. /** Used to detect `setImmediate` in Node.js */
  455. var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
  456. !reNative.test(setImmediate) && setImmediate;
  457. /** Used to set meta data on functions */
  458. var defineProperty = (function() {
  459. // IE 8 only accepts DOM elements
  460. try {
  461. var o = {},
  462. func = reNative.test(func = Object.defineProperty) && func,
  463. result = func(o, o, o) && func;
  464. } catch(e) { }
  465. return result;
  466. }());
  467. /* Native method shortcuts for methods with the same name as other `lodash` methods */
  468. var nativeCreate = reNative.test(nativeCreate = Object.create) && nativeCreate,
  469. nativeIsArray = reNative.test(nativeIsArray = Array.isArray) && nativeIsArray,
  470. nativeIsFinite = context.isFinite,
  471. nativeIsNaN = context.isNaN,
  472. nativeKeys = reNative.test(nativeKeys = Object.keys) && nativeKeys,
  473. nativeMax = Math.max,
  474. nativeMin = Math.min,
  475. nativeParseInt = context.parseInt,
  476. nativeRandom = Math.random;
  477. /** Used to lookup a built-in constructor by [[Class]] */
  478. var ctorByClass = {};
  479. ctorByClass[arrayClass] = Array;
  480. ctorByClass[boolClass] = Boolean;
  481. ctorByClass[dateClass] = Date;
  482. ctorByClass[funcClass] = Function;
  483. ctorByClass[objectClass] = Object;
  484. ctorByClass[numberClass] = Number;
  485. ctorByClass[regexpClass] = RegExp;
  486. ctorByClass[stringClass] = String;
  487. /** Used to avoid iterating non-enumerable properties in IE < 9 */
  488. var nonEnumProps = {};
  489. nonEnumProps[arrayClass] = nonEnumProps[dateClass] = nonEnumProps[numberClass] = { 'constructor': true, 'toLocaleString': true, 'toString': true, 'valueOf': true };
  490. nonEnumProps[boolClass] = nonEnumProps[stringClass] = { 'constructor': true, 'toString': true, 'valueOf': true };
  491. nonEnumProps[errorClass] = nonEnumProps[funcClass] = nonEnumProps[regexpClass] = { 'constructor': true, 'toString': true };
  492. nonEnumProps[objectClass] = { 'constructor': true };
  493. (function() {
  494. var length = shadowedProps.length;
  495. while (length--) {
  496. var key = shadowedProps[length];
  497. for (var className in nonEnumProps) {
  498. if (hasOwnProperty.call(nonEnumProps, className) && !hasOwnProperty.call(nonEnumProps[className], key)) {
  499. nonEnumProps[className][key] = false;
  500. }
  501. }
  502. }
  503. }());
  504. /*--------------------------------------------------------------------------*/
  505. /**
  506. * Creates a `lodash` object which wraps the given value to enable intuitive
  507. * method chaining.
  508. *
  509. * In addition to Lo-Dash methods, wrappers also have the following `Array` methods:
  510. * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`,
  511. * and `unshift`
  512. *
  513. * Chaining is supported in custom builds as long as the `value` method is
  514. * implicitly or explicitly included in the build.
  515. *
  516. * The chainable wrapper functions are:
  517. * `after`, `assign`, `bind`, `bindAll`, `bindKey`, `chain`, `compact`,
  518. * `compose`, `concat`, `countBy`, `create`, `createCallback`, `curry`,
  519. * `debounce`, `defaults`, `defer`, `delay`, `difference`, `filter`, `flatten`,
  520. * `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
  521. * `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
  522. * `invoke`, `keys`, `map`, `max`, `memoize`, `merge`, `min`, `object`, `omit`,
  523. * `once`, `pairs`, `partial`, `partialRight`, `pick`, `pluck`, `pull`, `push`,
  524. * `range`, `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`,
  525. * `sortBy`, `splice`, `tap`, `throttle`, `times`, `toArray`, `transform`,
  526. * `union`, `uniq`, `unshift`, `unzip`, `values`, `where`, `without`, `wrap`,
  527. * and `zip`
  528. *
  529. * The non-chainable wrapper functions are:
  530. * `clone`, `cloneDeep`, `contains`, `escape`, `every`, `find`, `findIndex`,
  531. * `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `has`, `identity`,
  532. * `indexOf`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
  533. * `isEmpty`, `isEqual`, `isFinite`, `isFunction`, `isNaN`, `isNull`, `isNumber`,
  534. * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, `join`,
  535. * `lastIndexOf`, `mixin`, `noConflict`, `parseInt`, `pop`, `random`, `reduce`,
  536. * `reduceRight`, `result`, `shift`, `size`, `some`, `sortedIndex`, `runInContext`,
  537. * `template`, `unescape`, `uniqueId`, and `value`
  538. *
  539. * The wrapper functions `first` and `last` return wrapped values when `n` is
  540. * provided, otherwise they return unwrapped values.
  541. *
  542. * Explicit chaining can be enabled by using the `_.chain` method.
  543. *
  544. * @name _
  545. * @constructor
  546. * @category Chaining
  547. * @param {*} value The value to wrap in a `lodash` instance.
  548. * @returns {Object} Returns a `lodash` instance.
  549. * @example
  550. *
  551. * var wrapped = _([1, 2, 3]);
  552. *
  553. * // returns an unwrapped value
  554. * wrapped.reduce(function(sum, num) {
  555. * return sum + num;
  556. * });
  557. * // => 6
  558. *
  559. * // returns a wrapped value
  560. * var squares = wrapped.map(function(num) {
  561. * return num * num;
  562. * });
  563. *
  564. * _.isArray(squares);
  565. * // => false
  566. *
  567. * _.isArray(squares.value());
  568. * // => true
  569. */
  570. function lodash(value) {
  571. // don't wrap if already wrapped, even if wrapped by a different `lodash` constructor
  572. return (value && typeof value == 'object' && !isArray(value) && hasOwnProperty.call(value, '__wrapped__'))
  573. ? value
  574. : new lodashWrapper(value);
  575. }
  576. /**
  577. * A fast path for creating `lodash` wrapper objects.
  578. *
  579. * @private
  580. * @param {*} value The value to wrap in a `lodash` instance.
  581. * @param {boolean} chainAll A flag to enable chaining for all methods
  582. * @returns {Object} Returns a `lodash` instance.
  583. */
  584. function lodashWrapper(value, chainAll) {
  585. this.__chain__ = !!chainAll;
  586. this.__wrapped__ = value;
  587. }
  588. // ensure `new lodashWrapper` is an instance of `lodash`
  589. lodashWrapper.prototype = lodash.prototype;
  590. /**
  591. * An object used to flag environments features.
  592. *
  593. * @static
  594. * @memberOf _
  595. * @type Object
  596. */
  597. var support = lodash.support = {};
  598. (function() {
  599. var ctor = function() { this.x = 1; },
  600. object = { '0': 1, 'length': 1 },
  601. props = [];
  602. ctor.prototype = { 'valueOf': 1, 'y': 1 };
  603. for (var key in new ctor) { props.push(key); }
  604. for (key in arguments) { }
  605. /**
  606. * Detect if an `arguments` object's [[Class]] is resolvable (all but Firefox < 4, IE < 9).
  607. *
  608. * @memberOf _.support
  609. * @type boolean
  610. */
  611. support.argsClass = toString.call(arguments) == argsClass;
  612. /**
  613. * Detect if `arguments` objects are `Object` objects (all but Narwhal and Opera < 10.5).
  614. *
  615. * @memberOf _.support
  616. * @type boolean
  617. */
  618. support.argsObject = arguments.constructor == Object && !(arguments instanceof Array);
  619. /**
  620. * Detect if `name` or `message` properties of `Error.prototype` are
  621. * enumerable by default. (IE < 9, Safari < 5.1)
  622. *
  623. * @memberOf _.support
  624. * @type boolean
  625. */
  626. support.enumErrorProps = propertyIsEnumerable.call(errorProto, 'message') || propertyIsEnumerable.call(errorProto, 'name');
  627. /**
  628. * Detect if `prototype` properties are enumerable by default.
  629. *
  630. * Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1
  631. * (if the prototype or a property on the prototype has been set)
  632. * incorrectly sets a function's `prototype` property [[Enumerable]]
  633. * value to `true`.
  634. *
  635. * @memberOf _.support
  636. * @type boolean
  637. */
  638. support.enumPrototypes = propertyIsEnumerable.call(ctor, 'prototype');
  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 = key != 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 `_.bind` that creates the bound function and
  863. * sets its meta data.
  864. *
  865. * @private
  866. * @param {Array} bindData The bind data array.
  867. * @returns {Function} Returns the new bound function.
  868. */
  869. function baseBind(bindData) {
  870. var func = bindData[0],
  871. partialArgs = bindData[2],
  872. thisArg = bindData[4];
  873. function bound() {
  874. // `Function#bind` spec
  875. // http://es5.github.io/#x15.3.4.5
  876. if (partialArgs) {
  877. var args = partialArgs.slice();
  878. push.apply(args, arguments);
  879. }
  880. // mimic the constructor's `return` behavior
  881. // http://es5.github.io/#x13.2.2
  882. if (this instanceof bound) {
  883. // ensure `new bound` is an instance of `func`
  884. var thisBinding = baseCreate(func.prototype),
  885. result = func.apply(thisBinding, args || arguments);
  886. return isObject(result) ? result : thisBinding;
  887. }
  888. return func.apply(thisArg, args || arguments);
  889. }
  890. setBindData(bound, bindData);
  891. return bound;
  892. }
  893. /**
  894. * The base implementation of `_.clone` without argument juggling or support
  895. * for `thisArg` binding.
  896. *
  897. * @private
  898. * @param {*} value The value to clone.
  899. * @param {boolean} [isDeep=false] Specify a deep clone.
  900. * @param {Function} [callback] The function to customize cloning values.
  901. * @param {Array} [stackA=[]] Tracks traversed source objects.
  902. * @param {Array} [stackB=[]] Associates clones with source counterparts.
  903. * @returns {*} Returns the cloned value.
  904. */
  905. function baseClone(value, isDeep, callback, stackA, stackB) {
  906. if (callback) {
  907. var result = callback(value);
  908. if (typeof result != 'undefined') {
  909. return result;
  910. }
  911. }
  912. // inspect [[Class]]
  913. var isObj = isObject(value);
  914. if (isObj) {
  915. var className = toString.call(value);
  916. if (!cloneableClasses[className] || (!support.nodeClass && isNode(value))) {
  917. return value;
  918. }
  919. var ctor = ctorByClass[className];
  920. switch (className) {
  921. case boolClass:
  922. case dateClass:
  923. return new ctor(+value);
  924. case numberClass:
  925. case stringClass:
  926. return new ctor(value);
  927. case regexpClass:
  928. result = ctor(value.source, reFlags.exec(value));
  929. result.lastIndex = value.lastIndex;
  930. return result;
  931. }
  932. } else {
  933. return value;
  934. }
  935. var isArr = isArray(value);
  936. if (isDeep) {
  937. // check for circular references and return corresponding clone
  938. var initedStack = !stackA;
  939. stackA || (stackA = getArray());
  940. stackB || (stackB = getArray());
  941. var length = stackA.length;
  942. while (length--) {
  943. if (stackA[length] == value) {
  944. return stackB[length];
  945. }
  946. }
  947. result = isArr ? ctor(value.length) : {};
  948. }
  949. else {
  950. result = isArr ? slice(value) : assign({}, value);
  951. }
  952. // add array properties assigned by `RegExp#exec`
  953. if (isArr) {
  954. if (hasOwnProperty.call(value, 'index')) {
  955. result.index = value.index;
  956. }
  957. if (hasOwnProperty.call(value, 'input')) {
  958. result.input = value.input;
  959. }
  960. }
  961. // exit for shallow clone
  962. if (!isDeep) {
  963. return result;
  964. }
  965. // add the source value to the stack of traversed objects
  966. // and associate it with its clone
  967. stackA.push(value);
  968. stackB.push(result);
  969. // recursively populate clone (susceptible to call stack limits)
  970. (isArr ? baseEach : forOwn)(value, function(objValue, key) {
  971. result[key] = baseClone(objValue, isDeep, callback, stackA, stackB);
  972. });
  973. if (initedStack) {
  974. releaseArray(stackA);
  975. releaseArray(stackB);
  976. }
  977. return result;
  978. }
  979. /**
  980. * The base implementation of `_.create` without support for assigning
  981. * properties to the created object.
  982. *
  983. * @private
  984. * @param {Object} prototype The object to inherit from.
  985. * @returns {Object} Returns the new object.
  986. */
  987. function baseCreate(prototype, properties) {
  988. return isObject(prototype) ? nativeCreate(prototype) : {};
  989. }
  990. // fallback for browsers without `Object.create`
  991. if (!nativeCreate) {
  992. baseCreate = (function() {
  993. function Object() {}
  994. return function(prototype) {
  995. if (isObject(prototype)) {
  996. Object.prototype = prototype;
  997. var result = new Object;
  998. Object.prototype = null;
  999. }
  1000. return result || context.Object();
  1001. };
  1002. }());
  1003. }
  1004. /**
  1005. * The base implementation of `_.createCallback` without support for creating
  1006. * "_.pluck" or "_.where" style callbacks.
  1007. *
  1008. * @private
  1009. * @param {*} [func=identity] The value to convert to a callback.
  1010. * @param {*} [thisArg] The `this` binding of the created callback.
  1011. * @param {number} [argCount] The number of arguments the callback accepts.
  1012. * @returns {Function} Returns a callback function.
  1013. */
  1014. function baseCreateCallback(func, thisArg, argCount) {
  1015. if (typeof func != 'function') {
  1016. return identity;
  1017. }
  1018. // exit early for no `thisArg` or already bound by `Function#bind`
  1019. if (typeof thisArg == 'undefined' || !('prototype' in func)) {
  1020. return func;
  1021. }
  1022. var bindData = func.__bindData__;
  1023. if (typeof bindData == 'undefined') {
  1024. if (support.funcNames) {
  1025. bindData = !func.name;
  1026. }
  1027. bindData = bindData || !support.funcDecomp;
  1028. if (!bindData) {
  1029. var source = fnToString.call(func);
  1030. if (!support.funcNames) {
  1031. bindData = !reFuncName.test(source);
  1032. }
  1033. if (!bindData) {
  1034. // checks if `func` references the `this` keyword and stores the result
  1035. bindData = reThis.test(source);
  1036. setBindData(func, bindData);
  1037. }
  1038. }
  1039. }
  1040. // exit early if there are no `this` references or `func` is bound
  1041. if (bindData === false || (bindData !== true && bindData[1] & 1)) {
  1042. return func;
  1043. }
  1044. switch (argCount) {
  1045. case 1: return function(value) {
  1046. return func.call(thisArg, value);
  1047. };
  1048. case 2: return function(a, b) {
  1049. return func.call(thisArg, a, b);
  1050. };
  1051. case 3: return function(value, index, collection) {
  1052. return func.call(thisArg, value, index, collection);
  1053. };
  1054. case 4: return function(accumulator, value, index, collection) {
  1055. return func.call(thisArg, accumulator, value, index, collection);
  1056. };
  1057. }
  1058. return bind(func, thisArg);
  1059. }
  1060. /**
  1061. * The base implementation of `createWrapper` that creates the wrapper and
  1062. * sets its meta data.
  1063. *
  1064. * @private
  1065. * @param {Array} bindData The bind data array.
  1066. * @returns {Function} Returns the new function.
  1067. */
  1068. function baseCreateWrapper(bindData) {
  1069. var func = bindData[0],
  1070. bitmask = bindData[1],
  1071. partialArgs = bindData[2],
  1072. partialRightArgs = bindData[3],
  1073. thisArg = bindData[4],
  1074. arity = bindData[5];
  1075. var isBind = bitmask & 1,
  1076. isBindKey = bitmask & 2,
  1077. isCurry = bitmask & 4,
  1078. isCurryBound = bitmask & 8,
  1079. key = func;
  1080. function bound() {
  1081. var thisBinding = isBind ? thisArg : this;
  1082. if (partialArgs) {
  1083. var args = partialArgs.slice();
  1084. push.apply(args, arguments);
  1085. }
  1086. if (partialRightArgs || isCurry) {
  1087. args || (args = slice(arguments));
  1088. if (partialRightArgs) {
  1089. push.apply(args, partialRightArgs);
  1090. }
  1091. if (isCurry && args.length < arity) {
  1092. bitmask |= 16 & ~32;
  1093. return baseCreateWrapper([func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity]);
  1094. }
  1095. }
  1096. args || (args = arguments);
  1097. if (isBindKey) {
  1098. func = thisBinding[key];
  1099. }
  1100. if (this instanceof bound) {
  1101. thisBinding = baseCreate(func.prototype);
  1102. var result = func.apply(thisBinding, args);
  1103. return isObject(result) ? result : thisBinding;
  1104. }
  1105. return func.apply(thisBinding, args);
  1106. }
  1107. setBindData(bound, bindData);
  1108. return bound;
  1109. }
  1110. /**
  1111. * The base implementation of `_.difference` that accepts a single array
  1112. * of values to exclude.
  1113. *
  1114. * @private
  1115. * @param {Array} array The array to process.
  1116. * @param {Array} [values] The array of values to exclude.
  1117. * @returns {Array} Returns a new array of filtered values.
  1118. */
  1119. function baseDifference(array, values) {
  1120. var index = -1,
  1121. indexOf = getIndexOf(),
  1122. length = array ? array.length : 0,
  1123. isLarge = length >= largeArraySize && indexOf === baseIndexOf,
  1124. result = [];
  1125. if (isLarge) {
  1126. var cache = createCache(values);
  1127. if (cache) {
  1128. indexOf = cacheIndexOf;
  1129. values = cache;
  1130. } else {
  1131. isLarge = false;
  1132. }
  1133. }
  1134. while (++index < length) {
  1135. var value = array[index];
  1136. if (indexOf(values, value) < 0) {
  1137. result.push(value);
  1138. }
  1139. }
  1140. if (isLarge) {
  1141. releaseObject(values);
  1142. }
  1143. return result;
  1144. }
  1145. /**
  1146. * The base implementation of `_.flatten` without support for callback
  1147. * shorthands or `thisArg` binding.
  1148. *
  1149. * @private
  1150. * @param {Array} array The array to flatten.
  1151. * @param {boolean} [isShallow=false] A flag to restrict flattening to a single level.
  1152. * @param {boolean} [isStrict=false] A flag to restrict flattening to arrays and `arguments` objects.
  1153. * @param {number} [fromIndex=0] The index to start from.
  1154. * @returns {Array} Returns a new flattened array.
  1155. */
  1156. function baseFlatten(array, isShallow, isStrict, fromIndex) {
  1157. var index = (fromIndex || 0) - 1,
  1158. length = array ? array.length : 0,
  1159. result = [];
  1160. while (++index < length) {
  1161. var value = array[index];
  1162. if (value && typeof value == 'object' && typeof value.length == 'number'
  1163. && (isArray(value) || isArguments(value))) {
  1164. // recursively flatten arrays (susceptible to call stack limits)
  1165. if (!isShallow) {
  1166. value = baseFlatten(value, isShallow, isStrict);
  1167. }
  1168. var valIndex = -1,
  1169. valLength = value.length,
  1170. resIndex = result.length;
  1171. result.length += valLength;
  1172. while (++valIndex < valLength) {
  1173. result[resIndex++] = value[valIndex];
  1174. }
  1175. } else if (!isStrict) {
  1176. result.push(value);
  1177. }
  1178. }
  1179. return result;
  1180. }
  1181. /**
  1182. * The base implementation of `_.isEqual`, without support for `thisArg` binding,
  1183. * that allows partial "_.where" style comparisons.
  1184. *
  1185. * @private
  1186. * @param {*} a The value to compare.
  1187. * @param {*} b The other value to compare.
  1188. * @param {Function} [callback] The function to customize comparing values.
  1189. * @param {Function} [isWhere=false] A flag to indicate performing partial comparisons.
  1190. * @param {Array} [stackA=[]] Tracks traversed `a` objects.
  1191. * @param {Array} [stackB=[]] Tracks traversed `b` objects.
  1192. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  1193. */
  1194. function baseIsEqual(a, b, callback, isWhere, stackA, stackB) {
  1195. // used to indicate that when comparing objects, `a` has at least the properties of `b`
  1196. if (callback) {
  1197. var result = callback(a, b);
  1198. if (typeof result != 'undefined') {
  1199. return !!result;
  1200. }
  1201. }
  1202. // exit early for identical values
  1203. if (a === b) {
  1204. // treat `+0` vs. `-0` as not equal
  1205. return a !== 0 || (1 / a == 1 / b);
  1206. }
  1207. var type = typeof a,
  1208. otherType = typeof b;
  1209. // exit early for unlike primitive values
  1210. if (a === a &&
  1211. !(a && objectTypes[type]) &&
  1212. !(b && objectTypes[otherType])) {
  1213. return false;
  1214. }
  1215. // exit early for `null` and `undefined` avoiding ES3's Function#call behavior
  1216. // http://es5.github.io/#x15.3.4.4
  1217. if (a == null || b == null) {
  1218. return a === b;
  1219. }
  1220. // compare [[Class]] names
  1221. var className = toString.call(a),
  1222. otherClass = toString.call(b);
  1223. if (className == argsClass) {
  1224. className = objectClass;
  1225. }
  1226. if (otherClass == argsClass) {
  1227. otherClass = objectClass;
  1228. }
  1229. if (className != otherClass) {
  1230. return false;
  1231. }
  1232. switch (className) {
  1233. case boolClass:
  1234. case dateClass:
  1235. // coerce dates and booleans to numbers, dates to milliseconds and booleans
  1236. // to `1` or `0` treating invalid dates coerced to `NaN` as not equal
  1237. return +a == +b;
  1238. case numberClass:
  1239. // treat `NaN` vs. `NaN` as equal
  1240. return (a != +a)
  1241. ? b != +b
  1242. // but treat `+0` vs. `-0` as not equal
  1243. : (a == 0 ? (1 / a == 1 / b) : a == +b);
  1244. case regexpClass:
  1245. case stringClass:
  1246. // coerce regexes to strings (http://es5.github.io/#x15.10.6.4)
  1247. // treat string primitives and their corresponding object instances as equal
  1248. return a == String(b);
  1249. }
  1250. var isArr = className == arrayClass;
  1251. if (!isArr) {
  1252. // unwrap any `lodash` wrapped values
  1253. var aWrapped = hasOwnProperty.call(a, '__wrapped__'),
  1254. bWrapped = hasOwnProperty.call(b, '__wrapped__');
  1255. if (aWrapped || bWrapped) {
  1256. return baseIsEqual(aWrapped ? a.__wrapped__ : a, bWrapped ? b.__wrapped__ : b, callback, isWhere, stackA, stackB);
  1257. }
  1258. // exit for functions and DOM nodes
  1259. if (className != objectClass || (!support.nodeClass && (isNode(a) || isNode(b)))) {
  1260. return false;
  1261. }
  1262. // in older versions of Opera, `arguments` objects have `Array` constructors
  1263. var ctorA = !support.argsObject && isArguments(a) ? Object : a.constructor,
  1264. ctorB = !support.argsObject && isArguments(b) ? Object : b.constructor;
  1265. // non `Object` object instances with different constructors are not equal
  1266. if (ctorA != ctorB &&
  1267. !(isFunction(ctorA) && ctorA instanceof ctorA && isFunction(ctorB) && ctorB instanceof ctorB) &&
  1268. ('constructor' in a && 'constructor' in b)
  1269. ) {
  1270. return false;
  1271. }
  1272. }
  1273. // assume cyclic structures are equal
  1274. // the algorithm for detecting cyclic structures is adapted from ES 5.1
  1275. // section 15.12.3, abstract operation `JO` (http://es5.github.io/#x15.12.3)
  1276. var initedStack = !stackA;
  1277. stackA || (stackA = getArray());
  1278. stackB || (stackB = getArray());
  1279. var length = stackA.length;
  1280. while (length--) {
  1281. if (stackA[length] == a) {
  1282. return stackB[length] == b;
  1283. }
  1284. }
  1285. var size = 0;
  1286. result = true;
  1287. // add `a` and `b` to the stack of traversed objects
  1288. stackA.push(a);
  1289. stackB.push(b);
  1290. // recursively compare objects and arrays (susceptible to call stack limits)
  1291. if (isArr) {
  1292. length = a.length;
  1293. size = b.length;
  1294. // compare lengths to determine if a deep comparison is necessary
  1295. result = size == a.length;
  1296. if (!result && !isWhere) {
  1297. return result;
  1298. }
  1299. // deep compare the contents, ignoring non-numeric properties
  1300. while (size--) {
  1301. var index = length,
  1302. value = b[size];
  1303. if (isWhere) {
  1304. while (index--) {
  1305. if ((result = baseIsEqual(a[index], value, callback, isWhere, stackA, stackB))) {
  1306. break;
  1307. }
  1308. }
  1309. } else if (!(result = baseIsEqual(a[size], value, callback, isWhere, stackA, stackB))) {
  1310. break;
  1311. }
  1312. }
  1313. return result;
  1314. }
  1315. // deep compare objects using `forIn`, instead of `forOwn`, to avoid `Object.keys`
  1316. // which, in this case, is more costly
  1317. forIn(b, function(value, key, b) {
  1318. if (hasOwnProperty.call(b, key)) {
  1319. // count the number of properties.
  1320. size++;
  1321. // deep compare each property value.
  1322. return (result = hasOwnProperty.call(a, key) && baseIsEqual(a[key], value, callback, isWhere, stackA, stackB));
  1323. }
  1324. });
  1325. if (result && !isWhere) {
  1326. // ensure both objects have the same number of properties
  1327. forIn(a, function(value, key, a) {
  1328. if (hasOwnProperty.call(a, key)) {
  1329. // `size` will be `-1` if `a` has more properties than `b`
  1330. return (result = --size > -1);
  1331. }
  1332. });
  1333. }
  1334. if (initedStack) {
  1335. releaseArray(stackA);
  1336. releaseArray(stackB);
  1337. }
  1338. return result;
  1339. }
  1340. /**
  1341. * The base implementation of `_.merge` without argument juggling or support
  1342. * for `thisArg` binding.
  1343. *
  1344. * @private
  1345. * @param {Object} object The destination object.
  1346. * @param {Object} source The source object.
  1347. * @param {Function} [callback] The function to customize merging properties.
  1348. * @param {Array} [stackA=[]] Tracks traversed source objects.
  1349. * @param {Array} [stackB=[]] Associates values with source counterparts.
  1350. */
  1351. function baseMerge(object, source, callback, stackA, stackB) {
  1352. (isArray(source) ? forEach : forOwn)(source, function(source, key) {
  1353. var found,
  1354. isArr,
  1355. result = source,
  1356. value = object[key];
  1357. if (source && ((isArr = isArray(source)) || isPlainObject(source))) {
  1358. // avoid merging previously merged cyclic sources
  1359. var stackLength = stackA.length;
  1360. whil