PageRenderTime 47ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/files/lodash/2.4.0/lodash.mobile.js

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