PageRenderTime 58ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/files/lodash/2.4.2/lodash.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 1522 lines | 827 code | 133 blank | 562 comment | 281 complexity | e711d3ebde0fbeabcb24359e6db7b49a MD5 | raw file
  1. /**
  2. * @license
  3. * Lo-Dash 2.4.2 (Custom Build) <https://lodash.com/>
  4. * Build: `lodash modern -o ./dist/lodash.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 <https://lodash.com/license>
  9. */
  10. ;(function() {
  11. /** Used as a safe reference for `undefined` in pre ES5 environments */
  12. var undefined;
  13. /** Used to pool arrays and objects used internally */
  14. var arrayPool = [],
  15. objectPool = [];
  16. /** Used to generate unique IDs */
  17. var idCounter = 0;
  18. /** Used to prefix keys to avoid issues with `__proto__` and properties on `Object.prototype` */
  19. var keyPrefix = +new Date + '';
  20. /** Used as the size when optimizations are enabled for large arrays */
  21. var largeArraySize = 75;
  22. /** Used as the max size of the `arrayPool` and `objectPool` */
  23. var maxPoolSize = 40;
  24. /** Used to detect and test whitespace */
  25. var whitespace = (
  26. // whitespace
  27. ' \t\x0B\f\xA0\ufeff' +
  28. // line terminators
  29. '\n\r\u2028\u2029' +
  30. // unicode category "Zs" space separators
  31. '\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000'
  32. );
  33. /** Used to match empty string literals in compiled template source */
  34. var reEmptyStringLeading = /\b__p \+= '';/g,
  35. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  36. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  37. /**
  38. * Used to match ES6 template delimiters
  39. * http://people.mozilla.org/~jorendorff/es6-draft.html#sec-literals-string-literals
  40. */
  41. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  42. /** Used to match regexp flags from their coerced string values */
  43. var reFlags = /\w*$/;
  44. /** Used to detected named functions */
  45. var reFuncName = /^\s*function[ \n\r\t]+\w/;
  46. /** Used to match "interpolate" template delimiters */
  47. var reInterpolate = /<%=([\s\S]+?)%>/g;
  48. /** Used to match leading whitespace and zeros to be removed */
  49. var reLeadingSpacesAndZeros = RegExp('^[' + whitespace + ']*0+(?=.$)');
  50. /** Used to ensure capturing order of template delimiters */
  51. var reNoMatch = /($^)/;
  52. /** Used to detect functions containing a `this` reference */
  53. var reThis = /\bthis\b/;
  54. /** Used to match unescaped characters in compiled string literals */
  55. var reUnescapedString = /['\n\r\t\u2028\u2029\\]/g;
  56. /** Used to assign default `context` object properties */
  57. var contextProps = [
  58. 'Array', 'Boolean', 'Date', 'Function', 'Math', 'Number', 'Object',
  59. 'RegExp', 'String', '_', 'attachEvent', 'clearTimeout', 'isFinite', 'isNaN',
  60. 'parseInt', 'setTimeout'
  61. ];
  62. /** Used to make template sourceURLs easier to identify */
  63. var templateCounter = 0;
  64. /** `Object#toString` result shortcuts */
  65. var argsClass = '[object Arguments]',
  66. arrayClass = '[object Array]',
  67. boolClass = '[object Boolean]',
  68. dateClass = '[object Date]',
  69. funcClass = '[object Function]',
  70. numberClass = '[object Number]',
  71. objectClass = '[object Object]',
  72. regexpClass = '[object RegExp]',
  73. stringClass = '[object String]';
  74. /** Used to identify object classifications that `_.clone` supports */
  75. var cloneableClasses = {};
  76. cloneableClasses[funcClass] = false;
  77. cloneableClasses[argsClass] = cloneableClasses[arrayClass] =
  78. cloneableClasses[boolClass] = cloneableClasses[dateClass] =
  79. cloneableClasses[numberClass] = cloneableClasses[objectClass] =
  80. cloneableClasses[regexpClass] = cloneableClasses[stringClass] = true;
  81. /** Used as an internal `_.debounce` options object */
  82. var debounceOptions = {
  83. 'leading': false,
  84. 'maxWait': 0,
  85. 'trailing': false
  86. };
  87. /** Used as the property descriptor for `__bindData__` */
  88. var descriptor = {
  89. 'configurable': false,
  90. 'enumerable': false,
  91. 'value': null,
  92. 'writable': false
  93. };
  94. /** Used to determine if values are of the language type Object */
  95. var objectTypes = {
  96. 'boolean': false,
  97. 'function': true,
  98. 'object': true,
  99. 'number': false,
  100. 'string': false,
  101. 'undefined': false
  102. };
  103. /** Used to escape characters for inclusion in compiled string literals */
  104. var stringEscapes = {
  105. '\\': '\\',
  106. "'": "'",
  107. '\n': 'n',
  108. '\r': 'r',
  109. '\t': 't',
  110. '\u2028': 'u2028',
  111. '\u2029': 'u2029'
  112. };
  113. /** Used as a reference to the global object */
  114. var root = (objectTypes[typeof window] && window) || this;
  115. /** Detect free variable `exports` */
  116. var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
  117. /** Detect free variable `module` */
  118. var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
  119. /** Detect the popular CommonJS extension `module.exports` */
  120. var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
  121. /** Detect free variable `global` from Node.js or Browserified code and use it as `root` */
  122. var freeGlobal = objectTypes[typeof global] && global;
  123. if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal)) {
  124. root = freeGlobal;
  125. }
  126. /*--------------------------------------------------------------------------*/
  127. /**
  128. * The base implementation of `_.indexOf` without support for binary searches
  129. * or `fromIndex` constraints.
  130. *
  131. * @private
  132. * @param {Array} array The array to search.
  133. * @param {*} value The value to search for.
  134. * @param {number} [fromIndex=0] The index to search from.
  135. * @returns {number} Returns the index of the matched value or `-1`.
  136. */
  137. function baseIndexOf(array, value, fromIndex) {
  138. var index = (fromIndex || 0) - 1,
  139. length = array ? array.length : 0;
  140. while (++index < length) {
  141. if (array[index] === value) {
  142. return index;
  143. }
  144. }
  145. return -1;
  146. }
  147. /**
  148. * An implementation of `_.contains` for cache objects that mimics the return
  149. * signature of `_.indexOf` by returning `0` if the value is found, else `-1`.
  150. *
  151. * @private
  152. * @param {Object} cache The cache object to inspect.
  153. * @param {*} value The value to search for.
  154. * @returns {number} Returns `0` if `value` is found, else `-1`.
  155. */
  156. function cacheIndexOf(cache, value) {
  157. var type = typeof value;
  158. cache = cache.cache;
  159. if (type == 'boolean' || value == null) {
  160. return cache[value] ? 0 : -1;
  161. }
  162. if (type != 'number' && type != 'string') {
  163. type = 'object';
  164. }
  165. var key = type == 'number' ? value : keyPrefix + value;
  166. cache = (cache = cache[type]) && cache[key];
  167. return type == 'object'
  168. ? (cache && baseIndexOf(cache, value) > -1 ? 0 : -1)
  169. : (cache ? 0 : -1);
  170. }
  171. /**
  172. * Adds a given value to the corresponding cache object.
  173. *
  174. * @private
  175. * @param {*} value The value to add to the cache.
  176. */
  177. function cachePush(value) {
  178. var cache = this.cache,
  179. type = typeof value;
  180. if (type == 'boolean' || value == null) {
  181. cache[value] = true;
  182. } else {
  183. if (type != 'number' && type != 'string') {
  184. type = 'object';
  185. }
  186. var key = type == 'number' ? value : keyPrefix + value,
  187. typeCache = cache[type] || (cache[type] = {});
  188. if (type == 'object') {
  189. (typeCache[key] || (typeCache[key] = [])).push(value);
  190. } else {
  191. typeCache[key] = true;
  192. }
  193. }
  194. }
  195. /**
  196. * Used by `_.max` and `_.min` as the default callback when a given
  197. * collection is a string value.
  198. *
  199. * @private
  200. * @param {string} value The character to inspect.
  201. * @returns {number} Returns the code unit of given character.
  202. */
  203. function charAtCallback(value) {
  204. return value.charCodeAt(0);
  205. }
  206. /**
  207. * Used by `sortBy` to compare transformed `collection` elements, stable sorting
  208. * them in ascending order.
  209. *
  210. * @private
  211. * @param {Object} a The object to compare to `b`.
  212. * @param {Object} b The object to compare to `a`.
  213. * @returns {number} Returns the sort order indicator of `1` or `-1`.
  214. */
  215. function compareAscending(a, b) {
  216. var ac = a.criteria,
  217. bc = b.criteria,
  218. index = -1,
  219. length = ac.length;
  220. while (++index < length) {
  221. var value = ac[index],
  222. other = bc[index];
  223. if (value !== other) {
  224. if (value > other || typeof value == 'undefined') {
  225. return 1;
  226. }
  227. if (value < other || typeof other == 'undefined') {
  228. return -1;
  229. }
  230. }
  231. }
  232. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  233. // that causes it, under certain circumstances, to return the same value for
  234. // `a` and `b`. See https://github.com/jashkenas/underscore/pull/1247
  235. //
  236. // This also ensures a stable sort in V8 and other engines.
  237. // See http://code.google.com/p/v8/issues/detail?id=90
  238. return a.index - b.index;
  239. }
  240. /**
  241. * Creates a cache object to optimize linear searches of large arrays.
  242. *
  243. * @private
  244. * @param {Array} [array=[]] The array to search.
  245. * @returns {null|Object} Returns the cache object or `null` if caching should not be used.
  246. */
  247. function createCache(array) {
  248. var index = -1,
  249. length = array.length,
  250. first = array[0],
  251. mid = array[(length / 2) | 0],
  252. last = array[length - 1];
  253. if (first && typeof first == 'object' &&
  254. mid && typeof mid == 'object' && last && typeof last == 'object') {
  255. return false;
  256. }
  257. var cache = getObject();
  258. cache['false'] = cache['null'] = cache['true'] = cache['undefined'] = false;
  259. var result = getObject();
  260. result.array = array;
  261. result.cache = cache;
  262. result.push = cachePush;
  263. while (++index < length) {
  264. result.push(array[index]);
  265. }
  266. return result;
  267. }
  268. /**
  269. * Used by `template` to escape characters for inclusion in compiled
  270. * string literals.
  271. *
  272. * @private
  273. * @param {string} match The matched character to escape.
  274. * @returns {string} Returns the escaped character.
  275. */
  276. function escapeStringChar(match) {
  277. return '\\' + stringEscapes[match];
  278. }
  279. /**
  280. * Gets an array from the array pool or creates a new one if the pool is empty.
  281. *
  282. * @private
  283. * @returns {Array} The array from the pool.
  284. */
  285. function getArray() {
  286. return arrayPool.pop() || [];
  287. }
  288. /**
  289. * Gets an object from the object pool or creates a new one if the pool is empty.
  290. *
  291. * @private
  292. * @returns {Object} The object from the pool.
  293. */
  294. function getObject() {
  295. return objectPool.pop() || {
  296. 'array': null,
  297. 'cache': null,
  298. 'criteria': null,
  299. 'false': false,
  300. 'index': 0,
  301. 'null': false,
  302. 'number': null,
  303. 'object': null,
  304. 'push': null,
  305. 'string': null,
  306. 'true': false,
  307. 'undefined': false,
  308. 'value': null
  309. };
  310. }
  311. /**
  312. * Releases the given array back to the array pool.
  313. *
  314. * @private
  315. * @param {Array} [array] The array to release.
  316. */
  317. function releaseArray(array) {
  318. array.length = 0;
  319. if (arrayPool.length < maxPoolSize) {
  320. arrayPool.push(array);
  321. }
  322. }
  323. /**
  324. * Releases the given object back to the object pool.
  325. *
  326. * @private
  327. * @param {Object} [object] The object to release.
  328. */
  329. function releaseObject(object) {
  330. var cache = object.cache;
  331. if (cache) {
  332. releaseObject(cache);
  333. }
  334. object.array = object.cache = object.criteria = object.object = object.number = object.string = object.value = null;
  335. if (objectPool.length < maxPoolSize) {
  336. objectPool.push(object);
  337. }
  338. }
  339. /**
  340. * Slices the `collection` from the `start` index up to, but not including,
  341. * the `end` index.
  342. *
  343. * Note: This function is used instead of `Array#slice` to support node lists
  344. * in IE < 9 and to ensure dense arrays are returned.
  345. *
  346. * @private
  347. * @param {Array|Object|string} collection The collection to slice.
  348. * @param {number} start The start index.
  349. * @param {number} end The end index.
  350. * @returns {Array} Returns the new array.
  351. */
  352. function slice(array, start, end) {
  353. start || (start = 0);
  354. if (typeof end == 'undefined') {
  355. end = array ? array.length : 0;
  356. }
  357. var index = -1,
  358. length = end - start || 0,
  359. result = Array(length < 0 ? 0 : length);
  360. while (++index < length) {
  361. result[index] = array[start + index];
  362. }
  363. return result;
  364. }
  365. /*--------------------------------------------------------------------------*/
  366. /**
  367. * Create a new `lodash` function using the given context object.
  368. *
  369. * @static
  370. * @memberOf _
  371. * @category Utilities
  372. * @param {Object} [context=root] The context object.
  373. * @returns {Function} Returns the `lodash` function.
  374. */
  375. function runInContext(context) {
  376. // Avoid issues with some ES3 environments that attempt to use values, named
  377. // after built-in constructors like `Object`, for the creation of literals.
  378. // ES5 clears this up by stating that literals must use built-in constructors.
  379. // See http://es5.github.io/#x11.1.5.
  380. context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
  381. /** Native constructor references */
  382. var Array = context.Array,
  383. Boolean = context.Boolean,
  384. Date = context.Date,
  385. Function = context.Function,
  386. Math = context.Math,
  387. Number = context.Number,
  388. Object = context.Object,
  389. RegExp = context.RegExp,
  390. String = context.String,
  391. TypeError = context.TypeError;
  392. /**
  393. * Used for `Array` method references.
  394. *
  395. * Normally `Array.prototype` would suffice, however, using an array literal
  396. * avoids issues in Narwhal.
  397. */
  398. var arrayRef = [];
  399. /** Used for native method references */
  400. var objectProto = Object.prototype;
  401. /** Used to restore the original `_` reference in `noConflict` */
  402. var oldDash = context._;
  403. /** Used to resolve the internal [[Class]] of values */
  404. var toString = objectProto.toString;
  405. /** Used to detect if a method is native */
  406. var reNative = RegExp('^' +
  407. String(toString)
  408. .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
  409. .replace(/toString| for [^\]]+/g, '.*?') + '$'
  410. );
  411. /** Native method shortcuts */
  412. var ceil = Math.ceil,
  413. clearTimeout = context.clearTimeout,
  414. floor = Math.floor,
  415. fnToString = Function.prototype.toString,
  416. getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
  417. hasOwnProperty = objectProto.hasOwnProperty,
  418. push = arrayRef.push,
  419. setTimeout = context.setTimeout,
  420. splice = arrayRef.splice,
  421. unshift = arrayRef.unshift;
  422. /** Used to set meta data on functions */
  423. var defineProperty = (function() {
  424. // IE 8 only accepts DOM elements
  425. try {
  426. var o = {},
  427. func = isNative(func = Object.defineProperty) && func,
  428. result = func(o, o, o) && func;
  429. } catch(e) { }
  430. return result;
  431. }());
  432. /* Native method shortcuts for methods with the same name as other `lodash` methods */
  433. var nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate,
  434. nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray,
  435. nativeIsFinite = context.isFinite,
  436. nativeIsNaN = context.isNaN,
  437. nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys,
  438. nativeMax = Math.max,
  439. nativeMin = Math.min,
  440. nativeParseInt = context.parseInt,
  441. nativeRandom = Math.random;
  442. /** Used to lookup a built-in constructor by [[Class]] */
  443. var ctorByClass = {};
  444. ctorByClass[arrayClass] = Array;
  445. ctorByClass[boolClass] = Boolean;
  446. ctorByClass[dateClass] = Date;
  447. ctorByClass[funcClass] = Function;
  448. ctorByClass[objectClass] = Object;
  449. ctorByClass[numberClass] = Number;
  450. ctorByClass[regexpClass] = RegExp;
  451. ctorByClass[stringClass] = String;
  452. /*--------------------------------------------------------------------------*/
  453. /**
  454. * Creates a `lodash` object which wraps the given value to enable intuitive
  455. * method chaining.
  456. *
  457. * In addition to Lo-Dash methods, wrappers also have the following `Array` methods:
  458. * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`,
  459. * and `unshift`
  460. *
  461. * Chaining is supported in custom builds as long as the `value` method is
  462. * implicitly or explicitly included in the build.
  463. *
  464. * The chainable wrapper functions are:
  465. * `after`, `assign`, `bind`, `bindAll`, `bindKey`, `chain`, `compact`,
  466. * `compose`, `concat`, `countBy`, `create`, `createCallback`, `curry`,
  467. * `debounce`, `defaults`, `defer`, `delay`, `difference`, `filter`, `flatten`,
  468. * `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
  469. * `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
  470. * `invoke`, `keys`, `map`, `max`, `memoize`, `merge`, `min`, `object`, `omit`,
  471. * `once`, `pairs`, `partial`, `partialRight`, `pick`, `pluck`, `pull`, `push`,
  472. * `range`, `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`,
  473. * `sortBy`, `splice`, `tap`, `throttle`, `times`, `toArray`, `transform`,
  474. * `union`, `uniq`, `unshift`, `unzip`, `values`, `where`, `without`, `wrap`,
  475. * and `zip`
  476. *
  477. * The non-chainable wrapper functions are:
  478. * `clone`, `cloneDeep`, `contains`, `escape`, `every`, `find`, `findIndex`,
  479. * `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `has`, `identity`,
  480. * `indexOf`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
  481. * `isEmpty`, `isEqual`, `isFinite`, `isFunction`, `isNaN`, `isNull`, `isNumber`,
  482. * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, `join`,
  483. * `lastIndexOf`, `mixin`, `noConflict`, `parseInt`, `pop`, `random`, `reduce`,
  484. * `reduceRight`, `result`, `shift`, `size`, `some`, `sortedIndex`, `runInContext`,
  485. * `template`, `unescape`, `uniqueId`, and `value`
  486. *
  487. * The wrapper functions `first` and `last` return wrapped values when `n` is
  488. * provided, otherwise they return unwrapped values.
  489. *
  490. * Explicit chaining can be enabled by using the `_.chain` method.
  491. *
  492. * @name _
  493. * @constructor
  494. * @category Chaining
  495. * @param {*} value The value to wrap in a `lodash` instance.
  496. * @returns {Object} Returns a `lodash` instance.
  497. * @example
  498. *
  499. * var wrapped = _([1, 2, 3]);
  500. *
  501. * // returns an unwrapped value
  502. * wrapped.reduce(function(sum, num) {
  503. * return sum + num;
  504. * });
  505. * // => 6
  506. *
  507. * // returns a wrapped value
  508. * var squares = wrapped.map(function(num) {
  509. * return num * num;
  510. * });
  511. *
  512. * _.isArray(squares);
  513. * // => false
  514. *
  515. * _.isArray(squares.value());
  516. * // => true
  517. */
  518. function lodash(value) {
  519. // don't wrap if already wrapped, even if wrapped by a different `lodash` constructor
  520. return (value && typeof value == 'object' && !isArray(value) && hasOwnProperty.call(value, '__wrapped__'))
  521. ? value
  522. : new lodashWrapper(value);
  523. }
  524. /**
  525. * A fast path for creating `lodash` wrapper objects.
  526. *
  527. * @private
  528. * @param {*} value The value to wrap in a `lodash` instance.
  529. * @param {boolean} chainAll A flag to enable chaining for all methods
  530. * @returns {Object} Returns a `lodash` instance.
  531. */
  532. function lodashWrapper(value, chainAll) {
  533. this.__chain__ = !!chainAll;
  534. this.__wrapped__ = value;
  535. }
  536. // ensure `new lodashWrapper` is an instance of `lodash`
  537. lodashWrapper.prototype = lodash.prototype;
  538. /**
  539. * An object used to flag environments features.
  540. *
  541. * @static
  542. * @memberOf _
  543. * @type Object
  544. */
  545. var support = lodash.support = {};
  546. /**
  547. * Detect if functions can be decompiled by `Function#toString`
  548. * (all but PS3 and older Opera mobile browsers & avoided in Windows 8 apps).
  549. *
  550. * @memberOf _.support
  551. * @type boolean
  552. */
  553. support.funcDecomp = !isNative(context.WinRTError) && reThis.test(runInContext);
  554. /**
  555. * Detect if `Function#name` is supported (all but IE).
  556. *
  557. * @memberOf _.support
  558. * @type boolean
  559. */
  560. support.funcNames = typeof Function.name == 'string';
  561. /**
  562. * By default, the template delimiters used by Lo-Dash are similar to those in
  563. * embedded Ruby (ERB). Change the following template settings to use alternative
  564. * delimiters.
  565. *
  566. * @static
  567. * @memberOf _
  568. * @type Object
  569. */
  570. lodash.templateSettings = {
  571. /**
  572. * Used to detect `data` property values to be HTML-escaped.
  573. *
  574. * @memberOf _.templateSettings
  575. * @type RegExp
  576. */
  577. 'escape': /<%-([\s\S]+?)%>/g,
  578. /**
  579. * Used to detect code to be evaluated.
  580. *
  581. * @memberOf _.templateSettings
  582. * @type RegExp
  583. */
  584. 'evaluate': /<%([\s\S]+?)%>/g,
  585. /**
  586. * Used to detect `data` property values to inject.
  587. *
  588. * @memberOf _.templateSettings
  589. * @type RegExp
  590. */
  591. 'interpolate': reInterpolate,
  592. /**
  593. * Used to reference the data object in the template text.
  594. *
  595. * @memberOf _.templateSettings
  596. * @type string
  597. */
  598. 'variable': '',
  599. /**
  600. * Used to import variables into the compiled template.
  601. *
  602. * @memberOf _.templateSettings
  603. * @type Object
  604. */
  605. 'imports': {
  606. /**
  607. * A reference to the `lodash` function.
  608. *
  609. * @memberOf _.templateSettings.imports
  610. * @type Function
  611. */
  612. '_': lodash
  613. }
  614. };
  615. /*--------------------------------------------------------------------------*/
  616. /**
  617. * The base implementation of `_.bind` that creates the bound function and
  618. * sets its meta data.
  619. *
  620. * @private
  621. * @param {Array} bindData The bind data array.
  622. * @returns {Function} Returns the new bound function.
  623. */
  624. function baseBind(bindData) {
  625. var func = bindData[0],
  626. partialArgs = bindData[2],
  627. thisArg = bindData[4];
  628. function bound() {
  629. // `Function#bind` spec
  630. // http://es5.github.io/#x15.3.4.5
  631. if (partialArgs) {
  632. // avoid `arguments` object deoptimizations by using `slice` instead
  633. // of `Array.prototype.slice.call` and not assigning `arguments` to a
  634. // variable as a ternary expression
  635. var args = slice(partialArgs);
  636. push.apply(args, arguments);
  637. }
  638. // mimic the constructor's `return` behavior
  639. // http://es5.github.io/#x13.2.2
  640. if (this instanceof bound) {
  641. // ensure `new bound` is an instance of `func`
  642. var thisBinding = baseCreate(func.prototype),
  643. result = func.apply(thisBinding, args || arguments);
  644. return isObject(result) ? result : thisBinding;
  645. }
  646. return func.apply(thisArg, args || arguments);
  647. }
  648. setBindData(bound, bindData);
  649. return bound;
  650. }
  651. /**
  652. * The base implementation of `_.clone` without argument juggling or support
  653. * for `thisArg` binding.
  654. *
  655. * @private
  656. * @param {*} value The value to clone.
  657. * @param {boolean} [isDeep=false] Specify a deep clone.
  658. * @param {Function} [callback] The function to customize cloning values.
  659. * @param {Array} [stackA=[]] Tracks traversed source objects.
  660. * @param {Array} [stackB=[]] Associates clones with source counterparts.
  661. * @returns {*} Returns the cloned value.
  662. */
  663. function baseClone(value, isDeep, callback, stackA, stackB) {
  664. if (callback) {
  665. var result = callback(value);
  666. if (typeof result != 'undefined') {
  667. return result;
  668. }
  669. }
  670. // inspect [[Class]]
  671. var isObj = isObject(value);
  672. if (isObj) {
  673. var className = toString.call(value);
  674. if (!cloneableClasses[className]) {
  675. return value;
  676. }
  677. var ctor = ctorByClass[className];
  678. switch (className) {
  679. case boolClass:
  680. case dateClass:
  681. return new ctor(+value);
  682. case numberClass:
  683. case stringClass:
  684. return new ctor(value);
  685. case regexpClass:
  686. result = ctor(value.source, reFlags.exec(value));
  687. result.lastIndex = value.lastIndex;
  688. return result;
  689. }
  690. } else {
  691. return value;
  692. }
  693. var isArr = isArray(value);
  694. if (isDeep) {
  695. // check for circular references and return corresponding clone
  696. var initedStack = !stackA;
  697. stackA || (stackA = getArray());
  698. stackB || (stackB = getArray());
  699. var length = stackA.length;
  700. while (length--) {
  701. if (stackA[length] == value) {
  702. return stackB[length];
  703. }
  704. }
  705. result = isArr ? ctor(value.length) : {};
  706. }
  707. else {
  708. result = isArr ? slice(value) : assign({}, value);
  709. }
  710. // add array properties assigned by `RegExp#exec`
  711. if (isArr) {
  712. if (hasOwnProperty.call(value, 'index')) {
  713. result.index = value.index;
  714. }
  715. if (hasOwnProperty.call(value, 'input')) {
  716. result.input = value.input;
  717. }
  718. }
  719. // exit for shallow clone
  720. if (!isDeep) {
  721. return result;
  722. }
  723. // add the source value to the stack of traversed objects
  724. // and associate it with its clone
  725. stackA.push(value);
  726. stackB.push(result);
  727. // recursively populate clone (susceptible to call stack limits)
  728. (isArr ? forEach : forOwn)(value, function(objValue, key) {
  729. result[key] = baseClone(objValue, isDeep, callback, stackA, stackB);
  730. });
  731. if (initedStack) {
  732. releaseArray(stackA);
  733. releaseArray(stackB);
  734. }
  735. return result;
  736. }
  737. /**
  738. * The base implementation of `_.create` without support for assigning
  739. * properties to the created object.
  740. *
  741. * @private
  742. * @param {Object} prototype The object to inherit from.
  743. * @returns {Object} Returns the new object.
  744. */
  745. function baseCreate(prototype, properties) {
  746. return isObject(prototype) ? nativeCreate(prototype) : {};
  747. }
  748. // fallback for browsers without `Object.create`
  749. if (!nativeCreate) {
  750. baseCreate = (function() {
  751. function Object() {}
  752. return function(prototype) {
  753. if (isObject(prototype)) {
  754. Object.prototype = prototype;
  755. var result = new Object;
  756. Object.prototype = null;
  757. }
  758. return result || context.Object();
  759. };
  760. }());
  761. }
  762. /**
  763. * The base implementation of `_.createCallback` without support for creating
  764. * "_.pluck" or "_.where" style callbacks.
  765. *
  766. * @private
  767. * @param {*} [func=identity] The value to convert to a callback.
  768. * @param {*} [thisArg] The `this` binding of the created callback.
  769. * @param {number} [argCount] The number of arguments the callback accepts.
  770. * @returns {Function} Returns a callback function.
  771. */
  772. function baseCreateCallback(func, thisArg, argCount) {
  773. if (typeof func != 'function') {
  774. return identity;
  775. }
  776. // exit early for no `thisArg` or already bound by `Function#bind`
  777. if (typeof thisArg == 'undefined' || !('prototype' in func)) {
  778. return func;
  779. }
  780. var bindData = func.__bindData__;
  781. if (typeof bindData == 'undefined') {
  782. if (support.funcNames) {
  783. bindData = !func.name;
  784. }
  785. bindData = bindData || !support.funcDecomp;
  786. if (!bindData) {
  787. var source = fnToString.call(func);
  788. if (!support.funcNames) {
  789. bindData = !reFuncName.test(source);
  790. }
  791. if (!bindData) {
  792. // checks if `func` references the `this` keyword and stores the result
  793. bindData = reThis.test(source);
  794. setBindData(func, bindData);
  795. }
  796. }
  797. }
  798. // exit early if there are no `this` references or `func` is bound
  799. if (bindData === false || (bindData !== true && bindData[1] & 1)) {
  800. return func;
  801. }
  802. switch (argCount) {
  803. case 1: return function(value) {
  804. return func.call(thisArg, value);
  805. };
  806. case 2: return function(a, b) {
  807. return func.call(thisArg, a, b);
  808. };
  809. case 3: return function(value, index, collection) {
  810. return func.call(thisArg, value, index, collection);
  811. };
  812. case 4: return function(accumulator, value, index, collection) {
  813. return func.call(thisArg, accumulator, value, index, collection);
  814. };
  815. }
  816. return bind(func, thisArg);
  817. }
  818. /**
  819. * The base implementation of `createWrapper` that creates the wrapper and
  820. * sets its meta data.
  821. *
  822. * @private
  823. * @param {Array} bindData The bind data array.
  824. * @returns {Function} Returns the new function.
  825. */
  826. function baseCreateWrapper(bindData) {
  827. var func = bindData[0],
  828. bitmask = bindData[1],
  829. partialArgs = bindData[2],
  830. partialRightArgs = bindData[3],
  831. thisArg = bindData[4],
  832. arity = bindData[5];
  833. var isBind = bitmask & 1,
  834. isBindKey = bitmask & 2,
  835. isCurry = bitmask & 4,
  836. isCurryBound = bitmask & 8,
  837. key = func;
  838. function bound() {
  839. var thisBinding = isBind ? thisArg : this;
  840. if (partialArgs) {
  841. var args = slice(partialArgs);
  842. push.apply(args, arguments);
  843. }
  844. if (partialRightArgs || isCurry) {
  845. args || (args = slice(arguments));
  846. if (partialRightArgs) {
  847. push.apply(args, partialRightArgs);
  848. }
  849. if (isCurry && args.length < arity) {
  850. bitmask |= 16 & ~32;
  851. return baseCreateWrapper([func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity]);
  852. }
  853. }
  854. args || (args = arguments);
  855. if (isBindKey) {
  856. func = thisBinding[key];
  857. }
  858. if (this instanceof bound) {
  859. thisBinding = baseCreate(func.prototype);
  860. var result = func.apply(thisBinding, args);
  861. return isObject(result) ? result : thisBinding;
  862. }
  863. return func.apply(thisBinding, args);
  864. }
  865. setBindData(bound, bindData);
  866. return bound;
  867. }
  868. /**
  869. * The base implementation of `_.difference` that accepts a single array
  870. * of values to exclude.
  871. *
  872. * @private
  873. * @param {Array} array The array to process.
  874. * @param {Array} [values] The array of values to exclude.
  875. * @returns {Array} Returns a new array of filtered values.
  876. */
  877. function baseDifference(array, values) {
  878. var index = -1,
  879. indexOf = getIndexOf(),
  880. length = array ? array.length : 0,
  881. isLarge = length >= largeArraySize && indexOf === baseIndexOf,
  882. result = [];
  883. if (isLarge) {
  884. var cache = createCache(values);
  885. if (cache) {
  886. indexOf = cacheIndexOf;
  887. values = cache;
  888. } else {
  889. isLarge = false;
  890. }
  891. }
  892. while (++index < length) {
  893. var value = array[index];
  894. if (indexOf(values, value) < 0) {
  895. result.push(value);
  896. }
  897. }
  898. if (isLarge) {
  899. releaseObject(values);
  900. }
  901. return result;
  902. }
  903. /**
  904. * The base implementation of `_.flatten` without support for callback
  905. * shorthands or `thisArg` binding.
  906. *
  907. * @private
  908. * @param {Array} array The array to flatten.
  909. * @param {boolean} [isShallow=false] A flag to restrict flattening to a single level.
  910. * @param {boolean} [isStrict=false] A flag to restrict flattening to arrays and `arguments` objects.
  911. * @param {number} [fromIndex=0] The index to start from.
  912. * @returns {Array} Returns a new flattened array.
  913. */
  914. function baseFlatten(array, isShallow, isStrict, fromIndex) {
  915. var index = (fromIndex || 0) - 1,
  916. length = array ? array.length : 0,
  917. result = [];
  918. while (++index < length) {
  919. var value = array[index];
  920. if (value && typeof value == 'object' && typeof value.length == 'number'
  921. && (isArray(value) || isArguments(value))) {
  922. // recursively flatten arrays (susceptible to call stack limits)
  923. if (!isShallow) {
  924. value = baseFlatten(value, isShallow, isStrict);
  925. }
  926. var valIndex = -1,
  927. valLength = value.length,
  928. resIndex = result.length;
  929. result.length += valLength;
  930. while (++valIndex < valLength) {
  931. result[resIndex++] = value[valIndex];
  932. }
  933. } else if (!isStrict) {
  934. result.push(value);
  935. }
  936. }
  937. return result;
  938. }
  939. /**
  940. * The base implementation of `_.isEqual`, without support for `thisArg` binding,
  941. * that allows partial "_.where" style comparisons.
  942. *
  943. * @private
  944. * @param {*} a The value to compare.
  945. * @param {*} b The other value to compare.
  946. * @param {Function} [callback] The function to customize comparing values.
  947. * @param {Function} [isWhere=false] A flag to indicate performing partial comparisons.
  948. * @param {Array} [stackA=[]] Tracks traversed `a` objects.
  949. * @param {Array} [stackB=[]] Tracks traversed `b` objects.
  950. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  951. */
  952. function baseIsEqual(a, b, callback, isWhere, stackA, stackB) {
  953. // used to indicate that when comparing objects, `a` has at least the properties of `b`
  954. if (callback) {
  955. var result = callback(a, b);
  956. if (typeof result != 'undefined') {
  957. return !!result;
  958. }
  959. }
  960. // exit early for identical values
  961. if (a === b) {
  962. // treat `+0` vs. `-0` as not equal
  963. return a !== 0 || (1 / a == 1 / b);
  964. }
  965. var type = typeof a,
  966. otherType = typeof b;
  967. // exit early for unlike primitive values
  968. if (a === a &&
  969. !(a && objectTypes[type]) &&
  970. !(b && objectTypes[otherType])) {
  971. return false;
  972. }
  973. // exit early for `null` and `undefined` avoiding ES3's Function#call behavior
  974. // http://es5.github.io/#x15.3.4.4
  975. if (a == null || b == null) {
  976. return a === b;
  977. }
  978. // compare [[Class]] names
  979. var className = toString.call(a),
  980. otherClass = toString.call(b);
  981. if (className == argsClass) {
  982. className = objectClass;
  983. }
  984. if (otherClass == argsClass) {
  985. otherClass = objectClass;
  986. }
  987. if (className != otherClass) {
  988. return false;
  989. }
  990. switch (className) {
  991. case boolClass:
  992. case dateClass:
  993. // coerce dates and booleans to numbers, dates to milliseconds and booleans
  994. // to `1` or `0` treating invalid dates coerced to `NaN` as not equal
  995. return +a == +b;
  996. case numberClass:
  997. // treat `NaN` vs. `NaN` as equal
  998. return (a != +a)
  999. ? b != +b
  1000. // but treat `+0` vs. `-0` as not equal
  1001. : (a == 0 ? (1 / a == 1 / b) : a == +b);
  1002. case regexpClass:
  1003. case stringClass:
  1004. // coerce regexes to strings (http://es5.github.io/#x15.10.6.4)
  1005. // treat string primitives and their corresponding object instances as equal
  1006. return a == String(b);
  1007. }
  1008. var isArr = className == arrayClass;
  1009. if (!isArr) {
  1010. // unwrap any `lodash` wrapped values
  1011. var aWrapped = hasOwnProperty.call(a, '__wrapped__'),
  1012. bWrapped = hasOwnProperty.call(b, '__wrapped__');
  1013. if (aWrapped || bWrapped) {
  1014. return baseIsEqual(aWrapped ? a.__wrapped__ : a, bWrapped ? b.__wrapped__ : b, callback, isWhere, stackA, stackB);
  1015. }
  1016. // exit for functions and DOM nodes
  1017. if (className != objectClass) {
  1018. return false;
  1019. }
  1020. // in older versions of Opera, `arguments` objects have `Array` constructors
  1021. var ctorA = a.constructor,
  1022. ctorB = b.constructor;
  1023. // non `Object` object instances with different constructors are not equal
  1024. if (ctorA != ctorB &&
  1025. !(isFunction(ctorA) && ctorA instanceof ctorA && isFunction(ctorB) && ctorB instanceof ctorB) &&
  1026. ('constructor' in a && 'constructor' in b)
  1027. ) {
  1028. return false;
  1029. }
  1030. }
  1031. // assume cyclic structures are equal
  1032. // the algorithm for detecting cyclic structures is adapted from ES 5.1
  1033. // section 15.12.3, abstract operation `JO` (http://es5.github.io/#x15.12.3)
  1034. var initedStack = !stackA;
  1035. stackA || (stackA = getArray());
  1036. stackB || (stackB = getArray());
  1037. var length = stackA.length;
  1038. while (length--) {
  1039. if (stackA[length] == a) {
  1040. return stackB[length] == b;
  1041. }
  1042. }
  1043. var size = 0;
  1044. result = true;
  1045. // add `a` and `b` to the stack of traversed objects
  1046. stackA.push(a);
  1047. stackB.push(b);
  1048. // recursively compare objects and arrays (susceptible to call stack limits)
  1049. if (isArr) {
  1050. // compare lengths to determine if a deep comparison is necessary
  1051. length = a.length;
  1052. size = b.length;
  1053. result = size == length;
  1054. if (result || isWhere) {
  1055. // deep compare the contents, ignoring non-numeric properties
  1056. while (size--) {
  1057. var index = length,
  1058. value = b[size];
  1059. if (isWhere) {
  1060. while (index--) {
  1061. if ((result = baseIsEqual(a[index], value, callback, isWhere, stackA, stackB))) {
  1062. break;
  1063. }
  1064. }
  1065. } else if (!(result = baseIsEqual(a[size], value, callback, isWhere, stackA, stackB))) {
  1066. break;
  1067. }
  1068. }
  1069. }
  1070. }
  1071. else {
  1072. // deep compare objects using `forIn`, instead of `forOwn`, to avoid `Object.keys`
  1073. // which, in this case, is more costly
  1074. forIn(b, function(value, key, b) {
  1075. if (hasOwnProperty.call(b, key)) {
  1076. // count the number of properties.
  1077. size++;
  1078. // deep compare each property value.
  1079. return (result = hasOwnProperty.call(a, key) && baseIsEqual(a[key], value, callback, isWhere, stackA, stackB));
  1080. }
  1081. });
  1082. if (result && !isWhere) {
  1083. // ensure both objects have the same number of properties
  1084. forIn(a, function(value, key, a) {
  1085. if (hasOwnProperty.call(a, key)) {
  1086. // `size` will be `-1` if `a` has more properties than `b`
  1087. return (result = --size > -1);
  1088. }
  1089. });
  1090. }
  1091. }
  1092. stackA.pop();
  1093. stackB.pop();
  1094. if (initedStack) {
  1095. releaseArray(stackA);
  1096. releaseArray(stackB);
  1097. }
  1098. return result;
  1099. }
  1100. /**
  1101. * The base implementation of `_.merge` without argument juggling or support
  1102. * for `thisArg` binding.
  1103. *
  1104. * @private
  1105. * @param {Object} object The destination object.
  1106. * @param {Object} source The source object.
  1107. * @param {Function} [callback] The function to customize merging properties.
  1108. * @param {Array} [stackA=[]] Tracks traversed source objects.
  1109. * @param {Array} [stackB=[]] Associates values with source counterparts.
  1110. */
  1111. function baseMerge(object, source, callback, stackA, stackB) {
  1112. (isArray(source) ? forEach : forOwn)(source, function(source, key) {
  1113. var found,
  1114. isArr,
  1115. result = source,
  1116. value = object[key];
  1117. if (source && ((isArr = isArray(source)) || isPlainObject(source))) {
  1118. // avoid merging previously merged cyclic sources
  1119. var stackLength = stackA.length;
  1120. while (stackLength--) {
  1121. if ((found = stackA[stackLength] == source)) {
  1122. value = stackB[stackLength];
  1123. break;
  1124. }
  1125. }
  1126. if (!found) {
  1127. var isShallow;
  1128. if (callback) {
  1129. result = callback(value, source);
  1130. if ((isShallow = typeof result != 'undefined')) {
  1131. value = result;
  1132. }
  1133. }
  1134. if (!isShallow) {
  1135. value = isArr
  1136. ? (isArray(value) ? value : [])
  1137. : (isPlainObject(value) ? value : {});
  1138. }
  1139. // add `source` and associated `value` to the stack of traversed objects
  1140. stackA.push(source);
  1141. stackB.push(value);
  1142. // recursively merge objects and arrays (susceptible to call stack limits)
  1143. if (!isShallow) {
  1144. baseMerge(value, source, callback, stackA, stackB);
  1145. }
  1146. }
  1147. }
  1148. else {
  1149. if (callback) {
  1150. result = callback(value, source);
  1151. if (typeof result == 'undefined') {
  1152. result = source;
  1153. }
  1154. }
  1155. if (typeof result != 'undefined') {
  1156. value = result;
  1157. }
  1158. }
  1159. object[key] = value;
  1160. });
  1161. }
  1162. /**
  1163. * The base implementation of `_.random` without argument juggling or support
  1164. * for returning floating-point numbers.
  1165. *
  1166. * @private
  1167. * @param {number} min The minimum possible value.
  1168. * @param {number} max The maximum possible value.
  1169. * @returns {number} Returns a random number.
  1170. */
  1171. function baseRandom(min, max) {
  1172. return min + floor(nativeRandom() * (max - min + 1));
  1173. }
  1174. /**
  1175. * The base implementation of `_.uniq` without support for callback shorthands
  1176. * or `thisArg` binding.
  1177. *
  1178. * @private
  1179. * @param {Array} array The array to process.
  1180. * @param {boolean} [isSorted=false] A flag to indicate that `array` is sorted.
  1181. * @param {Function} [callback] The function called per iteration.
  1182. * @returns {Array} Returns a duplicate-value-free array.
  1183. */
  1184. function baseUniq(array, isSorted, callback) {
  1185. var index = -1,
  1186. indexOf = getIndexOf(),
  1187. length = array ? array.length : 0,
  1188. result = [];
  1189. var isLarge = !isSorted && length >= largeArraySize && indexOf === baseIndexOf,
  1190. seen = (callback || isLarge) ? getArray() : result;
  1191. if (isLarge) {
  1192. var cache = createCache(seen);
  1193. indexOf = cacheIndexOf;
  1194. seen = cache;
  1195. }
  1196. while (++index < length) {
  1197. var value = array[index],
  1198. computed = callback ? callback(value, index, array) : value;
  1199. if (isSorted
  1200. ? !index || seen[seen.length - 1] !== computed
  1201. : indexOf(seen, computed) < 0
  1202. ) {
  1203. if (callback || isLarge) {
  1204. seen.push(computed);
  1205. }
  1206. result.push(value);
  1207. }
  1208. }
  1209. if (isLarge) {
  1210. releaseArray(seen.array);
  1211. releaseObject(seen);
  1212. } else if (callback) {
  1213. releaseArray(seen);
  1214. }
  1215. return result;
  1216. }
  1217. /**
  1218. * Creates a function that aggregates a collection, creating an object composed
  1219. * of keys generated from the results of running each element of the collection
  1220. * through a callback. The given `setter` function sets the keys and values
  1221. * of the composed object.
  1222. *
  1223. * @private
  1224. * @param {Function} setter The setter function.
  1225. * @returns {Function} Returns the new aggregator function.
  1226. */
  1227. function createAggregator(setter) {
  1228. return function(collection, callback, thisArg) {
  1229. var result = {};
  1230. callback = lodash.createCallback(callback, thisArg, 3);
  1231. var index = -1,
  1232. length = collection ? collection.length : 0;
  1233. if (typeof length == 'number') {
  1234. while (++index < length) {
  1235. var value = collection[index];
  1236. setter(result, value, callback(value, index, collection), collection);
  1237. }
  1238. } else {
  1239. forOwn(collection, function(value, key, collection) {
  1240. setter(result, value, callback(value, key, collection), collection);
  1241. });
  1242. }
  1243. return result;
  1244. };
  1245. }
  1246. /**
  1247. * Creates a function that, when called, either curries or invokes `func`
  1248. * with an optional `this` binding and partially applied arguments.
  1249. *
  1250. * @private
  1251. * @param {Function|string} func The function or method name to reference.
  1252. * @param {number} bitmask The bitmask of method flags to compose.
  1253. * The bitmask may be composed of the following flags:
  1254. * 1 - `_.bind`
  1255. * 2 - `_.bindKey`
  1256. * 4 - `_.curry`
  1257. * 8 - `_.curry` (bound)
  1258. * 16 - `_.partial`
  1259. * 32 - `_.partialRight`
  1260. * @param {Array} [partialArgs] An array of arguments to prepend to those
  1261. * provided to the new function.
  1262. * @param {Array} [partialRightArgs] An array of arguments to append to those
  1263. * provided to the new function.
  1264. * @param {*} [thisArg] The `this` binding of `func`.
  1265. * @param {number} [arity] The arity of `func`.
  1266. * @returns {Function} Returns the new function.
  1267. */
  1268. function createWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) {
  1269. var isBind = bitmask & 1,
  1270. isBindKey = bitmask & 2,
  1271. isCurry = bitmask & 4,
  1272. isCurryBound = bitmask & 8,
  1273. isPartial = bitmask & 16,
  1274. isPartialRight = bitmask & 32;
  1275. if (!isBindKey && !isFunction(func)) {
  1276. throw new TypeError;
  1277. }
  1278. if (isPartial && !partialArgs.length) {
  1279. bitmask &= ~16;
  1280. isPartial = partialArgs = false;
  1281. }
  1282. if (isPartialRight && !partialRightArgs.length) {
  1283. bitmask &= ~32;
  1284. isPartialRight = partialRightArgs = false;
  1285. }
  1286. var bindData = func && func.__bindData__;
  1287. if (bindData && bindData !== true) {
  1288. // clone `bindData`
  1289. bindData = slice(bindData);
  1290. if (bindData[2]) {
  1291. bindData[2] = slice(bindData[2]);
  1292. }
  1293. if (bindData[3]) {
  1294. bindData[3] = slice(bindData[3]);
  1295. }
  1296. // set `thisBinding` is not previously bound
  1297. if (isBind && !(bindData[1] & 1)) {
  1298. bindData[4] = thisArg;
  1299. }
  1300. // set if previously bound but not currently (subsequent curried functions)
  1301. if (!isBind && bindData[1] & 1) {
  1302. bitmask |= 8;
  1303. }
  1304. // set curried arity if not yet set
  1305. if (isCurry && !(bindData[1] & 4)) {
  1306. bindData[5] = arity;
  1307. }
  1308. // append partial left arguments
  1309. if (isPartial) {
  1310. push.apply(bindData[2] || (bindData[2] = []), partialArgs);
  1311. }
  1312. // append partial right arguments
  1313. if (isPartialRight) {
  1314. unshift.apply(bindData[3] || (bindData[3] = []), partialRightArgs);
  1315. }
  1316. // merge flags
  1317. bindData[1] |= bitmask;
  1318. return createWrapper.apply(null, bindData);
  1319. }
  1320. // fast path for `_.bind`
  1321. var creater = (bitmask == 1 || bitmask === 17) ? baseBind : baseCreateWrapper;
  1322. return creater([func, bitmask, partialArgs, partialRightArgs, thisArg, arity]);
  1323. }
  1324. /**
  1325. * Used by `escape` to convert characters to HTML entities.
  1326. *
  1327. * @private
  1328. * @param {string} match The matched character to escape.
  1329. * @returns {string} Returns the escaped character.
  1330. */
  1331. function escapeHtmlChar(match) {
  1332. return htmlEscapes[match];
  1333. }
  1334. /**
  1335. * Gets the appropriate "indexOf" function. If the `_.indexOf` method is
  1336. * customized, this method returns the custom method, otherwise it returns
  1337. * the `baseIndexOf` function.
  1338. *
  1339. * @private
  1340. * @returns {Function} Returns the "indexOf" function.
  1341. */
  1342. function getIndexOf() {
  1343. var result = (result = lodash.indexOf) === indexOf ? baseIndexOf : result;
  1344. return result;
  1345. }
  1346. /**
  1347. * Checks if `value` is a native function.
  1348. *
  1349. * @private
  1350. * @param {*} value The value to check.
  1351. * @returns {boolean} Returns `true` if the `value` is a native function, else `false`.
  1352. */
  1353. function isNative(value) {
  1354. return typeof value == 'function' && reNative.test(value);
  1355. }
  1356. /**
  1357. * Sets `this` binding data on a given function.
  1358. *
  1359. * @private
  1360. * @param {Function} func The function to set data on.
  1361. * @param {Array} value The data array to set.
  1362. */
  1363. var setBindData = !defineProperty ? noop : function(func, value) {
  1364. descriptor.value = value;
  1365. defineProperty(func, '__bindData__', descriptor);
  1366. descriptor.value = null;
  1367. };
  1368. /**
  1369. * A fallback implementation of `isPlainObject` which checks if a given value
  1370. * is an object created by the `Object` constructor, assuming objects created
  1371. * by the `Object` constructor have no inherited enumerable properties and that
  1372. * there are no `Object.prototype` extensions.
  1373. *
  1374. * @private
  1375. * @param {*} value The value to check.
  1376. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  1377. */
  1378. function shimIsPlainObject(value) {
  1379. var ctor,
  1380. result;
  1381. // avoid non Object objects, `arguments` objects, and DOM elements
  1382. if (!(value && toString.call(value) == objectClass) ||
  1383. (ctor = value.constructor, isFunction(ctor) && !(ctor instanceof ctor))) {
  1384. return false;
  1385. }
  1386. // In most environments an object's own properties are iterated before
  1387. // its inherited properties. If the last iterated property is an object's
  1388. // own property then there are no inherited enumerable properties.
  1389. forIn(value, function(v