PageRenderTime 51ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/ajax/libs/lodash.js/2.2.0/lodash.underscore.js

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