lodash.js 라이브러리 버전 업데이트 및 코드 정리
This commit is contained in:
@@ -12,14 +12,15 @@
|
|||||||
var undefined;
|
var undefined;
|
||||||
|
|
||||||
/** Used as the semantic version number. */
|
/** Used as the semantic version number. */
|
||||||
var VERSION = '4.17.15';
|
var VERSION = '4.17.21';
|
||||||
|
|
||||||
/** Used as the size to enable large array optimizations. */
|
/** Used as the size to enable large array optimizations. */
|
||||||
var LARGE_ARRAY_SIZE = 200;
|
var LARGE_ARRAY_SIZE = 200;
|
||||||
|
|
||||||
/** Error message constants. */
|
/** Error message constants. */
|
||||||
var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
|
var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
|
||||||
FUNC_ERROR_TEXT = 'Expected a function';
|
FUNC_ERROR_TEXT = 'Expected a function',
|
||||||
|
INVALID_TEMPL_VAR_ERROR_TEXT = 'Invalid `variable` option passed into `_.template`';
|
||||||
|
|
||||||
/** Used to stand-in for `undefined` hash values. */
|
/** Used to stand-in for `undefined` hash values. */
|
||||||
var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
||||||
@@ -152,10 +153,11 @@
|
|||||||
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
|
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
|
||||||
reHasRegExpChar = RegExp(reRegExpChar.source);
|
reHasRegExpChar = RegExp(reRegExpChar.source);
|
||||||
|
|
||||||
/** Used to match leading and trailing whitespace. */
|
/** Used to match leading whitespace. */
|
||||||
var reTrim = /^\s+|\s+$/g,
|
var reTrimStart = /^\s+/;
|
||||||
reTrimStart = /^\s+/,
|
|
||||||
reTrimEnd = /\s+$/;
|
/** Used to match a single whitespace character. */
|
||||||
|
var reWhitespace = /\s/;
|
||||||
|
|
||||||
/** Used to match wrap detail comments. */
|
/** Used to match wrap detail comments. */
|
||||||
var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
|
var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
|
||||||
@@ -165,6 +167,18 @@
|
|||||||
/** Used to match words composed of alphanumeric characters. */
|
/** Used to match words composed of alphanumeric characters. */
|
||||||
var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
|
var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to validate the `validate` option in `_.template` variable.
|
||||||
|
*
|
||||||
|
* Forbids characters which could potentially change the meaning of the function argument definition:
|
||||||
|
* - "()," (modification of function parameters)
|
||||||
|
* - "=" (default value)
|
||||||
|
* - "[]{}" (destructuring of function parameters)
|
||||||
|
* - "/" (beginning of a comment)
|
||||||
|
* - whitespace
|
||||||
|
*/
|
||||||
|
var reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/;
|
||||||
|
|
||||||
/** Used to match backslashes in property paths. */
|
/** Used to match backslashes in property paths. */
|
||||||
var reEscapeChar = /\\(\\)?/g;
|
var reEscapeChar = /\\(\\)?/g;
|
||||||
|
|
||||||
@@ -993,6 +1007,19 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base implementation of `_.trim`.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {string} string The string to trim.
|
||||||
|
* @returns {string} Returns the trimmed string.
|
||||||
|
*/
|
||||||
|
function baseTrim(string) {
|
||||||
|
return string
|
||||||
|
? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
|
||||||
|
: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `_.unary` without support for storing metadata.
|
* The base implementation of `_.unary` without support for storing metadata.
|
||||||
*
|
*
|
||||||
@@ -1326,6 +1353,21 @@
|
|||||||
: asciiToArray(string);
|
: asciiToArray(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
|
||||||
|
* character of `string`.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {string} string The string to inspect.
|
||||||
|
* @returns {number} Returns the index of the last non-whitespace character.
|
||||||
|
*/
|
||||||
|
function trimmedEndIndex(string) {
|
||||||
|
var index = string.length;
|
||||||
|
|
||||||
|
while (index-- && reWhitespace.test(string.charAt(index))) {}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by `_.unescape` to convert HTML entities to characters.
|
* Used by `_.unescape` to convert HTML entities to characters.
|
||||||
*
|
*
|
||||||
@@ -3719,8 +3761,21 @@
|
|||||||
* @returns {Array} Returns the new sorted array.
|
* @returns {Array} Returns the new sorted array.
|
||||||
*/
|
*/
|
||||||
function baseOrderBy(collection, iteratees, orders) {
|
function baseOrderBy(collection, iteratees, orders) {
|
||||||
|
if (iteratees.length) {
|
||||||
|
iteratees = arrayMap(iteratees, function(iteratee) {
|
||||||
|
if (isArray(iteratee)) {
|
||||||
|
return function(value) {
|
||||||
|
return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return iteratee;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
iteratees = [identity];
|
||||||
|
}
|
||||||
|
|
||||||
var index = -1;
|
var index = -1;
|
||||||
iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
|
iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
|
||||||
|
|
||||||
var result = baseMap(collection, function(value, key, collection) {
|
var result = baseMap(collection, function(value, key, collection) {
|
||||||
var criteria = arrayMap(iteratees, function(iteratee) {
|
var criteria = arrayMap(iteratees, function(iteratee) {
|
||||||
@@ -3977,6 +4032,10 @@
|
|||||||
var key = toKey(path[index]),
|
var key = toKey(path[index]),
|
||||||
newValue = value;
|
newValue = value;
|
||||||
|
|
||||||
|
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
if (index != lastIndex) {
|
if (index != lastIndex) {
|
||||||
var objValue = nested[key];
|
var objValue = nested[key];
|
||||||
newValue = customizer ? customizer(objValue, key, nested) : undefined;
|
newValue = customizer ? customizer(objValue, key, nested) : undefined;
|
||||||
@@ -4129,11 +4188,14 @@
|
|||||||
* into `array`.
|
* into `array`.
|
||||||
*/
|
*/
|
||||||
function baseSortedIndexBy(array, value, iteratee, retHighest) {
|
function baseSortedIndexBy(array, value, iteratee, retHighest) {
|
||||||
value = iteratee(value);
|
|
||||||
|
|
||||||
var low = 0,
|
var low = 0,
|
||||||
high = array == null ? 0 : array.length,
|
high = array == null ? 0 : array.length;
|
||||||
valIsNaN = value !== value,
|
if (high === 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = iteratee(value);
|
||||||
|
var valIsNaN = value !== value,
|
||||||
valIsNull = value === null,
|
valIsNull = value === null,
|
||||||
valIsSymbol = isSymbol(value),
|
valIsSymbol = isSymbol(value),
|
||||||
valIsUndefined = value === undefined;
|
valIsUndefined = value === undefined;
|
||||||
@@ -5618,10 +5680,11 @@
|
|||||||
if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
|
if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Assume cyclic values are equal.
|
// Check that cyclic values are equal.
|
||||||
var stacked = stack.get(array);
|
var arrStacked = stack.get(array);
|
||||||
if (stacked && stack.get(other)) {
|
var othStacked = stack.get(other);
|
||||||
return stacked == other;
|
if (arrStacked && othStacked) {
|
||||||
|
return arrStacked == other && othStacked == array;
|
||||||
}
|
}
|
||||||
var index = -1,
|
var index = -1,
|
||||||
result = true,
|
result = true,
|
||||||
@@ -5783,10 +5846,11 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Assume cyclic values are equal.
|
// Check that cyclic values are equal.
|
||||||
var stacked = stack.get(object);
|
var objStacked = stack.get(object);
|
||||||
if (stacked && stack.get(other)) {
|
var othStacked = stack.get(other);
|
||||||
return stacked == other;
|
if (objStacked && othStacked) {
|
||||||
|
return objStacked == other && othStacked == object;
|
||||||
}
|
}
|
||||||
var result = true;
|
var result = true;
|
||||||
stack.set(object, other);
|
stack.set(object, other);
|
||||||
@@ -9167,6 +9231,10 @@
|
|||||||
* // The `_.property` iteratee shorthand.
|
* // The `_.property` iteratee shorthand.
|
||||||
* _.filter(users, 'active');
|
* _.filter(users, 'active');
|
||||||
* // => objects for ['barney']
|
* // => objects for ['barney']
|
||||||
|
*
|
||||||
|
* // Combining several predicates using `_.overEvery` or `_.overSome`.
|
||||||
|
* _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]]));
|
||||||
|
* // => objects for ['fred', 'barney']
|
||||||
*/
|
*/
|
||||||
function filter(collection, predicate) {
|
function filter(collection, predicate) {
|
||||||
var func = isArray(collection) ? arrayFilter : baseFilter;
|
var func = isArray(collection) ? arrayFilter : baseFilter;
|
||||||
@@ -9916,15 +9984,15 @@
|
|||||||
* var users = [
|
* var users = [
|
||||||
* { 'user': 'fred', 'age': 48 },
|
* { 'user': 'fred', 'age': 48 },
|
||||||
* { 'user': 'barney', 'age': 36 },
|
* { 'user': 'barney', 'age': 36 },
|
||||||
* { 'user': 'fred', 'age': 40 },
|
* { 'user': 'fred', 'age': 30 },
|
||||||
* { 'user': 'barney', 'age': 34 }
|
* { 'user': 'barney', 'age': 34 }
|
||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* _.sortBy(users, [function(o) { return o.user; }]);
|
* _.sortBy(users, [function(o) { return o.user; }]);
|
||||||
* // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
|
* // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]]
|
||||||
*
|
*
|
||||||
* _.sortBy(users, ['user', 'age']);
|
* _.sortBy(users, ['user', 'age']);
|
||||||
* // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
|
* // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]]
|
||||||
*/
|
*/
|
||||||
var sortBy = baseRest(function(collection, iteratees) {
|
var sortBy = baseRest(function(collection, iteratees) {
|
||||||
if (collection == null) {
|
if (collection == null) {
|
||||||
@@ -12468,7 +12536,7 @@
|
|||||||
if (typeof value != 'string') {
|
if (typeof value != 'string') {
|
||||||
return value === 0 ? value : +value;
|
return value === 0 ? value : +value;
|
||||||
}
|
}
|
||||||
value = value.replace(reTrim, '');
|
value = baseTrim(value);
|
||||||
var isBinary = reIsBinary.test(value);
|
var isBinary = reIsBinary.test(value);
|
||||||
return (isBinary || reIsOctal.test(value))
|
return (isBinary || reIsOctal.test(value))
|
||||||
? freeParseInt(value.slice(2), isBinary ? 2 : 8)
|
? freeParseInt(value.slice(2), isBinary ? 2 : 8)
|
||||||
@@ -14799,11 +14867,11 @@
|
|||||||
|
|
||||||
// Use a sourceURL for easier debugging.
|
// Use a sourceURL for easier debugging.
|
||||||
// The sourceURL gets injected into the source that's eval-ed, so be careful
|
// The sourceURL gets injected into the source that's eval-ed, so be careful
|
||||||
// with lookup (in case of e.g. prototype pollution), and strip newlines if any.
|
// to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in
|
||||||
// A newline wouldn't be a valid sourceURL anyway, and it'd enable code injection.
|
// and escape the comment, thus injecting code that gets evaled.
|
||||||
var sourceURL = '//# sourceURL=' +
|
var sourceURL = '//# sourceURL=' +
|
||||||
(hasOwnProperty.call(options, 'sourceURL')
|
(hasOwnProperty.call(options, 'sourceURL')
|
||||||
? (options.sourceURL + '').replace(/[\r\n]/g, ' ')
|
? (options.sourceURL + '').replace(/\s/g, ' ')
|
||||||
: ('lodash.templateSources[' + (++templateCounter) + ']')
|
: ('lodash.templateSources[' + (++templateCounter) + ']')
|
||||||
) + '\n';
|
) + '\n';
|
||||||
|
|
||||||
@@ -14836,12 +14904,16 @@
|
|||||||
|
|
||||||
// If `variable` is not specified wrap a with-statement around the generated
|
// If `variable` is not specified wrap a with-statement around the generated
|
||||||
// code to add the data object to the top of the scope chain.
|
// code to add the data object to the top of the scope chain.
|
||||||
// Like with sourceURL, we take care to not check the option's prototype,
|
|
||||||
// as this configuration is a code injection vector.
|
|
||||||
var variable = hasOwnProperty.call(options, 'variable') && options.variable;
|
var variable = hasOwnProperty.call(options, 'variable') && options.variable;
|
||||||
if (!variable) {
|
if (!variable) {
|
||||||
source = 'with (obj) {\n' + source + '\n}\n';
|
source = 'with (obj) {\n' + source + '\n}\n';
|
||||||
}
|
}
|
||||||
|
// Throw an error if a forbidden character was found in `variable`, to prevent
|
||||||
|
// potential command injection attacks.
|
||||||
|
else if (reForbiddenIdentifierChars.test(variable)) {
|
||||||
|
throw new Error(INVALID_TEMPL_VAR_ERROR_TEXT);
|
||||||
|
}
|
||||||
|
|
||||||
// Cleanup code by stripping empty strings.
|
// Cleanup code by stripping empty strings.
|
||||||
source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
|
source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
|
||||||
.replace(reEmptyStringMiddle, '$1')
|
.replace(reEmptyStringMiddle, '$1')
|
||||||
@@ -14955,7 +15027,7 @@
|
|||||||
function trim(string, chars, guard) {
|
function trim(string, chars, guard) {
|
||||||
string = toString(string);
|
string = toString(string);
|
||||||
if (string && (guard || chars === undefined)) {
|
if (string && (guard || chars === undefined)) {
|
||||||
return string.replace(reTrim, '');
|
return baseTrim(string);
|
||||||
}
|
}
|
||||||
if (!string || !(chars = baseToString(chars))) {
|
if (!string || !(chars = baseToString(chars))) {
|
||||||
return string;
|
return string;
|
||||||
@@ -14990,7 +15062,7 @@
|
|||||||
function trimEnd(string, chars, guard) {
|
function trimEnd(string, chars, guard) {
|
||||||
string = toString(string);
|
string = toString(string);
|
||||||
if (string && (guard || chars === undefined)) {
|
if (string && (guard || chars === undefined)) {
|
||||||
return string.replace(reTrimEnd, '');
|
return string.slice(0, trimmedEndIndex(string) + 1);
|
||||||
}
|
}
|
||||||
if (!string || !(chars = baseToString(chars))) {
|
if (!string || !(chars = baseToString(chars))) {
|
||||||
return string;
|
return string;
|
||||||
@@ -15544,6 +15616,9 @@
|
|||||||
* values against any array or object value, respectively. See `_.isEqual`
|
* values against any array or object value, respectively. See `_.isEqual`
|
||||||
* for a list of supported value comparisons.
|
* for a list of supported value comparisons.
|
||||||
*
|
*
|
||||||
|
* **Note:** Multiple values can be checked by combining several matchers
|
||||||
|
* using `_.overSome`
|
||||||
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
@@ -15559,6 +15634,10 @@
|
|||||||
*
|
*
|
||||||
* _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
|
* _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
|
||||||
* // => [{ 'a': 4, 'b': 5, 'c': 6 }]
|
* // => [{ 'a': 4, 'b': 5, 'c': 6 }]
|
||||||
|
*
|
||||||
|
* // Checking for several possible values
|
||||||
|
* _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
|
||||||
|
* // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
|
||||||
*/
|
*/
|
||||||
function matches(source) {
|
function matches(source) {
|
||||||
return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
|
return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
|
||||||
@@ -15573,6 +15652,9 @@
|
|||||||
* `srcValue` values against any array or object value, respectively. See
|
* `srcValue` values against any array or object value, respectively. See
|
||||||
* `_.isEqual` for a list of supported value comparisons.
|
* `_.isEqual` for a list of supported value comparisons.
|
||||||
*
|
*
|
||||||
|
* **Note:** Multiple values can be checked by combining several matchers
|
||||||
|
* using `_.overSome`
|
||||||
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
@@ -15589,6 +15671,10 @@
|
|||||||
*
|
*
|
||||||
* _.find(objects, _.matchesProperty('a', 4));
|
* _.find(objects, _.matchesProperty('a', 4));
|
||||||
* // => { 'a': 4, 'b': 5, 'c': 6 }
|
* // => { 'a': 4, 'b': 5, 'c': 6 }
|
||||||
|
*
|
||||||
|
* // Checking for several possible values
|
||||||
|
* _.filter(objects, _.overSome([_.matchesProperty('a', 1), _.matchesProperty('a', 4)]));
|
||||||
|
* // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
|
||||||
*/
|
*/
|
||||||
function matchesProperty(path, srcValue) {
|
function matchesProperty(path, srcValue) {
|
||||||
return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
|
return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
|
||||||
@@ -15812,6 +15898,10 @@
|
|||||||
* Creates a function that checks if **all** of the `predicates` return
|
* Creates a function that checks if **all** of the `predicates` return
|
||||||
* truthy when invoked with the arguments it receives.
|
* truthy when invoked with the arguments it receives.
|
||||||
*
|
*
|
||||||
|
* Following shorthands are possible for providing predicates.
|
||||||
|
* Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
|
||||||
|
* Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
|
||||||
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @since 4.0.0
|
* @since 4.0.0
|
||||||
@@ -15838,6 +15928,10 @@
|
|||||||
* Creates a function that checks if **any** of the `predicates` return
|
* Creates a function that checks if **any** of the `predicates` return
|
||||||
* truthy when invoked with the arguments it receives.
|
* truthy when invoked with the arguments it receives.
|
||||||
*
|
*
|
||||||
|
* Following shorthands are possible for providing predicates.
|
||||||
|
* Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
|
||||||
|
* Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
|
||||||
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @since 4.0.0
|
* @since 4.0.0
|
||||||
@@ -15857,6 +15951,9 @@
|
|||||||
*
|
*
|
||||||
* func(NaN);
|
* func(NaN);
|
||||||
* // => false
|
* // => false
|
||||||
|
*
|
||||||
|
* var matchesFunc = _.overSome([{ 'a': 1 }, { 'a': 2 }])
|
||||||
|
* var matchesPropertyFunc = _.overSome([['a', 1], ['a', 2]])
|
||||||
*/
|
*/
|
||||||
var overSome = createOver(arraySome);
|
var overSome = createOver(arraySome);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user