PageRenderTime 57ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/node_modules/grunt-bower-task/node_modules/lodash/lodash.js

https://bitbucket.org/biojazzard/gantry-eboracast
JavaScript | 4282 lines | 3417 code | 133 blank | 732 comment | 154 complexity | e4151912002c03158c2635de022017a2 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 0.10.0 <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. /** Reusable iterator options for `assign` and `defaults` */
  362. var assignIteratorOptions = {
  363. 'args': 'object, source, guard',
  364. 'top':
  365. 'for (var argsIndex = 1, argsLength = typeof guard == \'number\' ? 2 : arguments.length; argsIndex < argsLength; argsIndex++) {\n' +
  366. ' if ((iteratee = arguments[argsIndex])) {',
  367. 'objectLoop': 'result[index] = value',
  368. 'bottom': ' }\n}'
  369. };
  370. /**
  371. * Reusable iterator options shared by `forEach`, `forIn`, and `forOwn`.
  372. */
  373. var forEachIteratorOptions = {
  374. 'args': 'collection, callback, thisArg',
  375. 'top': 'callback = createCallback(callback, thisArg)',
  376. 'arrayLoop': 'if (callback(value, index, collection) === false) return result',
  377. 'objectLoop': 'if (callback(value, index, collection) === false) return result'
  378. };
  379. /** Reusable iterator options for `forIn` and `forOwn` */
  380. var forOwnIteratorOptions = {
  381. 'arrayLoop': null
  382. };
  383. /*--------------------------------------------------------------------------*/
  384. /**
  385. * Creates a function optimized to search large arrays for a given `value`,
  386. * starting at `fromIndex`, using strict equality for comparisons, i.e. `===`.
  387. *
  388. * @private
  389. * @param {Array} array The array to search.
  390. * @param {Mixed} value The value to search for.
  391. * @param {Number} [fromIndex=0] The index to search from.
  392. * @param {Number} [largeSize=30] The length at which an array is considered large.
  393. * @returns {Boolean} Returns `true` if `value` is found, else `false`.
  394. */
  395. function cachedContains(array, fromIndex, largeSize) {
  396. fromIndex || (fromIndex = 0);
  397. var length = array.length,
  398. isLarge = (length - fromIndex) >= (largeSize || largeArraySize);
  399. if (isLarge) {
  400. var cache = {},
  401. index = fromIndex - 1;
  402. while (++index < length) {
  403. // manually coerce `value` to a string because `hasOwnProperty`, in some
  404. // older versions of Firefox, coerces objects incorrectly
  405. var key = array[index] + '';
  406. (hasOwnProperty.call(cache, key) ? cache[key] : (cache[key] = [])).push(array[index]);
  407. }
  408. }
  409. return function(value) {
  410. if (isLarge) {
  411. var key = value + '';
  412. return hasOwnProperty.call(cache, key) && indexOf(cache[key], value) > -1;
  413. }
  414. return indexOf(array, value, fromIndex) > -1;
  415. }
  416. }
  417. /**
  418. * Used by `_.max` and `_.min` as the default `callback` when a given
  419. * `collection` is a string value.
  420. *
  421. * @private
  422. * @param {String} value The character to inspect.
  423. * @returns {Number} Returns the code unit of given character.
  424. */
  425. function charAtCallback(value) {
  426. return value.charCodeAt(0);
  427. }
  428. /**
  429. * Used by `sortBy` to compare transformed `collection` values, stable sorting
  430. * them in ascending order.
  431. *
  432. * @private
  433. * @param {Object} a The object to compare to `b`.
  434. * @param {Object} b The object to compare to `a`.
  435. * @returns {Number} Returns the sort order indicator of `1` or `-1`.
  436. */
  437. function compareAscending(a, b) {
  438. var ai = a.index,
  439. bi = b.index;
  440. a = a.criteria;
  441. b = b.criteria;
  442. // ensure a stable sort in V8 and other engines
  443. // http://code.google.com/p/v8/issues/detail?id=90
  444. if (a !== b) {
  445. if (a > b || a === undefined) {
  446. return 1;
  447. }
  448. if (a < b || b === undefined) {
  449. return -1;
  450. }
  451. }
  452. return ai < bi ? -1 : 1;
  453. }
  454. /**
  455. * Creates a function that, when called, invokes `func` with the `this`
  456. * binding of `thisArg` and prepends any `partailArgs` to the arguments passed
  457. * to the bound function.
  458. *
  459. * @private
  460. * @param {Function|String} func The function to bind or the method name.
  461. * @param {Mixed} [thisArg] The `this` binding of `func`.
  462. * @param {Array} partialArgs An array of arguments to be partially applied.
  463. * @returns {Function} Returns the new bound function.
  464. */
  465. function createBound(func, thisArg, partialArgs) {
  466. var isFunc = isFunction(func),
  467. isPartial = !partialArgs,
  468. key = thisArg;
  469. // juggle arguments
  470. if (isPartial) {
  471. partialArgs = thisArg;
  472. }
  473. if (!isFunc) {
  474. thisArg = func;
  475. }
  476. function bound() {
  477. // `Function#bind` spec
  478. // http://es5.github.com/#x15.3.4.5
  479. var args = arguments,
  480. thisBinding = isPartial ? this : thisArg;
  481. if (!isFunc) {
  482. func = thisArg[key];
  483. }
  484. if (partialArgs.length) {
  485. args = args.length
  486. ? partialArgs.concat(slice.call(args))
  487. : partialArgs;
  488. }
  489. if (this instanceof bound) {
  490. // get `func` instance if `bound` is invoked in a `new` expression
  491. noop.prototype = func.prototype;
  492. thisBinding = new noop;
  493. // mimic the constructor's `return` behavior
  494. // http://es5.github.com/#x13.2.2
  495. var result = func.apply(thisBinding, args);
  496. return isObject(result)
  497. ? result
  498. : thisBinding
  499. }
  500. return func.apply(thisBinding, args);
  501. }
  502. return bound;
  503. }
  504. /**
  505. * Produces an iteration callback bound to an optional `thisArg`. If `func` is
  506. * a property name, the callback will return the property value for a given element.
  507. *
  508. * @private
  509. * @param {Function|String} [func=identity|property] The function called per
  510. * iteration or property name to query.
  511. * @param {Mixed} [thisArg] The `this` binding of `callback`.
  512. * @returns {Function} Returns a callback function.
  513. */
  514. function createCallback(func, thisArg) {
  515. if (!func) {
  516. return identity;
  517. }
  518. if (typeof func != 'function') {
  519. return function(object) {
  520. return object[func];
  521. };
  522. }
  523. if (thisArg !== undefined) {
  524. return function(value, index, object) {
  525. return func.call(thisArg, value, index, object);
  526. };
  527. }
  528. return func;
  529. }
  530. /**
  531. * Creates compiled iteration functions.
  532. *
  533. * @private
  534. * @param {Object} [options1, options2, ...] The compile options object(s).
  535. * useHas - A boolean to specify using `hasOwnProperty` checks in the object loop.
  536. * args - A string of comma separated arguments the iteration function will accept.
  537. * top - A string of code to execute before the iteration branches.
  538. * arrayLoop - A string of code to execute in the array loop.
  539. * objectLoop - A string of code to execute in the object loop.
  540. * bottom - A string of code to execute after the iteration branches.
  541. *
  542. * @returns {Function} Returns the compiled function.
  543. */
  544. function createIterator() {
  545. var data = {
  546. 'arrayLoop': '',
  547. 'bottom': '',
  548. 'hasDontEnumBug': hasDontEnumBug,
  549. 'isKeysFast': isKeysFast,
  550. 'objectLoop': '',
  551. 'noArgsEnum': noArgsEnum,
  552. 'noCharByIndex': noCharByIndex,
  553. 'shadowed': shadowed,
  554. 'top': '',
  555. 'useHas': true
  556. };
  557. // merge options into a template data object
  558. for (var object, index = 0; object = arguments[index]; index++) {
  559. for (var key in object) {
  560. data[key] = object[key];
  561. }
  562. }
  563. var args = data.args;
  564. data.firstArg = /^[^,]+/.exec(args)[0];
  565. // create the function factory
  566. var factory = Function(
  567. 'createCallback, hasOwnProperty, isArguments, isString, objectTypes, ' +
  568. 'nativeKeys, propertyIsEnumerable',
  569. 'return function(' + args + ') {\n' + iteratorTemplate(data) + '\n}'
  570. );
  571. // return the compiled function
  572. return factory(
  573. createCallback, hasOwnProperty, isArguments, isString, objectTypes,
  574. nativeKeys, propertyIsEnumerable
  575. );
  576. }
  577. /**
  578. * Used by `template` to escape characters for inclusion in compiled
  579. * string literals.
  580. *
  581. * @private
  582. * @param {String} match The matched character to escape.
  583. * @returns {String} Returns the escaped character.
  584. */
  585. function escapeStringChar(match) {
  586. return '\\' + stringEscapes[match];
  587. }
  588. /**
  589. * Used by `escape` to convert characters to HTML entities.
  590. *
  591. * @private
  592. * @param {String} match The matched character to escape.
  593. * @returns {String} Returns the escaped character.
  594. */
  595. function escapeHtmlChar(match) {
  596. return htmlEscapes[match];
  597. }
  598. /**
  599. * A no-operation function.
  600. *
  601. * @private
  602. */
  603. function noop() {
  604. // no operation performed
  605. }
  606. /**
  607. * Used by `unescape` to convert HTML entities to characters.
  608. *
  609. * @private
  610. * @param {String} match The matched character to unescape.
  611. * @returns {String} Returns the unescaped character.
  612. */
  613. function unescapeHtmlChar(match) {
  614. return htmlUnescapes[match];
  615. }
  616. /*--------------------------------------------------------------------------*/
  617. /**
  618. * Assigns own enumerable properties of source object(s) to the `destination`
  619. * object. Subsequent sources will overwrite propery assignments of previous
  620. * sources.
  621. *
  622. * @static
  623. * @memberOf _
  624. * @alias extend
  625. * @category Objects
  626. * @param {Object} object The destination object.
  627. * @param {Object} [source1, source2, ...] The source objects.
  628. * @returns {Object} Returns the destination object.
  629. * @example
  630. *
  631. * _.assign({ 'name': 'moe' }, { 'age': 40 });
  632. * // => { 'name': 'moe', 'age': 40 }
  633. */
  634. var assign = createIterator(assignIteratorOptions);
  635. /**
  636. * Checks if `value` is an `arguments` object.
  637. *
  638. * @static
  639. * @memberOf _
  640. * @category Objects
  641. * @param {Mixed} value The value to check.
  642. * @returns {Boolean} Returns `true` if the `value` is an `arguments` object, else `false`.
  643. * @example
  644. *
  645. * (function() { return _.isArguments(arguments); })(1, 2, 3);
  646. * // => true
  647. *
  648. * _.isArguments([1, 2, 3]);
  649. * // => false
  650. */
  651. function isArguments(value) {
  652. return toString.call(value) == argsClass;
  653. }
  654. // fallback for browsers that can't detect `arguments` objects by [[Class]]
  655. if (noArgsClass) {
  656. isArguments = function(value) {
  657. return value ? hasOwnProperty.call(value, 'callee') : false;
  658. };
  659. }
  660. /**
  661. * Iterates over `object`'s own and inherited enumerable properties, executing
  662. * the `callback` for each property. The `callback` is bound to `thisArg` and
  663. * invoked with three arguments; (value, key, object). Callbacks may exit iteration
  664. * early by explicitly returning `false`.
  665. *
  666. * @static
  667. * @memberOf _
  668. * @category Objects
  669. * @param {Object} object The object to iterate over.
  670. * @param {Function} callback The function called per iteration.
  671. * @param {Mixed} [thisArg] The `this` binding of `callback`.
  672. * @returns {Object} Returns `object`.
  673. * @example
  674. *
  675. * function Dog(name) {
  676. * this.name = name;
  677. * }
  678. *
  679. * Dog.prototype.bark = function() {
  680. * alert('Woof, woof!');
  681. * };
  682. *
  683. * _.forIn(new Dog('Dagny'), function(value, key) {
  684. * alert(key);
  685. * });
  686. * // => alerts 'name' and 'bark' (order is not guaranteed)
  687. */
  688. var forIn = createIterator(forEachIteratorOptions, forOwnIteratorOptions, {
  689. 'useHas': false
  690. });
  691. /**
  692. * Iterates over an object's own enumerable properties, executing the `callback`
  693. * for each property. The `callback` is bound to `thisArg` and invoked with three
  694. * arguments; (value, key, object). Callbacks may exit iteration early by explicitly
  695. * returning `false`.
  696. *
  697. * @static
  698. * @memberOf _
  699. * @category Objects
  700. * @param {Object} object The object to iterate over.
  701. * @param {Function} callback The function called per iteration.
  702. * @param {Mixed} [thisArg] The `this` binding of `callback`.
  703. * @returns {Object} Returns `object`.
  704. * @example
  705. *
  706. * _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) {
  707. * alert(key);
  708. * });
  709. * // => alerts '0', '1', and 'length' (order is not guaranteed)
  710. */
  711. var forOwn = createIterator(forEachIteratorOptions, forOwnIteratorOptions);
  712. /**
  713. * A fallback implementation of `isPlainObject` that checks if a given `value`
  714. * is an object created by the `Object` constructor, assuming objects created
  715. * by the `Object` constructor have no inherited enumerable properties and that
  716. * there are no `Object.prototype` extensions.
  717. *
  718. * @private
  719. * @param {Mixed} value The value to check.
  720. * @returns {Boolean} Returns `true` if `value` is a plain object, else `false`.
  721. */
  722. function shimIsPlainObject(value) {
  723. // avoid non-objects and false positives for `arguments` objects
  724. var result = false;
  725. if (!(value && typeof value == 'object') || isArguments(value)) {
  726. return result;
  727. }
  728. // IE < 9 presents DOM nodes as `Object` objects except they have `toString`
  729. // methods that are `typeof` "string" and still can coerce nodes to strings.
  730. // Also check that the constructor is `Object` (i.e. `Object instanceof Object`)
  731. var ctor = value.constructor;
  732. if ((!noNodeClass || !(typeof value.toString != 'function' && typeof (value + '') == 'string')) &&
  733. (!isFunction(ctor) || ctor instanceof ctor)) {
  734. // IE < 9 iterates inherited properties before own properties. If the first
  735. // iterated property is an object's own property then there are no inherited
  736. // enumerable properties.
  737. if (iteratesOwnLast) {
  738. forIn(value, function(value, key, object) {
  739. result = !hasOwnProperty.call(object, key);
  740. return false;
  741. });
  742. return result === false;
  743. }
  744. // In most environments an object's own properties are iterated before
  745. // its inherited properties. If the last iterated property is an object's
  746. // own property then there are no inherited enumerable properties.
  747. forIn(value, function(value, key) {
  748. result = key;
  749. });
  750. return result === false || hasOwnProperty.call(value, result);
  751. }
  752. return result;
  753. }
  754. /**
  755. * A fallback implementation of `Object.keys` that produces an array of the
  756. * given object's own enumerable property names.
  757. *
  758. * @private
  759. * @param {Object} object The object to inspect.
  760. * @returns {Array} Returns a new array of property names.
  761. */
  762. function shimKeys(object) {
  763. var result = [];
  764. forOwn(object, function(value, key) {
  765. result.push(key);
  766. });
  767. return result;
  768. }
  769. /**
  770. * Used to convert characters to HTML entities:
  771. *
  772. * Though the `>` character is escaped for symmetry, characters like `>` and `/`
  773. * don't require escaping in HTML and have no special meaning unless they're part
  774. * of a tag or an unquoted attribute value.
  775. * http://mathiasbynens.be/notes/ambiguous-ampersands (under "semi-related fun fact")
  776. */
  777. var htmlEscapes = {
  778. '&': '&amp;',
  779. '<': '&lt;',
  780. '>': '&gt;',
  781. '"': '&quot;',
  782. "'": '&#x27;'
  783. };
  784. /** Used to convert HTML entities to characters */
  785. var htmlUnescapes = invert(htmlEscapes);
  786. /*--------------------------------------------------------------------------*/
  787. /**
  788. * Creates a clone of `value`. If `deep` is `true`, all nested objects will
  789. * also be cloned otherwise they will be assigned by reference. Functions, DOM
  790. * nodes, `arguments` objects, and objects created by constructors other than
  791. * `Object` are **not** cloned.
  792. *
  793. * @static
  794. * @memberOf _
  795. * @category Objects
  796. * @param {Mixed} value The value to clone.
  797. * @param {Boolean} deep A flag to indicate a deep clone.
  798. * @param- {Object} [guard] Internally used to allow this method to work with
  799. * others like `_.map` without using their callback `index` argument for `deep`.
  800. * @param- {Array} [stackA=[]] Internally used to track traversed source objects.
  801. * @param- {Array} [stackB=[]] Internally used to associate clones with their
  802. * source counterparts.
  803. * @returns {Mixed} Returns the cloned `value`.
  804. * @example
  805. *
  806. * var stooges = [
  807. * { 'name': 'moe', 'age': 40 },
  808. * { 'name': 'larry', 'age': 50 },
  809. * { 'name': 'curly', 'age': 60 }
  810. * ];
  811. *
  812. * _.clone({ 'name': 'moe' });
  813. * // => { 'name': 'moe' }
  814. *
  815. * var shallow = _.clone(stooges);
  816. * shallow[0] === stooges[0];
  817. * // => true
  818. *
  819. * var deep = _.clone(stooges, true);
  820. * shallow[0] === stooges[0];
  821. * // => false
  822. */
  823. function clone(value, deep, guard, stackA, stackB) {
  824. if (value == null) {
  825. return value;
  826. }
  827. if (guard) {
  828. deep = false;
  829. }
  830. // inspect [[Class]]
  831. var isObj = isObject(value);
  832. if (isObj) {
  833. // don't clone `arguments` objects, functions, or non-object Objects
  834. var className = toString.call(value);
  835. if (!cloneableClasses[className] || (noArgsClass && isArguments(value))) {
  836. return value;
  837. }
  838. var isArr = className == arrayClass;
  839. isObj = isArr || (className == objectClass ? isPlainObject(value) : isObj);
  840. }
  841. // shallow clone
  842. if (!isObj || !deep) {
  843. // don't clone functions
  844. return isObj
  845. ? (isArr ? slice.call(value) : assign({}, value))
  846. : value;
  847. }
  848. var ctor = value.constructor;
  849. switch (className) {
  850. case boolClass:
  851. case dateClass:
  852. return new ctor(+value);
  853. case numberClass:
  854. case stringClass:
  855. return new ctor(value);
  856. case regexpClass:
  857. return ctor(value.source, reFlags.exec(value));
  858. }
  859. // check for circular references and return corresponding clone
  860. stackA || (stackA = []);
  861. stackB || (stackB = []);
  862. var length = stackA.length;
  863. while (length--) {
  864. if (stackA[length] == value) {
  865. return stackB[length];
  866. }
  867. }
  868. // init cloned object
  869. var result = isArr ? ctor(value.length) : {};
  870. // add the source value to the stack of traversed objects
  871. // and associate it with its clone
  872. stackA.push(value);
  873. stackB.push(result);
  874. // recursively populate clone (susceptible to call stack limits)
  875. (isArr ? forEach : forOwn)(value, function(objValue, key) {
  876. result[key] = clone(objValue, deep, null, stackA, stackB);
  877. });
  878. return result;
  879. }
  880. /**
  881. * Assigns own enumerable properties of source object(s) to the `destination`
  882. * object for all `destination` properties that resolve to `null`/`undefined`.
  883. * Once a property is set, additional defaults of the same property will be
  884. * ignored.
  885. *
  886. * @static
  887. * @memberOf _
  888. * @category Objects
  889. * @param {Object} object The destination object.
  890. * @param {Object} [default1, default2, ...] The default objects.
  891. * @returns {Object} Returns the destination object.
  892. * @example
  893. *
  894. * var iceCream = { 'flavor': 'chocolate' };
  895. * _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' });
  896. * // => { 'flavor': 'chocolate', 'sprinkles': 'rainbow' }
  897. */
  898. var defaults = createIterator(assignIteratorOptions, {
  899. 'objectLoop': 'if (result[index] == null) ' + assignIteratorOptions.objectLoop
  900. });
  901. /**
  902. * Creates a sorted array of all enumerable properties, own and inherited,
  903. * of `object` that have function values.
  904. *
  905. * @static
  906. * @memberOf _
  907. * @alias methods
  908. * @category Objects
  909. * @param {Object} object The object to inspect.
  910. * @returns {Array} Returns a new array of property names that have function values.
  911. * @example
  912. *
  913. * _.functions(_);
  914. * // => ['all', 'any', 'bind', 'bindAll', 'clone', 'compact', 'compose', ...]
  915. */
  916. function functions(object) {
  917. var result = [];
  918. forIn(object, function(value, key) {
  919. if (isFunction(value)) {
  920. result.push(key);
  921. }
  922. });
  923. return result.sort();
  924. }
  925. /**
  926. * Checks if the specified object `property` exists and is a direct property,
  927. * instead of an inherited property.
  928. *
  929. * @static
  930. * @memberOf _
  931. * @category Objects
  932. * @param {Object} object The object to check.
  933. * @param {String} property The property to check for.
  934. * @returns {Boolean} Returns `true` if key is a direct property, else `false`.
  935. * @example
  936. *
  937. * _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b');
  938. * // => true
  939. */
  940. function has(object, property) {
  941. return object ? hasOwnProperty.call(object, property) : false;
  942. }
  943. /**
  944. * Creates an object composed of the inverted keys and values of the given `object`.
  945. *
  946. * @static
  947. * @memberOf _
  948. * @category Objects
  949. * @param {Object} object The object to invert.
  950. * @returns {Object} Returns the created inverted object.
  951. * @example
  952. *
  953. * _.invert({ 'first': 'Moe', 'second': 'Larry', 'third': 'Curly' });
  954. * // => { 'Moe': 'first', 'Larry': 'second', 'Curly': 'third' } (order is not guaranteed)
  955. */
  956. function invert(object) {
  957. var result = {};
  958. forOwn(object, function(value, key) {
  959. result[value] = key;
  960. });
  961. return result;
  962. }
  963. /**
  964. * Checks if `value` is an array.
  965. *
  966. * @static
  967. * @memberOf _
  968. * @category Objects
  969. * @param {Mixed} value The value to check.
  970. * @returns {Boolean} Returns `true` if the `value` is an array, else `false`.
  971. * @example
  972. *
  973. * (function() { return _.isArray(arguments); })();
  974. * // => false
  975. *
  976. * _.isArray([1, 2, 3]);
  977. * // => true
  978. */
  979. var isArray = nativeIsArray || function(value) {
  980. return toString.call(value) == arrayClass;
  981. };
  982. /**
  983. * Checks if `value` is a boolean (`true` or `false`) value.
  984. *
  985. * @static
  986. * @memberOf _
  987. * @category Objects
  988. * @param {Mixed} value The value to check.
  989. * @returns {Boolean} Returns `true` if the `value` is a boolean value, else `false`.
  990. * @example
  991. *
  992. * _.isBoolean(null);
  993. * // => false
  994. */
  995. function isBoolean(value) {
  996. return value === true || value === false || toString.call(value) == boolClass;
  997. }
  998. /**
  999. * Checks if `value` is a date.
  1000. *
  1001. * @static
  1002. * @memberOf _
  1003. * @category Objects
  1004. * @param {Mixed} value The value to check.
  1005. * @returns {Boolean} Returns `true` if the `value` is a date, else `false`.
  1006. * @example
  1007. *
  1008. * _.isDate(new Date);
  1009. * // => true
  1010. */
  1011. function isDate(value) {
  1012. return toString.call(value) == dateClass;
  1013. }
  1014. /**
  1015. * Checks if `value` is a DOM element.
  1016. *
  1017. * @static
  1018. * @memberOf _
  1019. * @category Objects
  1020. * @param {Mixed} value The value to check.
  1021. * @returns {Boolean} Returns `true` if the `value` is a DOM element, else `false`.
  1022. * @example
  1023. *
  1024. * _.isElement(document.body);
  1025. * // => true
  1026. */
  1027. function isElement(value) {
  1028. return value ? value.nodeType === 1 : false;
  1029. }
  1030. /**
  1031. * Checks if `value` is empty. Arrays, strings, or `arguments` objects with a
  1032. * length of `0` and objects with no own enumerable properties are considered
  1033. * "empty".
  1034. *
  1035. * @static
  1036. * @memberOf _
  1037. * @category Objects
  1038. * @param {Array|Object|String} value The value to inspect.
  1039. * @returns {Boolean} Returns `true` if the `value` is empty, else `false`.
  1040. * @example
  1041. *
  1042. * _.isEmpty([1, 2, 3]);
  1043. * // => false
  1044. *
  1045. * _.isEmpty({});
  1046. * // => true
  1047. *
  1048. * _.isEmpty('');
  1049. * // => true
  1050. */
  1051. function isEmpty(value) {
  1052. var result = true;
  1053. if (!value) {
  1054. return result;
  1055. }
  1056. var className = toString.call(value),
  1057. length = value.length;
  1058. if ((className == arrayClass || className == stringClass ||
  1059. className == argsClass || (noArgsClass && isArguments(value))) ||
  1060. (className == objectClass && typeof length == 'number' && isFunction(value.splice))) {
  1061. return !length;
  1062. }
  1063. forOwn(value, function() {
  1064. return (result = false);
  1065. });
  1066. return result;
  1067. }
  1068. /**
  1069. * Performs a deep comparison between two values to determine if they are
  1070. * equivalent to each other.
  1071. *
  1072. * @static
  1073. * @memberOf _
  1074. * @category Objects
  1075. * @param {Mixed} a The value to compare.
  1076. * @param {Mixed} b The other value to compare.
  1077. * @param- {Object} [stackA=[]] Internally used track traversed `a` objects.
  1078. * @param- {Object} [stackB=[]] Internally used track traversed `b` objects.
  1079. * @returns {Boolean} Returns `true` if the values are equvalent, else `false`.
  1080. * @example
  1081. *
  1082. * var moe = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] };
  1083. * var clone = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] };
  1084. *
  1085. * moe == clone;
  1086. * // => false
  1087. *
  1088. * _.isEqual(moe, clone);
  1089. * // => true
  1090. */
  1091. function isEqual(a, b, stackA, stackB) {
  1092. // exit early for identical values
  1093. if (a === b) {
  1094. // treat `+0` vs. `-0` as not equal
  1095. return a !== 0 || (1 / a == 1 / b);
  1096. }
  1097. // a strict comparison is necessary because `null == undefined`
  1098. if (a == null || b == null) {
  1099. return a === b;
  1100. }
  1101. // compare [[Class]] names
  1102. var className = toString.call(a);
  1103. if (className != toString.call(b)) {
  1104. return false;
  1105. }
  1106. switch (className) {
  1107. case boolClass:
  1108. case dateClass:
  1109. // coerce dates and booleans to numbers, dates to milliseconds and booleans
  1110. // to `1` or `0`, treating invalid dates coerced to `NaN` as not equal
  1111. return +a == +b;
  1112. case numberClass:
  1113. // treat `NaN` vs. `NaN` as equal
  1114. return a != +a
  1115. ? b != +b
  1116. // but treat `+0` vs. `-0` as not equal
  1117. : (a == 0 ? (1 / a == 1 / b) : a == +b);
  1118. case regexpClass:
  1119. case stringClass:
  1120. // coerce regexes to strings (http://es5.github.com/#x15.10.6.4)
  1121. // treat string primitives and their corresponding object instances as equal
  1122. return a == b + '';
  1123. }
  1124. // exit early, in older browsers, if `a` is array-like but not `b`
  1125. var isArr = className == arrayClass || className == argsClass;
  1126. if (noArgsClass && !isArr && (isArr = isArguments(a)) && !isArguments(b)) {
  1127. return false;
  1128. }
  1129. if (!isArr) {
  1130. // unwrap any `lodash` wrapped values
  1131. if (a.__wrapped__ || b.__wrapped__) {
  1132. return isEqual(a.__wrapped__ || a, b.__wrapped__ || b);
  1133. }
  1134. // exit for functions and DOM nodes
  1135. if (className != objectClass || (noNodeClass && (
  1136. (typeof a.toString != 'function' && typeof (a + '') == 'string') ||
  1137. (typeof b.toString != 'function' && typeof (b + '') == 'string')))) {
  1138. return false;
  1139. }
  1140. var ctorA = a.constructor,
  1141. ctorB = b.constructor;
  1142. // non `Object` object instances with different constructors are not equal
  1143. if (ctorA != ctorB && !(
  1144. isFunction(ctorA) && ctorA instanceof ctorA &&
  1145. isFunction(ctorB) && ctorB instanceof ctorB
  1146. )) {
  1147. return false;
  1148. }
  1149. }
  1150. // assume cyclic structures are equal
  1151. // the algorithm for detecting cyclic structures is adapted from ES 5.1
  1152. // section 15.12.3, abstract operation `JO` (http://es5.github.com/#x15.12.3)
  1153. stackA || (stackA = []);
  1154. stackB || (stackB = []);
  1155. var length = stackA.length;
  1156. while (length--) {
  1157. if (stackA[length] == a) {
  1158. return stackB[length] == b;
  1159. }
  1160. }
  1161. var index = -1,
  1162. result = true,
  1163. size = 0;
  1164. // add `a` and `b` to the stack of traversed objects
  1165. stackA.push(a);
  1166. stackB.push(b);
  1167. // recursively compare objects and arrays (susceptible to call stack limits)
  1168. if (isArr) {
  1169. // compare lengths to determine if a deep comparison is necessary
  1170. size = a.length;
  1171. result = size == b.length;
  1172. if (result) {
  1173. // deep compare the contents, ignoring non-numeric properties
  1174. while (size--) {
  1175. if (!(result = isEqual(a[size], b[size], stackA, stackB))) {
  1176. break;
  1177. }
  1178. }
  1179. }
  1180. return result;
  1181. }
  1182. // deep compare objects
  1183. for (var key in a) {
  1184. if (hasOwnProperty.call(a, key)) {
  1185. // count the number of properties.
  1186. size++;
  1187. // deep compare each property value.
  1188. if (!(hasOwnProperty.call(b, key) && isEqual(a[key], b[key], stackA, stackB))) {
  1189. return false;
  1190. }
  1191. }
  1192. }
  1193. // ensure both objects have the same number of properties
  1194. for (key in b) {
  1195. // The JS engine in Adobe products, like InDesign, has a bug that causes
  1196. // `!size--` to throw an error so it must be wrapped in parentheses.
  1197. // https://github.com/documentcloud/underscore/issues/355
  1198. if (hasOwnProperty.call(b, key) && !(size--)) {
  1199. // `size` will be `-1` if `b` has more properties than `a`
  1200. return false;
  1201. }
  1202. }
  1203. // handle JScript [[DontEnum]] bug
  1204. if (hasDontEnumBug) {
  1205. while (++index < 7) {
  1206. key = shadowed[index];
  1207. if (hasOwnProperty.call(a, key) &&
  1208. !(hasOwnProperty.call(b, key) && isEqual(a[key], b[key], stackA, stackB))) {
  1209. return false;
  1210. }
  1211. }
  1212. }
  1213. return true;
  1214. }
  1215. /**
  1216. * Checks if `value` is, or can be coerced to, a finite number.
  1217. *
  1218. * Note: This is not the same as native `isFinite`, which will return true for
  1219. * booleans and empty strings. See http://es5.github.com/#x15.1.2.5.
  1220. *
  1221. * @deprecated
  1222. * @static
  1223. * @memberOf _
  1224. * @category Objects
  1225. * @param {Mixed} value The value to check.
  1226. * @returns {Boolean} Returns `true` if the `value` is a finite number, else `false`.
  1227. * @example
  1228. *
  1229. * _.isFinite(-101);
  1230. * // => true
  1231. *
  1232. * _.isFinite('10');
  1233. * // => true
  1234. *
  1235. * _.isFinite(true);
  1236. * // => false
  1237. *
  1238. * _.isFinite('');
  1239. * // => false
  1240. *
  1241. * _.isFinite(Infinity);
  1242. * // => false
  1243. */
  1244. function isFinite(value) {
  1245. return nativeIsFinite(value) && !nativeIsNaN(parseFloat(value));
  1246. }
  1247. /**
  1248. * Checks if `value` is a function.
  1249. *
  1250. * @static
  1251. * @memberOf _
  1252. * @category Objects
  1253. * @param {Mixed} value The value to check.
  1254. * @returns {Boolean} Returns `true` if the `value` is a function, else `false`.
  1255. * @example
  1256. *
  1257. * _.isFunction(_);
  1258. * // => true
  1259. */
  1260. function isFunction(value) {
  1261. return typeof value == 'function';
  1262. }
  1263. // fallback for older versions of Chrome and Safari
  1264. if (isFunction(/x/)) {
  1265. isFunction = function(value) {
  1266. return toString.call(value) == funcClass;
  1267. };
  1268. }
  1269. /**
  1270. * Checks if `value` is the language type of Object.
  1271. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  1272. *
  1273. * @static
  1274. * @memberOf _
  1275. * @category Objects
  1276. * @param {Mixed} value The value to check.
  1277. * @returns {Boolean} Returns `true` if the `value` is an object, else `false`.
  1278. * @example
  1279. *
  1280. * _.isObject({});
  1281. * // => true
  1282. *
  1283. * _.isObject([1, 2, 3]);
  1284. * // => true
  1285. *
  1286. * _.isObject(1);
  1287. * // => false
  1288. */
  1289. function isObject(value) {
  1290. // check if the value is the ECMAScript language type of Object
  1291. // http://es5.github.com/#x8
  1292. // and avoid a V8 bug
  1293. // http://code.google.com/p/v8/issues/detail?id=2291
  1294. return value ? objectTypes[typeof value] : false;
  1295. }
  1296. /**
  1297. * Checks if `value` is `NaN`.
  1298. *
  1299. * Note: This is not the same as native `isNaN`, which will return true for
  1300. * `undefined` and other values. See http://es5.github.com/#x15.1.2.4.
  1301. *
  1302. * @deprecated
  1303. * @static
  1304. * @memberOf _
  1305. * @category Objects
  1306. * @param {Mixed} value The value to check.
  1307. * @returns {Boolean} Returns `true` if the `value` is `NaN`, else `false`.
  1308. * @example
  1309. *
  1310. * _.isNaN(NaN);
  1311. * // => true
  1312. *
  1313. * _.isNaN(new Number(NaN));
  1314. * // => true
  1315. *
  1316. * isNaN(undefined);
  1317. * // => true
  1318. *
  1319. * _.isNaN(undefined);
  1320. * // => false
  1321. */
  1322. function isNaN(value) {
  1323. // `NaN` as a primitive is the only value that is not equal to itself
  1324. // (perform the [[Class]] check first to avoid errors with some host objects in IE)
  1325. return toString.call(value) == numberClass && value != +value
  1326. }
  1327. /**
  1328. * Checks if `value` is `null`.
  1329. *
  1330. * @deprecated
  1331. * @static
  1332. * @memberOf _
  1333. * @category Objects
  1334. * @param {Mixed} value The value to check.
  1335. * @returns {Boolean} Returns `true` if the `value` is `null`, else `false`.
  1336. * @example
  1337. *
  1338. * _.isNull(null);
  1339. * // => true
  1340. *
  1341. * _.isNull(undefined);
  1342. * // => false
  1343. */
  1344. function isNull(value) {
  1345. return value === null;
  1346. }
  1347. /**
  1348. * Checks if `value` is a number.
  1349. *
  1350. * @static
  1351. * @memberOf _
  1352. * @category Objects
  1353. * @param {Mixed} value The value to check.
  1354. * @returns {Boolean} Returns `true` if the `value` is a number, else `false`.
  1355. * @example
  1356. *
  1357. * _.isNumber(8.4 * 5);
  1358. * // => true
  1359. */
  1360. function isNumber(value) {
  1361. return toString.call(value) == numberClass;
  1362. }
  1363. /**
  1364. * Checks if a given `value` is an object created by the `Object` constructor.
  1365. *
  1366. * @static
  1367. * @memberOf _
  1368. * @category Objects
  1369. * @param {Mixed} value The value to check.
  1370. * @returns {Boolean} Returns `true` if `value` is a plain object, else `false`.
  1371. * @example
  1372. *
  1373. * function Stooge(name, age) {
  1374. * this.name = name;
  1375. * this.age = age;
  1376. * }
  1377. *
  1378. * _.isPlainObject(new Stooge('moe', 40));
  1379. * // => false
  1380. *
  1381. * _.isPlainObject([1, 2, 3]);
  1382. * // => false
  1383. *
  1384. * _.isPlainObject({ 'name': 'moe', 'age': 40 });
  1385. * // => true
  1386. */
  1387. var isPlainObject = !getPrototypeOf ? shimIsPlainObject : function(value) {
  1388. if (!(value && typeof value == 'object')) {
  1389. return false;
  1390. }
  1391. var valueOf = value.valueOf,
  1392. objProto = typeof valueOf == 'function' && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
  1393. return objProto
  1394. ? value == objProto || (getPrototypeOf(value) == objProto && !isArguments(value))
  1395. : shimIsPlainObject(value);
  1396. };
  1397. /**
  1398. * Checks if `value` is a regular expression.
  1399. *
  1400. * @static
  1401. * @memberOf _
  1402. * @category Objects
  1403. * @param {Mixed} value The value to check.
  1404. * @returns {Boolean} Returns `true` if the `value` is a regular expression, else `false`.
  1405. * @example
  1406. *
  1407. * _.isRegExp(/moe/);
  1408. * // => true
  1409. */
  1410. function isRegExp(value) {
  1411. return toString.call(value) == regexpClass;
  1412. }
  1413. /**
  1414. * Checks if `value` is a string.
  1415. *
  1416. * @static
  1417. * @memberOf _
  1418. * @category Objects
  1419. * @param {Mixed} value The value to check.
  1420. * @returns {Boolean} Returns `true` if the `value` is a string, else `false`.
  1421. * @example
  1422. *
  1423. * _.isString('moe');
  1424. * // => true
  1425. */
  1426. function isString(value) {
  1427. return toString.call(value) == stringClass;
  1428. }
  1429. /**
  1430. * Checks if `value` is `undefined`.
  1431. *
  1432. * @deprecated
  1433. * @static
  1434. * @memberOf _
  1435. * @category Objects
  1436. * @param {Mixed} value The value to check.
  1437. * @returns {Boolean} Returns `true` if the `value` is `undefined`, else `false`.
  1438. * @example
  1439. *
  1440. * _.isUndefined(void 0);
  1441. * // => true
  1442. */
  1443. function isUndefined(value) {
  1444. return value === undefined;
  1445. }
  1446. /**
  1447. * Creates an array composed of the own enumerable property names of `object`.
  1448. *
  1449. * @static
  1450. * @memberOf _
  1451. * @category Objects
  1452. * @param {Object} object The object to inspect.
  1453. * @returns {Array} Returns a new array of property names.
  1454. * @example
  1455. *
  1456. * _.keys({ 'one': 1, 'two': 2, 'three': 3 });
  1457. * // => ['one', 'two', 'three'] (order is not guaranteed)
  1458. */
  1459. var keys = !nativeKeys ? shimKeys : function(object) {
  1460. // avoid iterating over the `prototype` property
  1461. return typeof object == 'function' && propertyIsEnumerable.call(object, 'prototype')
  1462. ? shimKeys(object)
  1463. : (isObject(object) ? nativeKeys(object) : []);
  1464. };
  1465. /**
  1466. * Merges enumerable properties of the source object(s) into the `destination`
  1467. * object. Subsequent sources will overwrite propery assignments of previous
  1468. * sources.
  1469. *
  1470. * @static
  1471. * @memberOf _
  1472. * @category Objects
  1473. * @param {Object} object The destination object.
  1474. * @param {Object} [source1, source2, ...] The source objects.
  1475. * @param- {Object} [indicator] Internally used to indicate that the `stack`
  1476. * argument is an array of traversed objects instead …

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