Compare commits

...

2 Commits

Author SHA1 Message Date
Benjamin Tan
11eb817cdf Bump to v4.17.21 2021-02-20 23:33:13 +08:00
Benjamin Tan
42e2585e5f Bump to v4.17.20. 2020-12-20 14:19:47 +08:00
23 changed files with 145 additions and 39 deletions

View File

@@ -1,4 +1,4 @@
# lodash-es v4.17.15
# lodash-es v4.17.21
The [Lodash](https://lodash.com/) library exported as [ES](http://www.ecma-international.org/ecma-262/6.0/) modules.
@@ -7,4 +7,4 @@ Generated using [lodash-cli](https://www.npmjs.com/package/lodash-cli):
$ lodash modularize exports=es -o ./
```
See the [package source](https://github.com/lodash/lodash/tree/4.17.15-es) for more details.
See the [package source](https://github.com/lodash/lodash/tree/4.17.21-es) for more details.

View File

@@ -19,6 +19,7 @@ import isMap from './isMap.js';
import isObject from './isObject.js';
import isSet from './isSet.js';
import keys from './keys.js';
import keysIn from './keysIn.js';
/** Used to compose bitmasks for cloning. */
var CLONE_DEEP_FLAG = 1,

View File

@@ -1,10 +1,12 @@
import arrayMap from './_arrayMap.js';
import baseGet from './_baseGet.js';
import baseIteratee from './_baseIteratee.js';
import baseMap from './_baseMap.js';
import baseSortBy from './_baseSortBy.js';
import baseUnary from './_baseUnary.js';
import compareMultiple from './_compareMultiple.js';
import identity from './identity.js';
import isArray from './isArray.js';
/**
* The base implementation of `_.orderBy` without param guards.
@@ -16,8 +18,21 @@ import identity from './identity.js';
* @returns {Array} Returns the new sorted array.
*/
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;
iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(baseIteratee));
iteratees = arrayMap(iteratees, baseUnary(baseIteratee));
var result = baseMap(collection, function(value, key, collection) {
var criteria = arrayMap(iteratees, function(iteratee) {

View File

@@ -29,6 +29,10 @@ function baseSet(object, path, value, customizer) {
var key = toKey(path[index]),
newValue = value;
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
return object;
}
if (index != lastIndex) {
var objValue = nested[key];
newValue = customizer ? customizer(objValue, key, nested) : undefined;

View File

@@ -22,11 +22,14 @@ var nativeFloor = Math.floor,
* into `array`.
*/
function baseSortedIndexBy(array, value, iteratee, retHighest) {
value = iteratee(value);
var low = 0,
high = array == null ? 0 : array.length,
valIsNaN = value !== value,
high = array == null ? 0 : array.length;
if (high === 0) {
return 0;
}
value = iteratee(value);
var valIsNaN = value !== value,
valIsNull = value === null,
valIsSymbol = isSymbol(value),
valIsUndefined = value === undefined;

19
_baseTrim.js Normal file
View File

@@ -0,0 +1,19 @@
import trimmedEndIndex from './_trimmedEndIndex.js';
/** Used to match leading whitespace. */
var reTrimStart = /^\s+/;
/**
* 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;
}
export default baseTrim;

View File

@@ -27,10 +27,11 @@ function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
return false;
}
// Assume cyclic values are equal.
var stacked = stack.get(array);
if (stacked && stack.get(other)) {
return stacked == other;
// Check that cyclic values are equal.
var arrStacked = stack.get(array);
var othStacked = stack.get(other);
if (arrStacked && othStacked) {
return arrStacked == other && othStacked == array;
}
var index = -1,
result = true,

View File

@@ -39,10 +39,11 @@ function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
return false;
}
}
// Assume cyclic values are equal.
var stacked = stack.get(object);
if (stacked && stack.get(other)) {
return stacked == other;
// Check that cyclic values are equal.
var objStacked = stack.get(object);
var othStacked = stack.get(other);
if (objStacked && othStacked) {
return objStacked == other && othStacked == object;
}
var result = true;
stack.set(object, other);

19
_trimmedEndIndex.js Normal file
View File

@@ -0,0 +1,19 @@
/** Used to match a single whitespace character. */
var reWhitespace = /\s/;
/**
* 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;
}
export default trimmedEndIndex;

View File

@@ -39,6 +39,10 @@ import isArray from './isArray.js';
* // The `_.property` iteratee shorthand.
* _.filter(users, 'active');
* // => 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) {
var func = isArray(collection) ? arrayFilter : baseFilter;

View File

@@ -45,7 +45,7 @@ import toInteger from './toInteger.js';
import lodash from './wrapperLodash.js';
/** Used as the semantic version number. */
var VERSION = '4.17.15';
var VERSION = '4.17.21';
/** Used to compose bitmasks for function metadata. */
var WRAP_BIND_KEY_FLAG = 2;

View File

@@ -16,6 +16,9 @@ var CLONE_DEEP_FLAG = 1;
* values against any array or object value, respectively. See `_.isEqual`
* for a list of supported value comparisons.
*
* **Note:** Multiple values can be checked by combining several matchers
* using `_.overSome`
*
* @static
* @memberOf _
* @since 3.0.0
@@ -31,6 +34,10 @@ var CLONE_DEEP_FLAG = 1;
*
* _.filter(objects, _.matches({ 'a': 4, '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) {
return baseMatches(baseClone(source, CLONE_DEEP_FLAG));

View File

@@ -13,6 +13,9 @@ var CLONE_DEEP_FLAG = 1;
* `srcValue` values against any array or object value, respectively. See
* `_.isEqual` for a list of supported value comparisons.
*
* **Note:** Multiple values can be checked by combining several matchers
* using `_.overSome`
*
* @static
* @memberOf _
* @since 3.2.0
@@ -29,6 +32,10 @@ var CLONE_DEEP_FLAG = 1;
*
* _.find(objects, _.matchesProperty('a', 4));
* // => { '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) {
return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));

View File

@@ -5,6 +5,10 @@ import createOver from './_createOver.js';
* Creates a function that checks if **all** of the `predicates` return
* 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
* @memberOf _
* @since 4.0.0

View File

@@ -5,6 +5,10 @@ import createOver from './_createOver.js';
* Creates a function that checks if **any** of the `predicates` return
* 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
* @memberOf _
* @since 4.0.0
@@ -24,6 +28,9 @@ import createOver from './_createOver.js';
*
* func(NaN);
* // => false
*
* var matchesFunc = _.overSome([{ 'a': 1 }, { 'a': 2 }])
* var matchesPropertyFunc = _.overSome([['a', 1], ['a', 2]])
*/
var overSome = createOver(arraySome);

View File

@@ -1,12 +1,13 @@
{
"name": "lodash-es",
"version": "4.17.15",
"version": "4.17.21",
"description": "Lodash exported as ES modules.",
"keywords": "es6, modules, stdlib, util",
"homepage": "https://lodash.com/custom-builds",
"bugs": "https://github.com/lodash/lodash-cli/issues",
"repository": "lodash/lodash",
"license": "MIT",
"type": "module",
"jsnext:main": "lodash.js",
"main": "lodash.js",
"module": "lodash.js",

View File

@@ -1,7 +1,7 @@
import root from './_root.js';
import toString from './toString.js';
/** Used to match leading and trailing whitespace. */
/** Used to match leading whitespace. */
var reTrimStart = /^\s+/;
/* Built-in method references for those with the same name as other `lodash` methods. */

View File

@@ -22,15 +22,15 @@ import isIterateeCall from './_isIterateeCall.js';
* var users = [
* { 'user': 'fred', 'age': 48 },
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 40 },
* { 'user': 'fred', 'age': 30 },
* { 'user': 'barney', 'age': 34 }
* ];
*
* _.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']);
* // => 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) {
if (collection == null) {

View File

@@ -10,11 +10,26 @@ import reInterpolate from './_reInterpolate.js';
import templateSettings from './templateSettings.js';
import toString from './toString.js';
/** Error message constants. */
var INVALID_TEMPL_VAR_ERROR_TEXT = 'Invalid `variable` option passed into `_.template`';
/** Used to match empty string literals in compiled template source. */
var reEmptyStringLeading = /\b__p \+= '';/g,
reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/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
* [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
@@ -169,11 +184,11 @@ function template(string, options, guard) {
// Use a sourceURL for easier debugging.
// 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.
// A newline wouldn't be a valid sourceURL anyway, and it'd enable code injection.
// to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in
// and escape the comment, thus injecting code that gets evaled.
var sourceURL = hasOwnProperty.call(options, 'sourceURL')
? ('//# sourceURL=' +
(options.sourceURL + '').replace(/[\r\n]/g, ' ') +
(options.sourceURL + '').replace(/\s/g, ' ') +
'\n')
: '';
@@ -206,12 +221,16 @@ function template(string, options, guard) {
// 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.
// 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;
if (!variable) {
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.
source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
.replace(reEmptyStringMiddle, '$1')

View File

@@ -1,12 +1,10 @@
import baseTrim from './_baseTrim.js';
import isObject from './isObject.js';
import isSymbol from './isSymbol.js';
/** Used as references for various `Number` constants. */
var NAN = 0 / 0;
/** Used to match leading and trailing whitespace. */
var reTrim = /^\s+|\s+$/g;
/** Used to detect bad signed hexadecimal string values. */
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
@@ -56,7 +54,7 @@ function toNumber(value) {
if (typeof value != 'string') {
return value === 0 ? value : +value;
}
value = value.replace(reTrim, '');
value = baseTrim(value);
var isBinary = reIsBinary.test(value);
return (isBinary || reIsOctal.test(value))
? freeParseInt(value.slice(2), isBinary ? 2 : 8)

View File

@@ -1,13 +1,11 @@
import baseToString from './_baseToString.js';
import baseTrim from './_baseTrim.js';
import castSlice from './_castSlice.js';
import charsEndIndex from './_charsEndIndex.js';
import charsStartIndex from './_charsStartIndex.js';
import stringToArray from './_stringToArray.js';
import toString from './toString.js';
/** Used to match leading and trailing whitespace. */
var reTrim = /^\s+|\s+$/g;
/**
* Removes leading and trailing whitespace or specified characters from `string`.
*
@@ -33,7 +31,7 @@ var reTrim = /^\s+|\s+$/g;
function trim(string, chars, guard) {
string = toString(string);
if (string && (guard || chars === undefined)) {
return string.replace(reTrim, '');
return baseTrim(string);
}
if (!string || !(chars = baseToString(chars))) {
return string;

View File

@@ -3,9 +3,7 @@ import castSlice from './_castSlice.js';
import charsEndIndex from './_charsEndIndex.js';
import stringToArray from './_stringToArray.js';
import toString from './toString.js';
/** Used to match leading and trailing whitespace. */
var reTrimEnd = /\s+$/;
import trimmedEndIndex from './_trimmedEndIndex.js';
/**
* Removes trailing whitespace or specified characters from `string`.
@@ -29,7 +27,7 @@ var reTrimEnd = /\s+$/;
function trimEnd(string, chars, guard) {
string = toString(string);
if (string && (guard || chars === undefined)) {
return string.replace(reTrimEnd, '');
return string.slice(0, trimmedEndIndex(string) + 1);
}
if (!string || !(chars = baseToString(chars))) {
return string;

View File

@@ -4,7 +4,7 @@ import charsStartIndex from './_charsStartIndex.js';
import stringToArray from './_stringToArray.js';
import toString from './toString.js';
/** Used to match leading and trailing whitespace. */
/** Used to match leading whitespace. */
var reTrimStart = /^\s+/;
/**