es-toolkit 1.50.0 → 1.51.0-dev.2065
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +82 -0
- package/NOTICE +39 -0
- package/README.md +2 -2
- package/bigint.d.ts +1 -0
- package/bigint.js +1 -0
- package/dist/_internal/NonPlainObject.d.mts +8 -0
- package/dist/_internal/NonPlainObject.d.ts +8 -0
- package/dist/_internal/bigIntRangeLength.js +19 -0
- package/dist/_internal/bigIntRangeLength.mjs +19 -0
- package/dist/_internal/isMergeableValue.js +17 -0
- package/dist/_internal/isMergeableValue.mjs +17 -0
- package/dist/_internal/isUnsafeProperty.js +7 -4
- package/dist/_internal/isUnsafeProperty.mjs +7 -4
- package/dist/_internal/isUnsafeToWriteProperty.js +22 -0
- package/dist/_internal/isUnsafeToWriteProperty.mjs +22 -0
- package/dist/array/at.d.mts +1 -1
- package/dist/array/at.d.ts +1 -1
- package/dist/array/filterAsync.js +1 -1
- package/dist/array/filterAsync.mjs +1 -1
- package/dist/array/flatMapAsync.js +1 -1
- package/dist/array/flatMapAsync.mjs +1 -1
- package/dist/array/forEachAsync.js +1 -1
- package/dist/array/forEachAsync.mjs +1 -1
- package/dist/array/index.js +1 -1
- package/dist/array/index.mjs +1 -1
- package/dist/array/limitAsync.d.mts +4 -28
- package/dist/array/limitAsync.d.ts +4 -28
- package/dist/array/limitAsync.js +2 -39
- package/dist/array/limitAsync.mjs +3 -39
- package/dist/array/mapAsync.js +1 -1
- package/dist/array/mapAsync.mjs +1 -1
- package/dist/array/orderBy.d.mts +1 -1
- package/dist/array/orderBy.d.ts +1 -1
- package/dist/array/pullAt.d.mts +1 -1
- package/dist/array/pullAt.d.ts +1 -1
- package/dist/array/pullAt.js +1 -1
- package/dist/array/pullAt.mjs +1 -1
- package/dist/array/sortBy.d.mts +1 -1
- package/dist/array/sortBy.d.ts +1 -1
- package/dist/array/unzip.d.mts +3 -0
- package/dist/array/unzip.d.ts +3 -0
- package/dist/array/unzip.js +3 -0
- package/dist/array/unzip.mjs +3 -0
- package/dist/bigint/clamp.d.mts +37 -0
- package/dist/bigint/clamp.d.ts +37 -0
- package/dist/bigint/clamp.js +16 -0
- package/dist/bigint/clamp.mjs +16 -0
- package/dist/bigint/inRange.d.mts +37 -0
- package/dist/bigint/inRange.d.ts +37 -0
- package/dist/bigint/inRange.js +20 -0
- package/dist/bigint/inRange.mjs +20 -0
- package/dist/bigint/index.d.mts +14 -0
- package/dist/bigint/index.d.ts +14 -0
- package/dist/bigint/index.js +27 -0
- package/dist/bigint/index.mjs +14 -0
- package/dist/bigint/max.d.mts +21 -0
- package/dist/bigint/max.d.ts +21 -0
- package/dist/bigint/max.js +26 -0
- package/dist/bigint/max.mjs +26 -0
- package/dist/bigint/maxBy.d.mts +21 -0
- package/dist/bigint/maxBy.d.ts +21 -0
- package/dist/bigint/maxBy.js +34 -0
- package/dist/bigint/maxBy.mjs +34 -0
- package/dist/bigint/median.d.mts +22 -0
- package/dist/bigint/median.d.ts +22 -0
- package/dist/bigint/median.js +28 -0
- package/dist/bigint/median.mjs +28 -0
- package/dist/bigint/medianBy.d.mts +21 -0
- package/dist/bigint/medianBy.d.ts +21 -0
- package/dist/bigint/medianBy.js +24 -0
- package/dist/bigint/medianBy.mjs +24 -0
- package/dist/bigint/min.d.mts +18 -0
- package/dist/bigint/min.d.ts +18 -0
- package/dist/bigint/min.js +23 -0
- package/dist/bigint/min.mjs +23 -0
- package/dist/bigint/minBy.d.mts +21 -0
- package/dist/bigint/minBy.d.ts +21 -0
- package/dist/bigint/minBy.js +34 -0
- package/dist/bigint/minBy.mjs +34 -0
- package/dist/bigint/percentile.d.mts +23 -0
- package/dist/bigint/percentile.d.ts +23 -0
- package/dist/bigint/percentile.js +31 -0
- package/dist/bigint/percentile.mjs +31 -0
- package/dist/bigint/range.d.mts +45 -0
- package/dist/bigint/range.d.ts +45 -0
- package/dist/bigint/range.js +24 -0
- package/dist/bigint/range.mjs +24 -0
- package/dist/bigint/rangeRight.d.mts +43 -0
- package/dist/bigint/rangeRight.d.ts +43 -0
- package/dist/bigint/rangeRight.js +25 -0
- package/dist/bigint/rangeRight.mjs +25 -0
- package/dist/bigint/sum.d.mts +18 -0
- package/dist/bigint/sum.d.ts +18 -0
- package/dist/bigint/sum.js +22 -0
- package/dist/bigint/sum.mjs +22 -0
- package/dist/bigint/sumBy.d.mts +20 -0
- package/dist/bigint/sumBy.d.ts +20 -0
- package/dist/bigint/sumBy.js +24 -0
- package/dist/bigint/sumBy.mjs +24 -0
- package/dist/browser.global.js +6 -3
- package/dist/compat/_internal/normalizeZero.js +13 -0
- package/dist/compat/_internal/normalizeZero.mjs +13 -0
- package/dist/compat/_internal/toKey.js +1 -1
- package/dist/compat/_internal/toKey.mjs +1 -1
- package/dist/compat/_internal/unicodeSize.js +45 -0
- package/dist/compat/_internal/unicodeSize.mjs +45 -0
- package/dist/compat/array/chunk.js +1 -0
- package/dist/compat/array/chunk.mjs +1 -0
- package/dist/compat/array/difference.js +2 -1
- package/dist/compat/array/difference.mjs +2 -1
- package/dist/compat/array/differenceBy.js +3 -2
- package/dist/compat/array/differenceBy.mjs +3 -2
- package/dist/compat/array/drop.d.mts +1 -1
- package/dist/compat/array/drop.d.ts +1 -1
- package/dist/compat/array/dropRight.d.mts +2 -3
- package/dist/compat/array/dropRight.d.ts +2 -3
- package/dist/compat/array/dropRight.js +4 -4
- package/dist/compat/array/dropRight.mjs +4 -4
- package/dist/compat/array/every.js +9 -9
- package/dist/compat/array/every.mjs +9 -9
- package/dist/compat/array/fill.js +8 -2
- package/dist/compat/array/fill.mjs +8 -2
- package/dist/compat/array/find.js +14 -13
- package/dist/compat/array/find.mjs +14 -13
- package/dist/compat/array/findIndex.js +3 -19
- package/dist/compat/array/findIndex.mjs +3 -19
- package/dist/compat/array/findLast.js +3 -3
- package/dist/compat/array/findLast.mjs +3 -3
- package/dist/compat/array/flatMap.js +3 -8
- package/dist/compat/array/flatMap.mjs +3 -7
- package/dist/compat/array/flatMapDepth.js +1 -1
- package/dist/compat/array/flatMapDepth.mjs +1 -1
- package/dist/compat/array/forEach.js +1 -1
- package/dist/compat/array/forEach.mjs +1 -1
- package/dist/compat/array/includes.js +13 -13
- package/dist/compat/array/includes.mjs +13 -13
- package/dist/compat/array/indexOf.js +2 -1
- package/dist/compat/array/indexOf.mjs +2 -1
- package/dist/compat/array/intersection.js +3 -2
- package/dist/compat/array/intersection.mjs +3 -2
- package/dist/compat/array/intersectionBy.js +7 -11
- package/dist/compat/array/intersectionBy.mjs +7 -11
- package/dist/compat/array/intersectionWith.js +6 -18
- package/dist/compat/array/intersectionWith.mjs +6 -18
- package/dist/compat/array/last.js +1 -1
- package/dist/compat/array/last.mjs +1 -1
- package/dist/compat/array/lastIndexOf.js +3 -1
- package/dist/compat/array/lastIndexOf.mjs +3 -1
- package/dist/compat/array/map.js +3 -3
- package/dist/compat/array/map.mjs +3 -3
- package/dist/compat/array/orderBy.js +8 -6
- package/dist/compat/array/orderBy.mjs +8 -6
- package/dist/compat/array/partition.js +6 -6
- package/dist/compat/array/partition.mjs +6 -6
- package/dist/compat/array/pull.js +1 -1
- package/dist/compat/array/pull.mjs +1 -1
- package/dist/compat/array/pullAll.js +2 -0
- package/dist/compat/array/pullAll.mjs +2 -0
- package/dist/compat/array/remove.js +8 -4
- package/dist/compat/array/remove.mjs +8 -4
- package/dist/compat/array/reverse.js +1 -1
- package/dist/compat/array/reverse.mjs +1 -1
- package/dist/compat/array/sampleSize.js +2 -1
- package/dist/compat/array/sampleSize.mjs +2 -1
- package/dist/compat/array/size.js +2 -1
- package/dist/compat/array/size.mjs +2 -1
- package/dist/compat/array/some.js +2 -1
- package/dist/compat/array/some.mjs +2 -1
- package/dist/compat/array/takeRightWhile.js +2 -2
- package/dist/compat/array/takeRightWhile.mjs +2 -2
- package/dist/compat/array/takeWhile.js +2 -2
- package/dist/compat/array/takeWhile.mjs +2 -2
- package/dist/compat/array/unionBy.js +2 -1
- package/dist/compat/array/unionBy.mjs +2 -1
- package/dist/compat/array/uniqBy.js +4 -3
- package/dist/compat/array/uniqBy.mjs +4 -3
- package/dist/compat/array/unzip.d.mts +3 -0
- package/dist/compat/array/unzip.d.ts +3 -0
- package/dist/compat/array/unzip.js +3 -0
- package/dist/compat/array/unzip.mjs +3 -0
- package/dist/compat/array/unzipWith.js +1 -1
- package/dist/compat/array/unzipWith.mjs +1 -1
- package/dist/compat/array/zipObject.js +2 -0
- package/dist/compat/array/zipObject.mjs +2 -0
- package/dist/compat/compat.d.mts +3 -3
- package/dist/compat/compat.d.ts +3 -3
- package/dist/compat/compat.js +8 -4
- package/dist/compat/compat.mjs +8 -4
- package/dist/compat/function/curry.d.mts +1 -1
- package/dist/compat/function/curry.d.ts +1 -1
- package/dist/compat/function/flowRight.d.mts +1 -1
- package/dist/compat/function/flowRight.d.ts +1 -1
- package/dist/compat/function/partial.d.mts +1 -1
- package/dist/compat/function/partial.d.ts +1 -1
- package/dist/compat/function/rest.d.mts +1 -1
- package/dist/compat/function/rest.d.ts +1 -1
- package/dist/compat/function/rest.js +1 -1
- package/dist/compat/function/rest.mjs +1 -1
- package/dist/compat/index.d.mts +3 -3
- package/dist/compat/index.d.ts +3 -3
- package/dist/compat/index.js +6 -4
- package/dist/compat/index.mjs +5 -5
- package/dist/compat/math/maxBy.js +1 -1
- package/dist/compat/math/maxBy.mjs +1 -1
- package/dist/compat/math/meanBy.d.mts +4 -0
- package/dist/compat/math/meanBy.d.ts +4 -0
- package/dist/compat/math/meanBy.js +8 -3
- package/dist/compat/math/meanBy.mjs +8 -3
- package/dist/compat/math/minBy.js +1 -1
- package/dist/compat/math/minBy.mjs +1 -1
- package/dist/compat/object/cloneDeep.d.mts +5 -5
- package/dist/compat/object/cloneDeep.d.ts +5 -5
- package/dist/compat/object/cloneDeep.js +5 -5
- package/dist/compat/object/cloneDeep.mjs +5 -5
- package/dist/compat/object/cloneDeepWith.js +3 -1
- package/dist/compat/object/cloneDeepWith.mjs +3 -1
- package/dist/compat/object/cloneWith.d.mts +1 -1
- package/dist/compat/object/cloneWith.d.ts +1 -1
- package/dist/compat/object/cloneWith.js +1 -1
- package/dist/compat/object/cloneWith.mjs +1 -1
- package/dist/compat/object/entries.d.mts +1 -0
- package/dist/compat/object/entries.d.ts +1 -0
- package/dist/compat/object/entries.js +1 -0
- package/dist/compat/object/entries.mjs +1 -0
- package/dist/compat/object/entriesIn.d.mts +1 -0
- package/dist/compat/object/entriesIn.d.ts +1 -0
- package/dist/compat/object/entriesIn.js +1 -0
- package/dist/compat/object/entriesIn.mjs +1 -0
- package/dist/compat/object/omit.js +5 -5
- package/dist/compat/object/omit.mjs +5 -5
- package/dist/compat/object/transform.js +1 -1
- package/dist/compat/object/transform.mjs +1 -1
- package/dist/compat/object/updateWith.js +2 -2
- package/dist/compat/object/updateWith.mjs +2 -2
- package/dist/compat/predicate/isMatchWith.js +14 -5
- package/dist/compat/predicate/isMatchWith.mjs +14 -5
- package/dist/compat/string/template.js +2 -1
- package/dist/compat/string/template.mjs +2 -1
- package/dist/compat/string/words.js +17 -13
- package/dist/compat/string/words.mjs +17 -13
- package/dist/compat/util/iteratee.js +1 -3
- package/dist/compat/util/iteratee.mjs +1 -3
- package/dist/compat/util/toArray.d.mts +5 -5
- package/dist/compat/util/toArray.d.ts +5 -5
- package/dist/compat/util/toArray.js +9 -5
- package/dist/compat/util/toArray.mjs +9 -5
- package/dist/compat/util/toPath.js +11 -3
- package/dist/compat/util/toPath.mjs +11 -3
- package/dist/compat/util/toString.js +4 -1
- package/dist/compat/util/toString.mjs +4 -1
- package/dist/fp/array/at.d.mts +1 -1
- package/dist/fp/array/at.d.ts +1 -1
- package/dist/fp/array/orderBy.d.mts +1 -1
- package/dist/fp/array/orderBy.d.ts +1 -1
- package/dist/fp/array/sortBy.d.mts +1 -1
- package/dist/fp/array/sortBy.d.ts +1 -1
- package/dist/fp/array/unzip.d.mts +3 -0
- package/dist/fp/array/unzip.d.ts +3 -0
- package/dist/fp/array/unzip.js +3 -0
- package/dist/fp/array/unzip.mjs +3 -0
- package/dist/function/memoize.d.mts +3 -2
- package/dist/function/memoize.d.ts +3 -2
- package/dist/function/memoize.js +3 -2
- package/dist/function/memoize.mjs +3 -2
- package/dist/function/partial.d.mts +2 -2
- package/dist/function/partial.d.ts +2 -2
- package/dist/function/partialRight.d.mts +5 -5
- package/dist/function/partialRight.d.ts +5 -5
- package/dist/function/rest.d.mts +1 -1
- package/dist/function/rest.d.ts +1 -1
- package/dist/function/rest.js +1 -1
- package/dist/function/rest.mjs +1 -1
- package/dist/function/retry.d.mts +7 -4
- package/dist/function/retry.d.ts +7 -4
- package/dist/function/retry.js +4 -2
- package/dist/function/retry.mjs +1 -1
- package/dist/index.d.mts +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.js +18 -4
- package/dist/index.mjs +12 -5
- package/dist/object/cloneDeepWith.d.mts +3 -1
- package/dist/object/cloneDeepWith.d.ts +3 -1
- package/dist/object/cloneDeepWith.js +3 -1
- package/dist/object/cloneDeepWith.mjs +3 -1
- package/dist/object/deepFreeze.d.mts +20 -0
- package/dist/object/deepFreeze.d.ts +20 -0
- package/dist/object/deepFreeze.js +29 -0
- package/dist/object/deepFreeze.mjs +29 -0
- package/dist/object/flattenObject.d.mts +16 -1
- package/dist/object/flattenObject.d.ts +16 -1
- package/dist/object/flattenObject.js +15 -6
- package/dist/object/flattenObject.mjs +15 -6
- package/dist/object/index.d.mts +7 -1
- package/dist/object/index.d.ts +7 -1
- package/dist/object/index.js +12 -0
- package/dist/object/index.mjs +7 -1
- package/dist/object/mapKeysAsync.d.mts +25 -0
- package/dist/object/mapKeysAsync.d.ts +25 -0
- package/dist/object/mapKeysAsync.js +32 -0
- package/dist/object/mapKeysAsync.mjs +32 -0
- package/dist/object/mapValuesAsync.d.mts +26 -0
- package/dist/object/mapValuesAsync.d.ts +26 -0
- package/dist/object/mapValuesAsync.js +32 -0
- package/dist/object/mapValuesAsync.mjs +32 -0
- package/dist/object/merge.js +2 -4
- package/dist/object/merge.mjs +1 -3
- package/dist/object/mergeWith.js +4 -4
- package/dist/object/mergeWith.mjs +4 -4
- package/dist/object/toCamelCaseKeys.d.mts +2 -6
- package/dist/object/toCamelCaseKeys.d.ts +2 -6
- package/dist/object/toConstantCaseKeys.d.mts +52 -0
- package/dist/object/toConstantCaseKeys.d.ts +52 -0
- package/dist/object/toConstantCaseKeys.js +66 -0
- package/dist/object/toConstantCaseKeys.mjs +66 -0
- package/dist/object/toKebabCaseKeys.d.mts +52 -0
- package/dist/object/toKebabCaseKeys.d.ts +52 -0
- package/dist/object/toKebabCaseKeys.js +66 -0
- package/dist/object/toKebabCaseKeys.mjs +66 -0
- package/dist/object/toMerged.js +4 -4
- package/dist/object/toMerged.mjs +4 -4
- package/dist/object/toPascalCaseKeys.d.mts +52 -0
- package/dist/object/toPascalCaseKeys.d.ts +52 -0
- package/dist/object/toPascalCaseKeys.js +66 -0
- package/dist/object/toPascalCaseKeys.mjs +66 -0
- package/dist/object/toSnakeCaseKeys.d.mts +2 -3
- package/dist/object/toSnakeCaseKeys.d.ts +2 -3
- package/dist/promise/index.d.mts +2 -1
- package/dist/promise/index.d.ts +2 -1
- package/dist/promise/index.js +2 -0
- package/dist/promise/index.mjs +2 -1
- package/dist/promise/limitAsync.d.mts +35 -0
- package/dist/promise/limitAsync.d.ts +35 -0
- package/dist/promise/limitAsync.js +46 -0
- package/dist/promise/limitAsync.mjs +46 -0
- package/dist/string/dedent.d.mts +37 -0
- package/dist/string/dedent.d.ts +37 -0
- package/dist/string/dedent.js +38 -0
- package/dist/string/dedent.mjs +38 -0
- package/dist/string/index.d.mts +2 -1
- package/dist/string/index.d.ts +2 -1
- package/dist/string/index.js +5 -3
- package/dist/string/index.mjs +5 -4
- package/dist/types/ToCamelCaseKeys.d.mts +24 -0
- package/dist/types/ToCamelCaseKeys.d.ts +24 -0
- package/dist/types/ToConstantCaseKeys.d.mts +21 -0
- package/dist/types/ToConstantCaseKeys.d.ts +21 -0
- package/dist/types/ToKebabCaseKeys.d.mts +23 -0
- package/dist/types/ToKebabCaseKeys.d.ts +23 -0
- package/dist/types/ToPascalCaseKeys.d.mts +24 -0
- package/dist/types/ToPascalCaseKeys.d.ts +24 -0
- package/dist/types/ToSnakeCaseKeys.d.mts +21 -0
- package/dist/types/ToSnakeCaseKeys.d.ts +21 -0
- package/dist/types/index.d.mts +6 -1
- package/dist/types/index.d.ts +6 -1
- package/package.json +27 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const require_difference = require("../../array/difference.js");
|
|
2
2
|
const require_differenceBy = require("../../array/differenceBy.js");
|
|
3
3
|
const require_iteratee = require("../util/iteratee.js");
|
|
4
|
+
const require_normalizeZero = require("../_internal/normalizeZero.js");
|
|
4
5
|
const require_isArrayLikeObject = require("../predicate/isArrayLikeObject.js");
|
|
5
6
|
const require_last = require("./last.js");
|
|
6
7
|
const require_flattenArrayLike = require("../_internal/flattenArrayLike.js");
|
|
@@ -17,8 +18,8 @@ function differenceBy(array, ..._values) {
|
|
|
17
18
|
if (!require_isArrayLikeObject.isArrayLikeObject(array)) return [];
|
|
18
19
|
const iteratee$1 = require_last.last(_values);
|
|
19
20
|
const values = require_flattenArrayLike.flattenArrayLike(_values);
|
|
20
|
-
if (require_isArrayLikeObject.isArrayLikeObject(iteratee$1)) return require_difference.difference(Array.from(array), values);
|
|
21
|
-
return require_differenceBy.differenceBy(Array.from(array), values, require_iteratee.iteratee(iteratee$1));
|
|
21
|
+
if (require_isArrayLikeObject.isArrayLikeObject(iteratee$1)) return require_difference.difference(Array.from(array), values).map(require_normalizeZero.normalizeZero);
|
|
22
|
+
return require_differenceBy.differenceBy(Array.from(array), values, require_iteratee.iteratee(iteratee$1)).map(require_normalizeZero.normalizeZero);
|
|
22
23
|
}
|
|
23
24
|
//#endregion
|
|
24
25
|
exports.differenceBy = differenceBy;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { difference } from "../../array/difference.mjs";
|
|
2
2
|
import { differenceBy as differenceBy$1 } from "../../array/differenceBy.mjs";
|
|
3
3
|
import { iteratee } from "../util/iteratee.mjs";
|
|
4
|
+
import { normalizeZero } from "../_internal/normalizeZero.mjs";
|
|
4
5
|
import { isArrayLikeObject } from "../predicate/isArrayLikeObject.mjs";
|
|
5
6
|
import { last } from "./last.mjs";
|
|
6
7
|
import { flattenArrayLike } from "../_internal/flattenArrayLike.mjs";
|
|
@@ -17,8 +18,8 @@ function differenceBy(array, ..._values) {
|
|
|
17
18
|
if (!isArrayLikeObject(array)) return [];
|
|
18
19
|
const iteratee$1 = last(_values);
|
|
19
20
|
const values = flattenArrayLike(_values);
|
|
20
|
-
if (isArrayLikeObject(iteratee$1)) return difference(Array.from(array), values);
|
|
21
|
-
return differenceBy$1(Array.from(array), values, iteratee(iteratee$1));
|
|
21
|
+
if (isArrayLikeObject(iteratee$1)) return difference(Array.from(array), values).map(normalizeZero);
|
|
22
|
+
return differenceBy$1(Array.from(array), values, iteratee(iteratee$1)).map(normalizeZero);
|
|
22
23
|
}
|
|
23
24
|
//#endregion
|
|
24
25
|
export { differenceBy };
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* @example
|
|
14
14
|
* const array = [1, 2, 3, 4, 5];
|
|
15
15
|
* const result = drop(array, 2);
|
|
16
|
-
*
|
|
16
|
+
* // => [3, 4, 5]
|
|
17
17
|
*/
|
|
18
18
|
declare function drop<T>(array: ArrayLike<T> | null | undefined, itemsCount?: number): T[];
|
|
19
19
|
//#endregion
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* @example
|
|
14
14
|
* const array = [1, 2, 3, 4, 5];
|
|
15
15
|
* const result = drop(array, 2);
|
|
16
|
-
*
|
|
16
|
+
* // => [3, 4, 5]
|
|
17
17
|
*/
|
|
18
18
|
declare function drop<T>(array: ArrayLike<T> | null | undefined, itemsCount?: number): T[];
|
|
19
19
|
//#endregion
|
|
@@ -6,9 +6,8 @@
|
|
|
6
6
|
* of elements removed from the end.
|
|
7
7
|
*
|
|
8
8
|
* @template T - The type of elements in the array.
|
|
9
|
-
* @param
|
|
9
|
+
* @param array - The array from which to drop elements.
|
|
10
10
|
* @param itemsCount - The number of elements to drop from the end of the array.
|
|
11
|
-
* @param [guard] - Enables use as an iteratee for methods like `_.map`.
|
|
12
11
|
* @returns A new array with the specified number of elements removed from the end.
|
|
13
12
|
*
|
|
14
13
|
* @example
|
|
@@ -16,6 +15,6 @@
|
|
|
16
15
|
* const result = dropRight(array, 2);
|
|
17
16
|
* // result will be [1, 2, 3] since the last two elements are dropped.
|
|
18
17
|
*/
|
|
19
|
-
declare function dropRight<T>(array: ArrayLike<T> | null | undefined,
|
|
18
|
+
declare function dropRight<T>(array: ArrayLike<T> | null | undefined, itemsCount?: number): T[];
|
|
20
19
|
//#endregion
|
|
21
20
|
export { dropRight };
|
|
@@ -6,9 +6,8 @@
|
|
|
6
6
|
* of elements removed from the end.
|
|
7
7
|
*
|
|
8
8
|
* @template T - The type of elements in the array.
|
|
9
|
-
* @param
|
|
9
|
+
* @param array - The array from which to drop elements.
|
|
10
10
|
* @param itemsCount - The number of elements to drop from the end of the array.
|
|
11
|
-
* @param [guard] - Enables use as an iteratee for methods like `_.map`.
|
|
12
11
|
* @returns A new array with the specified number of elements removed from the end.
|
|
13
12
|
*
|
|
14
13
|
* @example
|
|
@@ -16,6 +15,6 @@
|
|
|
16
15
|
* const result = dropRight(array, 2);
|
|
17
16
|
* // result will be [1, 2, 3] since the last two elements are dropped.
|
|
18
17
|
*/
|
|
19
|
-
declare function dropRight<T>(array: ArrayLike<T> | null | undefined,
|
|
18
|
+
declare function dropRight<T>(array: ArrayLike<T> | null | undefined, itemsCount?: number): T[];
|
|
20
19
|
//#endregion
|
|
21
20
|
export { dropRight };
|
|
@@ -10,7 +10,7 @@ const require_toInteger = require("../util/toInteger.js");
|
|
|
10
10
|
* of elements removed from the end.
|
|
11
11
|
*
|
|
12
12
|
* @template T - The type of elements in the array.
|
|
13
|
-
* @param
|
|
13
|
+
* @param array - The array from which to drop elements.
|
|
14
14
|
* @param itemsCount - The number of elements to drop from the end of the array.
|
|
15
15
|
* @param [guard] - Enables use as an iteratee for methods like `_.map`.
|
|
16
16
|
* @returns A new array with the specified number of elements removed from the end.
|
|
@@ -20,10 +20,10 @@ const require_toInteger = require("../util/toInteger.js");
|
|
|
20
20
|
* const result = dropRight(array, 2);
|
|
21
21
|
* // result will be [1, 2, 3] since the last two elements are dropped.
|
|
22
22
|
*/
|
|
23
|
-
function dropRight(
|
|
24
|
-
if (!require_isArrayLike.isArrayLike(
|
|
23
|
+
function dropRight(array, itemsCount = 1, guard) {
|
|
24
|
+
if (!require_isArrayLike.isArrayLike(array)) return [];
|
|
25
25
|
itemsCount = guard ? 1 : require_toInteger.toInteger(itemsCount);
|
|
26
|
-
return require_dropRight.dropRight(require_toArray.toArray(
|
|
26
|
+
return require_dropRight.dropRight(require_toArray.toArray(array), itemsCount);
|
|
27
27
|
}
|
|
28
28
|
//#endregion
|
|
29
29
|
exports.dropRight = dropRight;
|
|
@@ -10,7 +10,7 @@ import { toInteger } from "../util/toInteger.mjs";
|
|
|
10
10
|
* of elements removed from the end.
|
|
11
11
|
*
|
|
12
12
|
* @template T - The type of elements in the array.
|
|
13
|
-
* @param
|
|
13
|
+
* @param array - The array from which to drop elements.
|
|
14
14
|
* @param itemsCount - The number of elements to drop from the end of the array.
|
|
15
15
|
* @param [guard] - Enables use as an iteratee for methods like `_.map`.
|
|
16
16
|
* @returns A new array with the specified number of elements removed from the end.
|
|
@@ -20,10 +20,10 @@ import { toInteger } from "../util/toInteger.mjs";
|
|
|
20
20
|
* const result = dropRight(array, 2);
|
|
21
21
|
* // result will be [1, 2, 3] since the last two elements are dropped.
|
|
22
22
|
*/
|
|
23
|
-
function dropRight(
|
|
24
|
-
if (!isArrayLike(
|
|
23
|
+
function dropRight(array, itemsCount = 1, guard) {
|
|
24
|
+
if (!isArrayLike(array)) return [];
|
|
25
25
|
itemsCount = guard ? 1 : toInteger(itemsCount);
|
|
26
|
-
return dropRight$1(toArray(
|
|
26
|
+
return dropRight$1(toArray(array), itemsCount);
|
|
27
27
|
}
|
|
28
28
|
//#endregion
|
|
29
29
|
export { dropRight };
|
|
@@ -8,7 +8,7 @@ require("../compat.js");
|
|
|
8
8
|
* Checks if every item in an object has a specific property, where the property name is provided as a PropertyKey.
|
|
9
9
|
*
|
|
10
10
|
* @template T
|
|
11
|
-
* @param
|
|
11
|
+
* @param collection - The source array or object to check through.
|
|
12
12
|
* @param [doesMatch] - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
|
|
13
13
|
* @param [guard] - Enables use as an iteratee for methods like `_.map`.
|
|
14
14
|
* @returns `true` if every property value has the specified property, or `false` if at least one does not match.
|
|
@@ -19,20 +19,20 @@ require("../compat.js");
|
|
|
19
19
|
* const result = every(obj, 'name');
|
|
20
20
|
* console.log(result); // true
|
|
21
21
|
*/
|
|
22
|
-
function every(
|
|
23
|
-
if (!
|
|
24
|
-
if (guard && require_isIterateeCall.isIterateeCall(
|
|
22
|
+
function every(collection, doesMatch, guard) {
|
|
23
|
+
if (!collection) return true;
|
|
24
|
+
if (guard && require_isIterateeCall.isIterateeCall(collection, doesMatch, guard)) doesMatch = void 0;
|
|
25
25
|
const predicate = require_iteratee.iteratee(doesMatch ?? require_identity.identity);
|
|
26
|
-
if (!require_isArrayLike.isArrayLike(
|
|
27
|
-
const keys = Object.keys(
|
|
26
|
+
if (!require_isArrayLike.isArrayLike(collection)) {
|
|
27
|
+
const keys = Object.keys(collection);
|
|
28
28
|
for (let i = 0; i < keys.length; i++) {
|
|
29
29
|
const key = keys[i];
|
|
30
|
-
const value =
|
|
31
|
-
if (!predicate(value, key,
|
|
30
|
+
const value = collection[key];
|
|
31
|
+
if (!predicate(value, key, collection)) return false;
|
|
32
32
|
}
|
|
33
33
|
return true;
|
|
34
34
|
}
|
|
35
|
-
for (let i = 0; i <
|
|
35
|
+
for (let i = 0; i < collection.length; i++) if (!predicate(collection[i], i, collection)) return false;
|
|
36
36
|
return true;
|
|
37
37
|
}
|
|
38
38
|
//#endregion
|
|
@@ -8,7 +8,7 @@ import "../compat.mjs";
|
|
|
8
8
|
* Checks if every item in an object has a specific property, where the property name is provided as a PropertyKey.
|
|
9
9
|
*
|
|
10
10
|
* @template T
|
|
11
|
-
* @param
|
|
11
|
+
* @param collection - The source array or object to check through.
|
|
12
12
|
* @param [doesMatch] - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
|
|
13
13
|
* @param [guard] - Enables use as an iteratee for methods like `_.map`.
|
|
14
14
|
* @returns `true` if every property value has the specified property, or `false` if at least one does not match.
|
|
@@ -19,20 +19,20 @@ import "../compat.mjs";
|
|
|
19
19
|
* const result = every(obj, 'name');
|
|
20
20
|
* console.log(result); // true
|
|
21
21
|
*/
|
|
22
|
-
function every(
|
|
23
|
-
if (!
|
|
24
|
-
if (guard && isIterateeCall(
|
|
22
|
+
function every(collection, doesMatch, guard) {
|
|
23
|
+
if (!collection) return true;
|
|
24
|
+
if (guard && isIterateeCall(collection, doesMatch, guard)) doesMatch = void 0;
|
|
25
25
|
const predicate = iteratee(doesMatch ?? identity);
|
|
26
|
-
if (!isArrayLike(
|
|
27
|
-
const keys = Object.keys(
|
|
26
|
+
if (!isArrayLike(collection)) {
|
|
27
|
+
const keys = Object.keys(collection);
|
|
28
28
|
for (let i = 0; i < keys.length; i++) {
|
|
29
29
|
const key = keys[i];
|
|
30
|
-
const value =
|
|
31
|
-
if (!predicate(value, key,
|
|
30
|
+
const value = collection[key];
|
|
31
|
+
if (!predicate(value, key, collection)) return false;
|
|
32
32
|
}
|
|
33
33
|
return true;
|
|
34
34
|
}
|
|
35
|
-
for (let i = 0; i <
|
|
35
|
+
for (let i = 0; i < collection.length; i++) if (!predicate(collection[i], i, collection)) return false;
|
|
36
36
|
return true;
|
|
37
37
|
}
|
|
38
38
|
//#endregion
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const require_fill = require("../../array/fill.js");
|
|
2
2
|
const require_isArrayLike = require("../predicate/isArrayLike.js");
|
|
3
|
+
const require_toInteger = require("../util/toInteger.js");
|
|
4
|
+
const require_isIterateeCall = require("../_internal/isIterateeCall.js");
|
|
3
5
|
const require_isString = require("../predicate/isString.js");
|
|
4
6
|
//#region src/compat/array/fill.ts
|
|
5
7
|
/**
|
|
@@ -32,8 +34,12 @@ const require_isString = require("../predicate/isString.js");
|
|
|
32
34
|
function fill(array, value, start = 0, end = array ? array.length : 0) {
|
|
33
35
|
if (!require_isArrayLike.isArrayLike(array)) return [];
|
|
34
36
|
if (require_isString.isString(array)) return array;
|
|
35
|
-
start
|
|
36
|
-
|
|
37
|
+
if (start && typeof start !== "number" && require_isIterateeCall.isIterateeCall(array, value, start)) {
|
|
38
|
+
start = 0;
|
|
39
|
+
end = array.length;
|
|
40
|
+
}
|
|
41
|
+
start = require_toInteger.toInteger(start);
|
|
42
|
+
end = require_toInteger.toInteger(end);
|
|
37
43
|
if (!start) start = 0;
|
|
38
44
|
if (!end) end = 0;
|
|
39
45
|
return require_fill.fill(array, value, start, end);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { fill as fill$1 } from "../../array/fill.mjs";
|
|
2
2
|
import { isArrayLike } from "../predicate/isArrayLike.mjs";
|
|
3
|
+
import { toInteger } from "../util/toInteger.mjs";
|
|
4
|
+
import { isIterateeCall } from "../_internal/isIterateeCall.mjs";
|
|
3
5
|
import { isString } from "../predicate/isString.mjs";
|
|
4
6
|
//#region src/compat/array/fill.ts
|
|
5
7
|
/**
|
|
@@ -32,8 +34,12 @@ import { isString } from "../predicate/isString.mjs";
|
|
|
32
34
|
function fill(array, value, start = 0, end = array ? array.length : 0) {
|
|
33
35
|
if (!isArrayLike(array)) return [];
|
|
34
36
|
if (isString(array)) return array;
|
|
35
|
-
start
|
|
36
|
-
|
|
37
|
+
if (start && typeof start !== "number" && isIterateeCall(array, value, start)) {
|
|
38
|
+
start = 0;
|
|
39
|
+
end = array.length;
|
|
40
|
+
}
|
|
41
|
+
start = toInteger(start);
|
|
42
|
+
end = toInteger(end);
|
|
37
43
|
if (!start) start = 0;
|
|
38
44
|
if (!end) end = 0;
|
|
39
45
|
return fill$1(array, value, start, end);
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
const require_identity = require("../../function/identity.js");
|
|
2
|
+
const require_range = require("../../math/range.js");
|
|
3
|
+
const require_isArrayLike = require("../predicate/isArrayLike.js");
|
|
2
4
|
const require_iteratee = require("../util/iteratee.js");
|
|
5
|
+
const require_toInteger = require("../util/toInteger.js");
|
|
3
6
|
//#region src/compat/array/find.ts
|
|
4
7
|
/**
|
|
5
8
|
* Finds the first item in an object that has a specific property, where the property name is provided as a PropertyKey.
|
|
6
9
|
*
|
|
7
10
|
* @template T
|
|
8
|
-
* @param
|
|
11
|
+
* @param collection - The source array or object to search through.
|
|
9
12
|
* @param [doesMatch=identity] - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
|
|
10
13
|
* @param [fromIndex=0] - The index to start the search from, defaults to 0.
|
|
11
14
|
* @returns The first property value that has the specified property, or `undefined` if no match is found.
|
|
@@ -16,20 +19,18 @@ const require_iteratee = require("../util/iteratee.js");
|
|
|
16
19
|
* const result = find(obj, 'name');
|
|
17
20
|
* console.log(result); // { id: 1, name: 'Alice' }
|
|
18
21
|
*/
|
|
19
|
-
function find(
|
|
20
|
-
if (!
|
|
21
|
-
if (fromIndex < 0) fromIndex = Math.max(source.length + fromIndex, 0);
|
|
22
|
+
function find(collection, _doesMatch = require_identity.identity, fromIndex = 0) {
|
|
23
|
+
if (!collection) return;
|
|
22
24
|
const doesMatch = require_iteratee.iteratee(_doesMatch);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return;
|
|
25
|
+
const keys = require_isArrayLike.isArrayLike(collection) ? require_range.range(0, collection.length) : Object.keys(collection);
|
|
26
|
+
fromIndex = require_toInteger.toInteger(fromIndex);
|
|
27
|
+
if (!fromIndex) fromIndex = 0;
|
|
28
|
+
if (fromIndex < 0) fromIndex = Math.max(keys.length + fromIndex, 0);
|
|
29
|
+
for (let i = fromIndex; i < keys.length; i++) {
|
|
30
|
+
const key = keys[i];
|
|
31
|
+
const value = collection[key];
|
|
32
|
+
if (doesMatch(value, key, collection)) return value;
|
|
31
33
|
}
|
|
32
|
-
return source.slice(fromIndex).find(doesMatch);
|
|
33
34
|
}
|
|
34
35
|
//#endregion
|
|
35
36
|
exports.find = find;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { identity } from "../../function/identity.mjs";
|
|
2
|
+
import { range } from "../../math/range.mjs";
|
|
3
|
+
import { isArrayLike } from "../predicate/isArrayLike.mjs";
|
|
2
4
|
import { iteratee } from "../util/iteratee.mjs";
|
|
5
|
+
import { toInteger } from "../util/toInteger.mjs";
|
|
3
6
|
//#region src/compat/array/find.ts
|
|
4
7
|
/**
|
|
5
8
|
* Finds the first item in an object that has a specific property, where the property name is provided as a PropertyKey.
|
|
6
9
|
*
|
|
7
10
|
* @template T
|
|
8
|
-
* @param
|
|
11
|
+
* @param collection - The source array or object to search through.
|
|
9
12
|
* @param [doesMatch=identity] - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
|
|
10
13
|
* @param [fromIndex=0] - The index to start the search from, defaults to 0.
|
|
11
14
|
* @returns The first property value that has the specified property, or `undefined` if no match is found.
|
|
@@ -16,20 +19,18 @@ import { iteratee } from "../util/iteratee.mjs";
|
|
|
16
19
|
* const result = find(obj, 'name');
|
|
17
20
|
* console.log(result); // { id: 1, name: 'Alice' }
|
|
18
21
|
*/
|
|
19
|
-
function find(
|
|
20
|
-
if (!
|
|
21
|
-
if (fromIndex < 0) fromIndex = Math.max(source.length + fromIndex, 0);
|
|
22
|
+
function find(collection, _doesMatch = identity, fromIndex = 0) {
|
|
23
|
+
if (!collection) return;
|
|
22
24
|
const doesMatch = iteratee(_doesMatch);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return;
|
|
25
|
+
const keys = isArrayLike(collection) ? range(0, collection.length) : Object.keys(collection);
|
|
26
|
+
fromIndex = toInteger(fromIndex);
|
|
27
|
+
if (!fromIndex) fromIndex = 0;
|
|
28
|
+
if (fromIndex < 0) fromIndex = Math.max(keys.length + fromIndex, 0);
|
|
29
|
+
for (let i = fromIndex; i < keys.length; i++) {
|
|
30
|
+
const key = keys[i];
|
|
31
|
+
const value = collection[key];
|
|
32
|
+
if (doesMatch(value, key, collection)) return value;
|
|
31
33
|
}
|
|
32
|
-
return source.slice(fromIndex).find(doesMatch);
|
|
33
34
|
}
|
|
34
35
|
//#endregion
|
|
35
36
|
export { find };
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_matches = require("../predicate/matches.js");
|
|
3
|
-
const require_matchesProperty = require("../predicate/matchesProperty.js");
|
|
1
|
+
const require_iteratee = require("../util/iteratee.js");
|
|
4
2
|
const require_toInteger = require("../util/toInteger.js");
|
|
5
3
|
const require_identity = require("../function/identity.js");
|
|
6
4
|
//#region src/compat/array/findIndex.ts
|
|
@@ -24,22 +22,8 @@ function findIndex(arr, doesMatch = require_identity.identity, fromIndex = 0) {
|
|
|
24
22
|
fromIndex = require_toInteger.toInteger(fromIndex);
|
|
25
23
|
if (fromIndex < 0) fromIndex = Math.max(arr.length + fromIndex, 0);
|
|
26
24
|
const subArray = Array.from(arr).slice(fromIndex);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
case "function":
|
|
30
|
-
index = subArray.findIndex(doesMatch);
|
|
31
|
-
break;
|
|
32
|
-
case "object":
|
|
33
|
-
if (Array.isArray(doesMatch) && doesMatch.length === 2) {
|
|
34
|
-
const key = doesMatch[0];
|
|
35
|
-
const value = doesMatch[1];
|
|
36
|
-
index = subArray.findIndex(require_matchesProperty.matchesProperty(key, value));
|
|
37
|
-
} else index = subArray.findIndex(require_matches.matches(doesMatch));
|
|
38
|
-
break;
|
|
39
|
-
case "number":
|
|
40
|
-
case "symbol":
|
|
41
|
-
case "string": index = subArray.findIndex(require_property.property(doesMatch));
|
|
42
|
-
}
|
|
25
|
+
const iteratee$1 = require_iteratee.iteratee(doesMatch);
|
|
26
|
+
const index = subArray.findIndex(iteratee$1);
|
|
43
27
|
return index === -1 ? -1 : index + fromIndex;
|
|
44
28
|
}
|
|
45
29
|
//#endregion
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { matches } from "../predicate/matches.mjs";
|
|
3
|
-
import { matchesProperty } from "../predicate/matchesProperty.mjs";
|
|
1
|
+
import { iteratee } from "../util/iteratee.mjs";
|
|
4
2
|
import { toInteger } from "../util/toInteger.mjs";
|
|
5
3
|
import { identity } from "../function/identity.mjs";
|
|
6
4
|
//#region src/compat/array/findIndex.ts
|
|
@@ -24,22 +22,8 @@ function findIndex(arr, doesMatch = identity, fromIndex = 0) {
|
|
|
24
22
|
fromIndex = toInteger(fromIndex);
|
|
25
23
|
if (fromIndex < 0) fromIndex = Math.max(arr.length + fromIndex, 0);
|
|
26
24
|
const subArray = Array.from(arr).slice(fromIndex);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
case "function":
|
|
30
|
-
index = subArray.findIndex(doesMatch);
|
|
31
|
-
break;
|
|
32
|
-
case "object":
|
|
33
|
-
if (Array.isArray(doesMatch) && doesMatch.length === 2) {
|
|
34
|
-
const key = doesMatch[0];
|
|
35
|
-
const value = doesMatch[1];
|
|
36
|
-
index = subArray.findIndex(matchesProperty(key, value));
|
|
37
|
-
} else index = subArray.findIndex(matches(doesMatch));
|
|
38
|
-
break;
|
|
39
|
-
case "number":
|
|
40
|
-
case "symbol":
|
|
41
|
-
case "string": index = subArray.findIndex(property(doesMatch));
|
|
42
|
-
}
|
|
25
|
+
const iteratee$1 = iteratee(doesMatch);
|
|
26
|
+
const index = subArray.findIndex(iteratee$1);
|
|
43
27
|
return index === -1 ? -1 : index + fromIndex;
|
|
44
28
|
}
|
|
45
29
|
//#endregion
|
|
@@ -7,7 +7,7 @@ const require_toInteger = require("../util/toInteger.js");
|
|
|
7
7
|
*
|
|
8
8
|
* @template T
|
|
9
9
|
* @param collection - The array or object to search through.
|
|
10
|
-
* @param [
|
|
10
|
+
* @param [_doesMatch=identity] - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
|
|
11
11
|
* @param [fromIndex] - The index to start the search from, defaults to collection.length-1 for arrays or Object.keys(collection).length-1 for objects.
|
|
12
12
|
* @returns The last property value that has the specified property, or `undefined` if no match is found.
|
|
13
13
|
*
|
|
@@ -17,13 +17,13 @@ const require_toInteger = require("../util/toInteger.js");
|
|
|
17
17
|
* const result = findLast(obj, 'name');
|
|
18
18
|
* console.log(result); // { id: 3, name: 'Bob' }
|
|
19
19
|
*/
|
|
20
|
-
function findLast(collection,
|
|
20
|
+
function findLast(collection, _doesMatch = require_identity.identity, fromIndex) {
|
|
21
21
|
if (!collection) return;
|
|
22
22
|
const length = Array.isArray(collection) ? collection.length : Object.keys(collection).length;
|
|
23
23
|
fromIndex = require_toInteger.toInteger(fromIndex ?? length - 1);
|
|
24
24
|
if (fromIndex < 0) fromIndex = Math.max(length + fromIndex, 0);
|
|
25
25
|
else fromIndex = Math.min(fromIndex, length - 1);
|
|
26
|
-
const doesMatch = require_iteratee.iteratee(
|
|
26
|
+
const doesMatch = require_iteratee.iteratee(_doesMatch);
|
|
27
27
|
if (!Array.isArray(collection)) {
|
|
28
28
|
const keys = Object.keys(collection);
|
|
29
29
|
for (let i = fromIndex; i >= 0; i--) {
|
|
@@ -7,7 +7,7 @@ import { toInteger } from "../util/toInteger.mjs";
|
|
|
7
7
|
*
|
|
8
8
|
* @template T
|
|
9
9
|
* @param collection - The array or object to search through.
|
|
10
|
-
* @param [
|
|
10
|
+
* @param [_doesMatch=identity] - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
|
|
11
11
|
* @param [fromIndex] - The index to start the search from, defaults to collection.length-1 for arrays or Object.keys(collection).length-1 for objects.
|
|
12
12
|
* @returns The last property value that has the specified property, or `undefined` if no match is found.
|
|
13
13
|
*
|
|
@@ -17,13 +17,13 @@ import { toInteger } from "../util/toInteger.mjs";
|
|
|
17
17
|
* const result = findLast(obj, 'name');
|
|
18
18
|
* console.log(result); // { id: 3, name: 'Bob' }
|
|
19
19
|
*/
|
|
20
|
-
function findLast(collection,
|
|
20
|
+
function findLast(collection, _doesMatch = identity, fromIndex) {
|
|
21
21
|
if (!collection) return;
|
|
22
22
|
const length = Array.isArray(collection) ? collection.length : Object.keys(collection).length;
|
|
23
23
|
fromIndex = toInteger(fromIndex ?? length - 1);
|
|
24
24
|
if (fromIndex < 0) fromIndex = Math.max(length + fromIndex, 0);
|
|
25
25
|
else fromIndex = Math.min(fromIndex, length - 1);
|
|
26
|
-
const doesMatch = iteratee(
|
|
26
|
+
const doesMatch = iteratee(_doesMatch);
|
|
27
27
|
if (!Array.isArray(collection)) {
|
|
28
28
|
const keys = Object.keys(collection);
|
|
29
29
|
for (let i = fromIndex; i >= 0; i--) {
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_isNil = require("../../predicate/isNil.js");
|
|
3
|
-
const require_flattenDepth = require("./flattenDepth.js");
|
|
4
|
-
const require_map = require("./map.js");
|
|
1
|
+
const require_flatMapDepth = require("./flatMapDepth.js");
|
|
5
2
|
//#region src/compat/array/flatMap.ts
|
|
6
3
|
/**
|
|
7
4
|
* Creates a flattened array of values by running each element in collection through iteratee and flattening the mapped results.
|
|
@@ -15,10 +12,8 @@ const require_map = require("./map.js");
|
|
|
15
12
|
* flatMap([1, 2], n => [n, n * 2]);
|
|
16
13
|
* // => [1, 2, 2, 4]
|
|
17
14
|
*/
|
|
18
|
-
function flatMap(collection, iteratee
|
|
19
|
-
|
|
20
|
-
const mapped = require_isNil.isNil(iteratee) ? require_map.map(collection) : require_map.map(collection, iteratee);
|
|
21
|
-
return require_flattenDepth.flattenDepth(mapped, 1);
|
|
15
|
+
function flatMap(collection, iteratee) {
|
|
16
|
+
return require_flatMapDepth.flatMapDepth(collection, iteratee, 1);
|
|
22
17
|
}
|
|
23
18
|
//#endregion
|
|
24
19
|
exports.flatMap = flatMap;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isNil } from "../../predicate/isNil.mjs";
|
|
3
|
-
import { flattenDepth } from "./flattenDepth.mjs";
|
|
4
|
-
import { map } from "./map.mjs";
|
|
1
|
+
import { flatMapDepth } from "./flatMapDepth.mjs";
|
|
5
2
|
//#region src/compat/array/flatMap.ts
|
|
6
3
|
/**
|
|
7
4
|
* Creates a flattened array of values by running each element in collection through iteratee and flattening the mapped results.
|
|
@@ -15,9 +12,8 @@ import { map } from "./map.mjs";
|
|
|
15
12
|
* flatMap([1, 2], n => [n, n * 2]);
|
|
16
13
|
* // => [1, 2, 2, 4]
|
|
17
14
|
*/
|
|
18
|
-
function flatMap(collection, iteratee
|
|
19
|
-
|
|
20
|
-
return flattenDepth(isNil(iteratee) ? map(collection) : map(collection, iteratee), 1);
|
|
15
|
+
function flatMap(collection, iteratee) {
|
|
16
|
+
return flatMapDepth(collection, iteratee, 1);
|
|
21
17
|
}
|
|
22
18
|
//#endregion
|
|
23
19
|
export { flatMap };
|
|
@@ -8,7 +8,7 @@ const require_map = require("./map.js");
|
|
|
8
8
|
*
|
|
9
9
|
* @template T, R
|
|
10
10
|
* @param collection - The array or object to iterate over.
|
|
11
|
-
* @param [iteratee] - The function that produces the new array elements.
|
|
11
|
+
* @param [iteratee=identity] - The function that produces the new array elements.
|
|
12
12
|
* @param [depth=1] - The maximum recursion depth.
|
|
13
13
|
* @returns A new array that has been flattened up to the specified depth.
|
|
14
14
|
*
|
|
@@ -8,7 +8,7 @@ import { map } from "./map.mjs";
|
|
|
8
8
|
*
|
|
9
9
|
* @template T, R
|
|
10
10
|
* @param collection - The array or object to iterate over.
|
|
11
|
-
* @param [iteratee] - The function that produces the new array elements.
|
|
11
|
+
* @param [iteratee=identity] - The function that produces the new array elements.
|
|
12
12
|
* @param [depth=1] - The maximum recursion depth.
|
|
13
13
|
* @returns A new array that has been flattened up to the specified depth.
|
|
14
14
|
*
|
|
@@ -22,7 +22,7 @@ const require_isArrayLike = require("../predicate/isArrayLike.js");
|
|
|
22
22
|
*/
|
|
23
23
|
function forEach(collection, callback = require_identity.identity) {
|
|
24
24
|
if (!collection) return collection;
|
|
25
|
-
const keys = require_isArrayLike.isArrayLike(collection)
|
|
25
|
+
const keys = require_isArrayLike.isArrayLike(collection) ? require_range.range(0, collection.length) : Object.keys(collection);
|
|
26
26
|
for (let i = 0; i < keys.length; i++) {
|
|
27
27
|
const key = keys[i];
|
|
28
28
|
const value = collection[key];
|
|
@@ -22,7 +22,7 @@ import { isArrayLike } from "../predicate/isArrayLike.mjs";
|
|
|
22
22
|
*/
|
|
23
23
|
function forEach(collection, callback = identity) {
|
|
24
24
|
if (!collection) return collection;
|
|
25
|
-
const keys = isArrayLike(collection)
|
|
25
|
+
const keys = isArrayLike(collection) ? range(0, collection.length) : Object.keys(collection);
|
|
26
26
|
for (let i = 0; i < keys.length; i++) {
|
|
27
27
|
const key = keys[i];
|
|
28
28
|
const value = collection[key];
|
|
@@ -8,7 +8,7 @@ const require_isString = require("../predicate/isString.js");
|
|
|
8
8
|
*
|
|
9
9
|
* The comparison uses SameValueZero to check for inclusion.
|
|
10
10
|
*
|
|
11
|
-
* @param
|
|
11
|
+
* @param collection - The source to search in. It can be an array, an object, or a string.
|
|
12
12
|
* @param [target] - The value to search for in the source.
|
|
13
13
|
* @param [fromIndex=0] - The index to start searching from. If negative, it is treated as an offset from the end of the source.
|
|
14
14
|
* @returns `true` if the value is found in the source, `false` otherwise.
|
|
@@ -19,25 +19,25 @@ const require_isString = require("../predicate/isString.js");
|
|
|
19
19
|
* includes('hello world', 'world'); // true
|
|
20
20
|
* includes('hello world', 'test'); // false
|
|
21
21
|
*/
|
|
22
|
-
function includes(
|
|
23
|
-
if (
|
|
22
|
+
function includes(collection, target, fromIndex, guard) {
|
|
23
|
+
if (collection == null) return false;
|
|
24
24
|
if (guard || !fromIndex) fromIndex = 0;
|
|
25
25
|
else fromIndex = require_toInteger.toInteger(fromIndex);
|
|
26
|
-
if (require_isString.isString(
|
|
27
|
-
if (fromIndex >
|
|
28
|
-
if (fromIndex < 0) fromIndex = Math.max(0,
|
|
29
|
-
return
|
|
26
|
+
if (require_isString.isString(collection)) {
|
|
27
|
+
if (fromIndex > collection.length || target instanceof RegExp) return false;
|
|
28
|
+
if (fromIndex < 0) fromIndex = Math.max(0, collection.length + fromIndex);
|
|
29
|
+
return collection.includes(target, fromIndex);
|
|
30
30
|
}
|
|
31
|
-
if (Array.isArray(
|
|
32
|
-
if (require_isArrayLike.isArrayLike(
|
|
33
|
-
if (fromIndex < 0) fromIndex = Math.max(0,
|
|
34
|
-
for (let i = fromIndex; i <
|
|
31
|
+
if (Array.isArray(collection)) return collection.includes(target, fromIndex);
|
|
32
|
+
if (require_isArrayLike.isArrayLike(collection)) {
|
|
33
|
+
if (fromIndex < 0) fromIndex = Math.max(0, collection.length + fromIndex);
|
|
34
|
+
for (let i = fromIndex; i < collection.length; i++) if (require_eq.eq(collection[i], target)) return true;
|
|
35
35
|
return false;
|
|
36
36
|
}
|
|
37
|
-
const keys = Object.keys(
|
|
37
|
+
const keys = Object.keys(collection);
|
|
38
38
|
if (fromIndex < 0) fromIndex = Math.max(0, keys.length + fromIndex);
|
|
39
39
|
for (let i = fromIndex; i < keys.length; i++) {
|
|
40
|
-
const value = Reflect.get(
|
|
40
|
+
const value = Reflect.get(collection, keys[i]);
|
|
41
41
|
if (require_eq.eq(value, target)) return true;
|
|
42
42
|
}
|
|
43
43
|
return false;
|