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

/files/lodash/2.3.0/lodash.js

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