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

/files/lodash/2.1.0/lodash.underscore.js

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