UNPKG

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