PageRenderTime 63ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/node_modules/grunt/node_modules/lodash/lodash.js

https://bitbucket.org/biojazzard/gantry-eboracast
JavaScript | 4258 lines | 3411 code | 132 blank | 715 comment | 152 complexity | 83730b82afded6015496eec19bfb9cd7 MD5 | raw file
Possible License(s): MIT, JSON, BSD-2-Clause, Unlicense, GPL-2.0, WTFPL, LGPL-3.0, Apache-2.0, 0BSD, BSD-3-Clause, CC-BY-SA-3.0

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file