lodash.default.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /**
  2. * @license
  3. * Lodash (Custom Build) <https://lodash.com/>
  4. * Build: `lodash modularize exports="es" -o ./`
  5. * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
  6. * Released under MIT license <https://lodash.com/license>
  7. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  8. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9. */
  10. import array from './array.js';
  11. import collection from './collection.js';
  12. import date from './date.js';
  13. import func from './function.js';
  14. import lang from './lang.js';
  15. import math from './math.js';
  16. import number from './number.js';
  17. import object from './object.js';
  18. import seq from './seq.js';
  19. import string from './string.js';
  20. import util from './util.js';
  21. import LazyWrapper from './_LazyWrapper.js';
  22. import LodashWrapper from './_LodashWrapper.js';
  23. import Symbol from './_Symbol.js';
  24. import arrayEach from './_arrayEach.js';
  25. import arrayPush from './_arrayPush.js';
  26. import baseForOwn from './_baseForOwn.js';
  27. import baseFunctions from './_baseFunctions.js';
  28. import baseInvoke from './_baseInvoke.js';
  29. import baseIteratee from './_baseIteratee.js';
  30. import baseRest from './_baseRest.js';
  31. import createHybrid from './_createHybrid.js';
  32. import identity from './identity.js';
  33. import isArray from './isArray.js';
  34. import isObject from './isObject.js';
  35. import keys from './keys.js';
  36. import last from './last.js';
  37. import lazyClone from './_lazyClone.js';
  38. import lazyReverse from './_lazyReverse.js';
  39. import lazyValue from './_lazyValue.js';
  40. import _mixin from './mixin.js';
  41. import negate from './negate.js';
  42. import realNames from './_realNames.js';
  43. import thru from './thru.js';
  44. import toInteger from './toInteger.js';
  45. import lodash from './wrapperLodash.js';
  46. /** Used as the semantic version number. */
  47. var VERSION = '4.17.21';
  48. /** Used to compose bitmasks for function metadata. */
  49. var WRAP_BIND_KEY_FLAG = 2;
  50. /** Used to indicate the type of lazy iteratees. */
  51. var LAZY_FILTER_FLAG = 1,
  52. LAZY_WHILE_FLAG = 3;
  53. /** Used as references for the maximum length and index of an array. */
  54. var MAX_ARRAY_LENGTH = 4294967295;
  55. /** Used for built-in method references. */
  56. var arrayProto = Array.prototype,
  57. objectProto = Object.prototype;
  58. /** Used to check objects for own properties. */
  59. var hasOwnProperty = objectProto.hasOwnProperty;
  60. /** Built-in value references. */
  61. var symIterator = Symbol ? Symbol.iterator : undefined;
  62. /* Built-in method references for those with the same name as other `lodash` methods. */
  63. var nativeMax = Math.max,
  64. nativeMin = Math.min;
  65. // wrap `_.mixin` so it works when provided only one argument
  66. var mixin = (function(func) {
  67. return function(object, source, options) {
  68. if (options == null) {
  69. var isObj = isObject(source),
  70. props = isObj && keys(source),
  71. methodNames = props && props.length && baseFunctions(source, props);
  72. if (!(methodNames ? methodNames.length : isObj)) {
  73. options = source;
  74. source = object;
  75. object = this;
  76. }
  77. }
  78. return func(object, source, options);
  79. };
  80. }(_mixin));
  81. // Add methods that return wrapped values in chain sequences.
  82. lodash.after = func.after;
  83. lodash.ary = func.ary;
  84. lodash.assign = object.assign;
  85. lodash.assignIn = object.assignIn;
  86. lodash.assignInWith = object.assignInWith;
  87. lodash.assignWith = object.assignWith;
  88. lodash.at = object.at;
  89. lodash.before = func.before;
  90. lodash.bind = func.bind;
  91. lodash.bindAll = util.bindAll;
  92. lodash.bindKey = func.bindKey;
  93. lodash.castArray = lang.castArray;
  94. lodash.chain = seq.chain;
  95. lodash.chunk = array.chunk;
  96. lodash.compact = array.compact;
  97. lodash.concat = array.concat;
  98. lodash.cond = util.cond;
  99. lodash.conforms = util.conforms;
  100. lodash.constant = util.constant;
  101. lodash.countBy = collection.countBy;
  102. lodash.create = object.create;
  103. lodash.curry = func.curry;
  104. lodash.curryRight = func.curryRight;
  105. lodash.debounce = func.debounce;
  106. lodash.defaults = object.defaults;
  107. lodash.defaultsDeep = object.defaultsDeep;
  108. lodash.defer = func.defer;
  109. lodash.delay = func.delay;
  110. lodash.difference = array.difference;
  111. lodash.differenceBy = array.differenceBy;
  112. lodash.differenceWith = array.differenceWith;
  113. lodash.drop = array.drop;
  114. lodash.dropRight = array.dropRight;
  115. lodash.dropRightWhile = array.dropRightWhile;
  116. lodash.dropWhile = array.dropWhile;
  117. lodash.fill = array.fill;
  118. lodash.filter = collection.filter;
  119. lodash.flatMap = collection.flatMap;
  120. lodash.flatMapDeep = collection.flatMapDeep;
  121. lodash.flatMapDepth = collection.flatMapDepth;
  122. lodash.flatten = array.flatten;
  123. lodash.flattenDeep = array.flattenDeep;
  124. lodash.flattenDepth = array.flattenDepth;
  125. lodash.flip = func.flip;
  126. lodash.flow = util.flow;
  127. lodash.flowRight = util.flowRight;
  128. lodash.fromPairs = array.fromPairs;
  129. lodash.functions = object.functions;
  130. lodash.functionsIn = object.functionsIn;
  131. lodash.groupBy = collection.groupBy;
  132. lodash.initial = array.initial;
  133. lodash.intersection = array.intersection;
  134. lodash.intersectionBy = array.intersectionBy;
  135. lodash.intersectionWith = array.intersectionWith;
  136. lodash.invert = object.invert;
  137. lodash.invertBy = object.invertBy;
  138. lodash.invokeMap = collection.invokeMap;
  139. lodash.iteratee = util.iteratee;
  140. lodash.keyBy = collection.keyBy;
  141. lodash.keys = keys;
  142. lodash.keysIn = object.keysIn;
  143. lodash.map = collection.map;
  144. lodash.mapKeys = object.mapKeys;
  145. lodash.mapValues = object.mapValues;
  146. lodash.matches = util.matches;
  147. lodash.matchesProperty = util.matchesProperty;
  148. lodash.memoize = func.memoize;
  149. lodash.merge = object.merge;
  150. lodash.mergeWith = object.mergeWith;
  151. lodash.method = util.method;
  152. lodash.methodOf = util.methodOf;
  153. lodash.mixin = mixin;
  154. lodash.negate = negate;
  155. lodash.nthArg = util.nthArg;
  156. lodash.omit = object.omit;
  157. lodash.omitBy = object.omitBy;
  158. lodash.once = func.once;
  159. lodash.orderBy = collection.orderBy;
  160. lodash.over = util.over;
  161. lodash.overArgs = func.overArgs;
  162. lodash.overEvery = util.overEvery;
  163. lodash.overSome = util.overSome;
  164. lodash.partial = func.partial;
  165. lodash.partialRight = func.partialRight;
  166. lodash.partition = collection.partition;
  167. lodash.pick = object.pick;
  168. lodash.pickBy = object.pickBy;
  169. lodash.property = util.property;
  170. lodash.propertyOf = util.propertyOf;
  171. lodash.pull = array.pull;
  172. lodash.pullAll = array.pullAll;
  173. lodash.pullAllBy = array.pullAllBy;
  174. lodash.pullAllWith = array.pullAllWith;
  175. lodash.pullAt = array.pullAt;
  176. lodash.range = util.range;
  177. lodash.rangeRight = util.rangeRight;
  178. lodash.rearg = func.rearg;
  179. lodash.reject = collection.reject;
  180. lodash.remove = array.remove;
  181. lodash.rest = func.rest;
  182. lodash.reverse = array.reverse;
  183. lodash.sampleSize = collection.sampleSize;
  184. lodash.set = object.set;
  185. lodash.setWith = object.setWith;
  186. lodash.shuffle = collection.shuffle;
  187. lodash.slice = array.slice;
  188. lodash.sortBy = collection.sortBy;
  189. lodash.sortedUniq = array.sortedUniq;
  190. lodash.sortedUniqBy = array.sortedUniqBy;
  191. lodash.split = string.split;
  192. lodash.spread = func.spread;
  193. lodash.tail = array.tail;
  194. lodash.take = array.take;
  195. lodash.takeRight = array.takeRight;
  196. lodash.takeRightWhile = array.takeRightWhile;
  197. lodash.takeWhile = array.takeWhile;
  198. lodash.tap = seq.tap;
  199. lodash.throttle = func.throttle;
  200. lodash.thru = thru;
  201. lodash.toArray = lang.toArray;
  202. lodash.toPairs = object.toPairs;
  203. lodash.toPairsIn = object.toPairsIn;
  204. lodash.toPath = util.toPath;
  205. lodash.toPlainObject = lang.toPlainObject;
  206. lodash.transform = object.transform;
  207. lodash.unary = func.unary;
  208. lodash.union = array.union;
  209. lodash.unionBy = array.unionBy;
  210. lodash.unionWith = array.unionWith;
  211. lodash.uniq = array.uniq;
  212. lodash.uniqBy = array.uniqBy;
  213. lodash.uniqWith = array.uniqWith;
  214. lodash.unset = object.unset;
  215. lodash.unzip = array.unzip;
  216. lodash.unzipWith = array.unzipWith;
  217. lodash.update = object.update;
  218. lodash.updateWith = object.updateWith;
  219. lodash.values = object.values;
  220. lodash.valuesIn = object.valuesIn;
  221. lodash.without = array.without;
  222. lodash.words = string.words;
  223. lodash.wrap = func.wrap;
  224. lodash.xor = array.xor;
  225. lodash.xorBy = array.xorBy;
  226. lodash.xorWith = array.xorWith;
  227. lodash.zip = array.zip;
  228. lodash.zipObject = array.zipObject;
  229. lodash.zipObjectDeep = array.zipObjectDeep;
  230. lodash.zipWith = array.zipWith;
  231. // Add aliases.
  232. lodash.entries = object.toPairs;
  233. lodash.entriesIn = object.toPairsIn;
  234. lodash.extend = object.assignIn;
  235. lodash.extendWith = object.assignInWith;
  236. // Add methods to `lodash.prototype`.
  237. mixin(lodash, lodash);
  238. // Add methods that return unwrapped values in chain sequences.
  239. lodash.add = math.add;
  240. lodash.attempt = util.attempt;
  241. lodash.camelCase = string.camelCase;
  242. lodash.capitalize = string.capitalize;
  243. lodash.ceil = math.ceil;
  244. lodash.clamp = number.clamp;
  245. lodash.clone = lang.clone;
  246. lodash.cloneDeep = lang.cloneDeep;
  247. lodash.cloneDeepWith = lang.cloneDeepWith;
  248. lodash.cloneWith = lang.cloneWith;
  249. lodash.conformsTo = lang.conformsTo;
  250. lodash.deburr = string.deburr;
  251. lodash.defaultTo = util.defaultTo;
  252. lodash.divide = math.divide;
  253. lodash.endsWith = string.endsWith;
  254. lodash.eq = lang.eq;
  255. lodash.escape = string.escape;
  256. lodash.escapeRegExp = string.escapeRegExp;
  257. lodash.every = collection.every;
  258. lodash.find = collection.find;
  259. lodash.findIndex = array.findIndex;
  260. lodash.findKey = object.findKey;
  261. lodash.findLast = collection.findLast;
  262. lodash.findLastIndex = array.findLastIndex;
  263. lodash.findLastKey = object.findLastKey;
  264. lodash.floor = math.floor;
  265. lodash.forEach = collection.forEach;
  266. lodash.forEachRight = collection.forEachRight;
  267. lodash.forIn = object.forIn;
  268. lodash.forInRight = object.forInRight;
  269. lodash.forOwn = object.forOwn;
  270. lodash.forOwnRight = object.forOwnRight;
  271. lodash.get = object.get;
  272. lodash.gt = lang.gt;
  273. lodash.gte = lang.gte;
  274. lodash.has = object.has;
  275. lodash.hasIn = object.hasIn;
  276. lodash.head = array.head;
  277. lodash.identity = identity;
  278. lodash.includes = collection.includes;
  279. lodash.indexOf = array.indexOf;
  280. lodash.inRange = number.inRange;
  281. lodash.invoke = object.invoke;
  282. lodash.isArguments = lang.isArguments;
  283. lodash.isArray = isArray;
  284. lodash.isArrayBuffer = lang.isArrayBuffer;
  285. lodash.isArrayLike = lang.isArrayLike;
  286. lodash.isArrayLikeObject = lang.isArrayLikeObject;
  287. lodash.isBoolean = lang.isBoolean;
  288. lodash.isBuffer = lang.isBuffer;
  289. lodash.isDate = lang.isDate;
  290. lodash.isElement = lang.isElement;
  291. lodash.isEmpty = lang.isEmpty;
  292. lodash.isEqual = lang.isEqual;
  293. lodash.isEqualWith = lang.isEqualWith;
  294. lodash.isError = lang.isError;
  295. lodash.isFinite = lang.isFinite;
  296. lodash.isFunction = lang.isFunction;
  297. lodash.isInteger = lang.isInteger;
  298. lodash.isLength = lang.isLength;
  299. lodash.isMap = lang.isMap;
  300. lodash.isMatch = lang.isMatch;
  301. lodash.isMatchWith = lang.isMatchWith;
  302. lodash.isNaN = lang.isNaN;
  303. lodash.isNative = lang.isNative;
  304. lodash.isNil = lang.isNil;
  305. lodash.isNull = lang.isNull;
  306. lodash.isNumber = lang.isNumber;
  307. lodash.isObject = isObject;
  308. lodash.isObjectLike = lang.isObjectLike;
  309. lodash.isPlainObject = lang.isPlainObject;
  310. lodash.isRegExp = lang.isRegExp;
  311. lodash.isSafeInteger = lang.isSafeInteger;
  312. lodash.isSet = lang.isSet;
  313. lodash.isString = lang.isString;
  314. lodash.isSymbol = lang.isSymbol;
  315. lodash.isTypedArray = lang.isTypedArray;
  316. lodash.isUndefined = lang.isUndefined;
  317. lodash.isWeakMap = lang.isWeakMap;
  318. lodash.isWeakSet = lang.isWeakSet;
  319. lodash.join = array.join;
  320. lodash.kebabCase = string.kebabCase;
  321. lodash.last = last;
  322. lodash.lastIndexOf = array.lastIndexOf;
  323. lodash.lowerCase = string.lowerCase;
  324. lodash.lowerFirst = string.lowerFirst;
  325. lodash.lt = lang.lt;
  326. lodash.lte = lang.lte;
  327. lodash.max = math.max;
  328. lodash.maxBy = math.maxBy;
  329. lodash.mean = math.mean;
  330. lodash.meanBy = math.meanBy;
  331. lodash.min = math.min;
  332. lodash.minBy = math.minBy;
  333. lodash.stubArray = util.stubArray;
  334. lodash.stubFalse = util.stubFalse;
  335. lodash.stubObject = util.stubObject;
  336. lodash.stubString = util.stubString;
  337. lodash.stubTrue = util.stubTrue;
  338. lodash.multiply = math.multiply;
  339. lodash.nth = array.nth;
  340. lodash.noop = util.noop;
  341. lodash.now = date.now;
  342. lodash.pad = string.pad;
  343. lodash.padEnd = string.padEnd;
  344. lodash.padStart = string.padStart;
  345. lodash.parseInt = string.parseInt;
  346. lodash.random = number.random;
  347. lodash.reduce = collection.reduce;
  348. lodash.reduceRight = collection.reduceRight;
  349. lodash.repeat = string.repeat;
  350. lodash.replace = string.replace;
  351. lodash.result = object.result;
  352. lodash.round = math.round;
  353. lodash.sample = collection.sample;
  354. lodash.size = collection.size;
  355. lodash.snakeCase = string.snakeCase;
  356. lodash.some = collection.some;
  357. lodash.sortedIndex = array.sortedIndex;
  358. lodash.sortedIndexBy = array.sortedIndexBy;
  359. lodash.sortedIndexOf = array.sortedIndexOf;
  360. lodash.sortedLastIndex = array.sortedLastIndex;
  361. lodash.sortedLastIndexBy = array.sortedLastIndexBy;
  362. lodash.sortedLastIndexOf = array.sortedLastIndexOf;
  363. lodash.startCase = string.startCase;
  364. lodash.startsWith = string.startsWith;
  365. lodash.subtract = math.subtract;
  366. lodash.sum = math.sum;
  367. lodash.sumBy = math.sumBy;
  368. lodash.template = string.template;
  369. lodash.times = util.times;
  370. lodash.toFinite = lang.toFinite;
  371. lodash.toInteger = toInteger;
  372. lodash.toLength = lang.toLength;
  373. lodash.toLower = string.toLower;
  374. lodash.toNumber = lang.toNumber;
  375. lodash.toSafeInteger = lang.toSafeInteger;
  376. lodash.toString = lang.toString;
  377. lodash.toUpper = string.toUpper;
  378. lodash.trim = string.trim;
  379. lodash.trimEnd = string.trimEnd;
  380. lodash.trimStart = string.trimStart;
  381. lodash.truncate = string.truncate;
  382. lodash.unescape = string.unescape;
  383. lodash.uniqueId = util.uniqueId;
  384. lodash.upperCase = string.upperCase;
  385. lodash.upperFirst = string.upperFirst;
  386. // Add aliases.
  387. lodash.each = collection.forEach;
  388. lodash.eachRight = collection.forEachRight;
  389. lodash.first = array.head;
  390. mixin(lodash, (function() {
  391. var source = {};
  392. baseForOwn(lodash, function(func, methodName) {
  393. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  394. source[methodName] = func;
  395. }
  396. });
  397. return source;
  398. }()), { 'chain': false });
  399. /**
  400. * The semantic version number.
  401. *
  402. * @static
  403. * @memberOf _
  404. * @type {string}
  405. */
  406. lodash.VERSION = VERSION;
  407. (lodash.templateSettings = string.templateSettings).imports._ = lodash;
  408. // Assign default placeholders.
  409. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  410. lodash[methodName].placeholder = lodash;
  411. });
  412. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  413. arrayEach(['drop', 'take'], function(methodName, index) {
  414. LazyWrapper.prototype[methodName] = function(n) {
  415. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  416. var result = (this.__filtered__ && !index)
  417. ? new LazyWrapper(this)
  418. : this.clone();
  419. if (result.__filtered__) {
  420. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  421. } else {
  422. result.__views__.push({
  423. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  424. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  425. });
  426. }
  427. return result;
  428. };
  429. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  430. return this.reverse()[methodName](n).reverse();
  431. };
  432. });
  433. // Add `LazyWrapper` methods that accept an `iteratee` value.
  434. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  435. var type = index + 1,
  436. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  437. LazyWrapper.prototype[methodName] = function(iteratee) {
  438. var result = this.clone();
  439. result.__iteratees__.push({
  440. 'iteratee': baseIteratee(iteratee, 3),
  441. 'type': type
  442. });
  443. result.__filtered__ = result.__filtered__ || isFilter;
  444. return result;
  445. };
  446. });
  447. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  448. arrayEach(['head', 'last'], function(methodName, index) {
  449. var takeName = 'take' + (index ? 'Right' : '');
  450. LazyWrapper.prototype[methodName] = function() {
  451. return this[takeName](1).value()[0];
  452. };
  453. });
  454. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  455. arrayEach(['initial', 'tail'], function(methodName, index) {
  456. var dropName = 'drop' + (index ? '' : 'Right');
  457. LazyWrapper.prototype[methodName] = function() {
  458. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  459. };
  460. });
  461. LazyWrapper.prototype.compact = function() {
  462. return this.filter(identity);
  463. };
  464. LazyWrapper.prototype.find = function(predicate) {
  465. return this.filter(predicate).head();
  466. };
  467. LazyWrapper.prototype.findLast = function(predicate) {
  468. return this.reverse().find(predicate);
  469. };
  470. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  471. if (typeof path == 'function') {
  472. return new LazyWrapper(this);
  473. }
  474. return this.map(function(value) {
  475. return baseInvoke(value, path, args);
  476. });
  477. });
  478. LazyWrapper.prototype.reject = function(predicate) {
  479. return this.filter(negate(baseIteratee(predicate)));
  480. };
  481. LazyWrapper.prototype.slice = function(start, end) {
  482. start = toInteger(start);
  483. var result = this;
  484. if (result.__filtered__ && (start > 0 || end < 0)) {
  485. return new LazyWrapper(result);
  486. }
  487. if (start < 0) {
  488. result = result.takeRight(-start);
  489. } else if (start) {
  490. result = result.drop(start);
  491. }
  492. if (end !== undefined) {
  493. end = toInteger(end);
  494. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  495. }
  496. return result;
  497. };
  498. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  499. return this.reverse().takeWhile(predicate).reverse();
  500. };
  501. LazyWrapper.prototype.toArray = function() {
  502. return this.take(MAX_ARRAY_LENGTH);
  503. };
  504. // Add `LazyWrapper` methods to `lodash.prototype`.
  505. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  506. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  507. isTaker = /^(?:head|last)$/.test(methodName),
  508. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  509. retUnwrapped = isTaker || /^find/.test(methodName);
  510. if (!lodashFunc) {
  511. return;
  512. }
  513. lodash.prototype[methodName] = function() {
  514. var value = this.__wrapped__,
  515. args = isTaker ? [1] : arguments,
  516. isLazy = value instanceof LazyWrapper,
  517. iteratee = args[0],
  518. useLazy = isLazy || isArray(value);
  519. var interceptor = function(value) {
  520. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  521. return (isTaker && chainAll) ? result[0] : result;
  522. };
  523. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  524. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  525. isLazy = useLazy = false;
  526. }
  527. var chainAll = this.__chain__,
  528. isHybrid = !!this.__actions__.length,
  529. isUnwrapped = retUnwrapped && !chainAll,
  530. onlyLazy = isLazy && !isHybrid;
  531. if (!retUnwrapped && useLazy) {
  532. value = onlyLazy ? value : new LazyWrapper(this);
  533. var result = func.apply(value, args);
  534. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  535. return new LodashWrapper(result, chainAll);
  536. }
  537. if (isUnwrapped && onlyLazy) {
  538. return func.apply(this, args);
  539. }
  540. result = this.thru(interceptor);
  541. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  542. };
  543. });
  544. // Add `Array` methods to `lodash.prototype`.
  545. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  546. var func = arrayProto[methodName],
  547. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  548. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  549. lodash.prototype[methodName] = function() {
  550. var args = arguments;
  551. if (retUnwrapped && !this.__chain__) {
  552. var value = this.value();
  553. return func.apply(isArray(value) ? value : [], args);
  554. }
  555. return this[chainName](function(value) {
  556. return func.apply(isArray(value) ? value : [], args);
  557. });
  558. };
  559. });
  560. // Map minified method names to their real names.
  561. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  562. var lodashFunc = lodash[methodName];
  563. if (lodashFunc) {
  564. var key = lodashFunc.name + '';
  565. if (!hasOwnProperty.call(realNames, key)) {
  566. realNames[key] = [];
  567. }
  568. realNames[key].push({ 'name': methodName, 'func': lodashFunc });
  569. }
  570. });
  571. realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
  572. 'name': 'wrapper',
  573. 'func': undefined
  574. }];
  575. // Add methods to `LazyWrapper`.
  576. LazyWrapper.prototype.clone = lazyClone;
  577. LazyWrapper.prototype.reverse = lazyReverse;
  578. LazyWrapper.prototype.value = lazyValue;
  579. // Add chain sequence methods to the `lodash` wrapper.
  580. lodash.prototype.at = seq.at;
  581. lodash.prototype.chain = seq.wrapperChain;
  582. lodash.prototype.commit = seq.commit;
  583. lodash.prototype.next = seq.next;
  584. lodash.prototype.plant = seq.plant;
  585. lodash.prototype.reverse = seq.reverse;
  586. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = seq.value;
  587. // Add lazy aliases.
  588. lodash.prototype.first = lodash.prototype.head;
  589. if (symIterator) {
  590. lodash.prototype[symIterator] = seq.toIterator;
  591. }
  592. export default lodash;