PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/files/lodash/2.4.0/lodash.underscore.js

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