PageRenderTime 26ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/front/node_modules/lodash/dist/lodash.underscore.js

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