PageRenderTime 61ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/files/lodash/2.2.1/lodash.underscore.js

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