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

/files/lodash/2.4.1/lodash.underscore.js

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