PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/packages/atom-ungit/node_modules/ungit/node_modules/lodash/lodash.js

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