es-toolkit 1.9.0 → 1.10.0-dev.204
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 +22 -1
- package/README.md +1 -1
- package/dist/array/chunk.mjs +1 -1
- package/dist/array/compact.mjs +1 -1
- package/dist/array/countBy.mjs +1 -1
- package/dist/array/difference.mjs +1 -1
- package/dist/array/differenceBy.mjs +1 -1
- package/dist/array/differenceWith.mjs +1 -1
- package/dist/array/drop.mjs +1 -1
- package/dist/array/dropRight.mjs +1 -1
- package/dist/array/dropRightWhile.mjs +1 -1
- package/dist/array/dropWhile.mjs +1 -1
- package/dist/array/fill.mjs +1 -1
- package/dist/array/flatten.mjs +1 -1
- package/dist/array/flattenDeep.d.mts +25 -0
- package/dist/array/flattenDeep.d.ts +25 -0
- package/dist/array/flattenDeep.js +52 -0
- package/dist/array/flattenDeep.js.map +1 -0
- package/dist/array/flattenDeep.mjs +9 -0
- package/dist/array/forEachRight.mjs +1 -1
- package/dist/array/groupBy.mjs +1 -1
- package/dist/array/head.mjs +1 -1
- package/dist/array/index.d.mts +4 -0
- package/dist/array/index.d.ts +4 -0
- package/dist/array/index.js +38 -0
- package/dist/array/index.js.map +1 -1
- package/dist/array/index.mjs +45 -29
- package/dist/array/initial.d.mts +26 -0
- package/dist/array/initial.d.ts +26 -0
- package/dist/array/initial.js +36 -0
- package/dist/array/initial.js.map +1 -0
- package/dist/array/initial.mjs +8 -0
- package/dist/array/intersection.mjs +1 -1
- package/dist/array/intersectionBy.mjs +1 -1
- package/dist/array/intersectionWith.mjs +1 -1
- package/dist/array/keyBy.mjs +1 -1
- package/dist/array/last.d.mts +25 -0
- package/dist/array/last.d.ts +25 -0
- package/dist/array/last.js +33 -0
- package/dist/array/last.js.map +1 -0
- package/dist/array/last.mjs +8 -0
- package/dist/array/maxBy.mjs +1 -1
- package/dist/array/minBy.mjs +1 -1
- package/dist/array/orderBy.mjs +1 -1
- package/dist/array/partition.mjs +1 -1
- package/dist/array/sample.mjs +1 -1
- package/dist/array/sampleSize.mjs +1 -1
- package/dist/array/shuffle.mjs +1 -1
- package/dist/array/tail.mjs +1 -1
- package/dist/array/take.mjs +1 -1
- package/dist/array/takeRight.mjs +1 -1
- package/dist/array/takeRightWhile.mjs +1 -1
- package/dist/array/takeWhile.mjs +1 -1
- package/dist/array/toFilled.d.mts +33 -0
- package/dist/array/toFilled.d.ts +33 -0
- package/dist/array/toFilled.js +40 -0
- package/dist/array/toFilled.js.map +1 -0
- package/dist/array/toFilled.mjs +8 -0
- package/dist/array/union.mjs +1 -1
- package/dist/array/unionBy.mjs +1 -1
- package/dist/array/unionWith.mjs +1 -1
- package/dist/array/uniq.mjs +1 -1
- package/dist/array/uniqBy.mjs +1 -1
- package/dist/array/uniqWith.mjs +1 -1
- package/dist/array/unzip.mjs +1 -1
- package/dist/array/unzipWith.mjs +1 -1
- package/dist/array/without.mjs +1 -1
- package/dist/array/xor.mjs +1 -1
- package/dist/array/xorBy.mjs +1 -1
- package/dist/array/xorWith.mjs +1 -1
- package/dist/array/zip.mjs +1 -1
- package/dist/array/zipObject.mjs +1 -1
- package/dist/array/zipWith.mjs +1 -1
- package/dist/chunk-236H5JZJ.mjs +1 -0
- package/dist/chunk-2HIMLZE3.mjs +46 -0
- package/dist/chunk-2HIMLZE3.mjs.map +1 -0
- package/dist/chunk-2MRZANXZ.mjs +1 -0
- package/dist/chunk-2MRZANXZ.mjs.map +1 -0
- package/dist/chunk-2SLTL4KL.mjs +13 -0
- package/dist/{chunk-NOFHNJ5C.mjs.map → chunk-2SLTL4KL.mjs.map} +1 -1
- package/dist/{chunk-QZITBKWX.mjs → chunk-4E4D3BMI.mjs} +2 -2
- package/dist/chunk-5IKVJGHO.mjs +14 -0
- package/dist/chunk-5IKVJGHO.mjs.map +1 -0
- package/dist/chunk-ASJF5D6C.mjs +1 -0
- package/dist/chunk-ASJF5D6C.mjs.map +1 -0
- package/dist/chunk-BOOQBJN2.mjs +9 -0
- package/dist/chunk-BOOQBJN2.mjs.map +1 -0
- package/dist/chunk-EYYZQFOP.mjs +14 -0
- package/dist/chunk-EYYZQFOP.mjs.map +1 -0
- package/dist/chunk-F3WCQQET.mjs +14 -0
- package/dist/chunk-F3WCQQET.mjs.map +1 -0
- package/dist/{chunk-LT6E4Y4Z.mjs → chunk-GDC64SYJ.mjs} +2 -2
- package/dist/{chunk-SDIMTYZW.mjs → chunk-IZAD2S7R.mjs} +2 -2
- package/dist/chunk-JYSV56US.mjs +41 -0
- package/dist/chunk-JYSV56US.mjs.map +1 -0
- package/dist/chunk-KPBQ7OUY.mjs +9 -0
- package/dist/chunk-KPBQ7OUY.mjs.map +1 -0
- package/dist/chunk-ML727RRJ.mjs +13 -0
- package/dist/chunk-ML727RRJ.mjs.map +1 -0
- package/dist/chunk-NKLIE2OI.mjs +1 -0
- package/dist/chunk-NKLIE2OI.mjs.map +1 -0
- package/dist/chunk-OP4OAKQJ.mjs +16 -0
- package/dist/chunk-OP4OAKQJ.mjs.map +1 -0
- package/dist/chunk-OSOLEQLZ.mjs +1 -0
- package/dist/chunk-OSOLEQLZ.mjs.map +1 -0
- package/dist/chunk-QKYYOLJ6.mjs +1 -0
- package/dist/chunk-QKYYOLJ6.mjs.map +1 -0
- package/dist/chunk-U4JGKZ56.mjs +41 -0
- package/dist/chunk-U4JGKZ56.mjs.map +1 -0
- package/dist/chunk-U56ZOM7L.mjs +9 -0
- package/dist/chunk-U56ZOM7L.mjs.map +1 -0
- package/dist/chunk-WMM7TZLG.mjs +9 -0
- package/dist/{chunk-OHQAR5AU.mjs.map → chunk-WMM7TZLG.mjs.map} +1 -1
- package/dist/chunk-WVQ7YVRK.mjs +11 -0
- package/dist/chunk-WVQ7YVRK.mjs.map +1 -0
- package/dist/chunk-XGCYC4YA.mjs +5516 -0
- package/dist/chunk-XGCYC4YA.mjs.map +1 -0
- package/dist/chunk-XPSOKBRZ.mjs +12 -0
- package/dist/chunk-XPSOKBRZ.mjs.map +1 -0
- package/dist/compat/index.d.mts +108 -0
- package/dist/compat/index.d.ts +108 -0
- package/dist/compat/index.js +6578 -0
- package/dist/compat/index.js.map +1 -0
- package/dist/compat/index.mjs +351 -0
- package/dist/compat/index.mjs.map +1 -0
- package/dist/error/AbortError.mjs +1 -1
- package/dist/error/index.mjs +1 -1
- package/dist/function/debounce.mjs +1 -1
- package/dist/function/index.d.mts +1 -0
- package/dist/function/index.d.ts +1 -0
- package/dist/function/index.js +7 -0
- package/dist/function/index.js.map +1 -1
- package/dist/function/index.mjs +8 -4
- package/dist/function/negate.d.mts +10 -0
- package/dist/function/negate.d.ts +10 -0
- package/dist/function/negate.js +33 -0
- package/dist/function/negate.js.map +1 -0
- package/dist/function/negate.mjs +8 -0
- package/dist/function/negate.mjs.map +1 -0
- package/dist/function/noop.mjs +1 -1
- package/dist/function/once.mjs +1 -1
- package/dist/function/throttle.mjs +1 -1
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +5681 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +101 -50
- package/dist/math/clamp.mjs +1 -1
- package/dist/math/inRange.mjs +1 -1
- package/dist/math/index.js +2 -2
- package/dist/math/index.js.map +1 -1
- package/dist/math/index.mjs +9 -9
- package/dist/math/mean.js +2 -2
- package/dist/math/mean.js.map +1 -1
- package/dist/math/mean.mjs +3 -3
- package/dist/math/meanBy.js +2 -2
- package/dist/math/meanBy.js.map +1 -1
- package/dist/math/meanBy.mjs +4 -4
- package/dist/math/random.mjs +1 -1
- package/dist/math/randomInt.mjs +1 -1
- package/dist/math/range.mjs +1 -1
- package/dist/math/round.mjs +1 -1
- package/dist/math/sum.js +2 -2
- package/dist/math/sum.js.map +1 -1
- package/dist/math/sum.mjs +2 -2
- package/dist/object/clone.d.mts +31 -0
- package/dist/object/clone.d.ts +31 -0
- package/dist/object/clone.js +65 -0
- package/dist/object/clone.js.map +1 -0
- package/dist/object/clone.mjs +8 -0
- package/dist/object/clone.mjs.map +1 -0
- package/dist/object/index.d.mts +1 -0
- package/dist/object/index.d.ts +1 -0
- package/dist/object/index.js +39 -0
- package/dist/object/index.js.map +1 -1
- package/dist/object/index.mjs +7 -3
- package/dist/object/invert.mjs +1 -1
- package/dist/object/omit.mjs +2 -2
- package/dist/object/omitBy.mjs +1 -1
- package/dist/object/pick.mjs +1 -1
- package/dist/object/pickBy.mjs +1 -1
- package/dist/predicate/index.d.mts +1 -0
- package/dist/predicate/index.d.ts +1 -0
- package/dist/predicate/index.js +46 -1
- package/dist/predicate/index.js.map +1 -1
- package/dist/predicate/index.mjs +9 -3
- package/dist/predicate/isEqual.d.mts +17 -0
- package/dist/predicate/isEqual.d.ts +17 -0
- package/dist/predicate/isEqual.js +73 -0
- package/dist/predicate/isEqual.js.map +1 -0
- package/dist/predicate/isEqual.mjs +10 -0
- package/dist/predicate/isEqual.mjs.map +1 -0
- package/dist/predicate/isNil.js +1 -1
- package/dist/predicate/isNil.js.map +1 -1
- package/dist/predicate/isNil.mjs +2 -2
- package/dist/predicate/isNotNil.mjs +1 -1
- package/dist/predicate/isNull.mjs +1 -1
- package/dist/predicate/isUndefined.mjs +1 -1
- package/dist/promise/delay.mjs +1 -1
- package/dist/promise/index.mjs +1 -1
- package/dist/string/camelCase.d.mts +17 -0
- package/dist/string/camelCase.d.ts +17 -0
- package/dist/string/camelCase.js +5554 -0
- package/dist/string/camelCase.js.map +1 -0
- package/dist/string/camelCase.mjs +9 -0
- package/dist/string/camelCase.mjs.map +1 -0
- package/dist/string/capitalize.d.mts +14 -0
- package/dist/string/capitalize.d.ts +14 -0
- package/dist/string/capitalize.js +33 -0
- package/dist/string/capitalize.js.map +1 -0
- package/dist/string/capitalize.mjs +8 -0
- package/dist/string/capitalize.mjs.map +1 -0
- package/dist/string/index.d.mts +5 -0
- package/dist/string/index.d.ts +5 -0
- package/dist/string/index.js +5587 -0
- package/dist/string/index.js.map +1 -0
- package/dist/string/index.mjs +26 -0
- package/dist/string/index.mjs.map +1 -0
- package/dist/string/kebabCase.d.mts +17 -0
- package/dist/string/kebabCase.d.ts +17 -0
- package/dist/string/kebabCase.js +43 -0
- package/dist/string/kebabCase.js.map +1 -0
- package/dist/string/kebabCase.mjs +9 -0
- package/dist/string/kebabCase.mjs.map +1 -0
- package/dist/string/lowerCase.d.mts +17 -0
- package/dist/string/lowerCase.d.ts +17 -0
- package/dist/string/lowerCase.js +43 -0
- package/dist/string/lowerCase.js.map +1 -0
- package/dist/string/lowerCase.mjs +9 -0
- package/dist/string/lowerCase.mjs.map +1 -0
- package/dist/string/snakeCase.d.mts +17 -0
- package/dist/string/snakeCase.d.ts +17 -0
- package/dist/string/snakeCase.js +43 -0
- package/dist/string/snakeCase.js.map +1 -0
- package/dist/string/snakeCase.mjs +9 -0
- package/dist/string/snakeCase.mjs.map +1 -0
- package/package.json +21 -1
- package/string.d.ts +1 -0
- package/dist/chunk-2MM5EJJX.mjs +0 -21
- package/dist/chunk-LOY6PATI.mjs +0 -1
- package/dist/chunk-MAJSPFA6.mjs +0 -1
- package/dist/chunk-N6EM6ETS.mjs +0 -1
- package/dist/chunk-NOFHNJ5C.mjs +0 -13
- package/dist/chunk-OHQAR5AU.mjs +0 -9
- package/dist/chunk-PMHULJNL.mjs +0 -1
- /package/dist/{chunk-2MM5EJJX.mjs.map → array/flattenDeep.mjs.map} +0 -0
- /package/dist/{chunk-LOY6PATI.mjs.map → array/initial.mjs.map} +0 -0
- /package/dist/{chunk-MAJSPFA6.mjs.map → array/last.mjs.map} +0 -0
- /package/dist/{chunk-N6EM6ETS.mjs.map → array/toFilled.mjs.map} +0 -0
- /package/dist/{chunk-PMHULJNL.mjs.map → chunk-236H5JZJ.mjs.map} +0 -0
- /package/dist/{chunk-QZITBKWX.mjs.map → chunk-4E4D3BMI.mjs.map} +0 -0
- /package/dist/{chunk-LT6E4Y4Z.mjs.map → chunk-GDC64SYJ.mjs.map} +0 -0
- /package/dist/{chunk-SDIMTYZW.mjs.map → chunk-IZAD2S7R.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# es-toolkit Changelog
|
|
2
2
|
|
|
3
|
+
## Version v1.10.0
|
|
4
|
+
|
|
5
|
+
Released on July 14th, 2024.
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
- Add support for [capitalize](https://es-toolkit.slash.page/reference/string/capitalize.html), [snakeCase](https://es-toolkit.slash.page/reference/string/snakeCase.html), [kebabCase](https://es-toolkit.slash.page/reference/string/kebabCase.html), [camelCase](https://es-toolkit.slash.page/reference/string/camelCase.html) and [lowerCase](https://es-toolkit.slash.page/reference/string/lowerCase.html). (https://github.com/toss/es-toolkit/pull/152, https://github.com/toss/es-toolkit/pull/161, https://github.com/toss/es-toolkit/pull/162, https://github.com/toss/es-toolkit/pull/166, [21d6530](https://github.com/toss/es-toolkit/commit/21d6530e16471d596410d57d59fd3ced8fc5569f)).
|
|
11
|
+
- Add support for [negate](https://es-toolkit.slash.page/reference/function/negate.html). (https://github.com/toss/es-toolkit/pull/177)
|
|
12
|
+
- Add support for [isEqual](https://es-toolkit.slash.page/reference/predicate/isEqual.html). (https://github.com/toss/es-toolkit/pull/174)
|
|
13
|
+
- Add support for [clone](https://es-toolkit.slash.page/reference/object/clone.html). (https://github.com/toss/es-toolkit/pull/155)
|
|
14
|
+
- Add support for [toFilled](https://es-toolkit.slash.page/reference/array/toFilled.html). (https://github.com/toss/es-toolkit/pull/154)
|
|
15
|
+
- Add support for [initial](https://es-toolkit.slash.page/reference/array/initial.html) and [last](https://es-toolkit.slash.page/reference/array/last.html). (https://github.com/toss/es-toolkit/pull/188, https://github.com/toss/es-toolkit/pull/149)
|
|
16
|
+
- Add support for [flattenDeep](https://es-toolkit.slash.page/reference/array/flattenDeep.html). (https://github.com/toss/es-toolkit/pull/160)
|
|
17
|
+
|
|
18
|
+
### Performance Improvements
|
|
19
|
+
|
|
20
|
+
- Optimize the performance of [isNil](https://es-toolkit.slash.page/reference/predicate/isNil.html) by simplifying its check. ([489ac76](https://github.com/toss/es-toolkit/commit/489ac76fc62f97cbfa3ca9eec2e0a4c03c4f5b1c))
|
|
21
|
+
- Optimize the performance of [sum](https://es-toolkit.slash.page/reference/array/sum.html). (https://github.com/toss/es-toolkit/pull/155)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
3
25
|
## Version v1.9.0
|
|
4
26
|
|
|
5
27
|
Released on July 10th, 2024.
|
|
@@ -8,7 +30,6 @@ Released on July 10th, 2024.
|
|
|
8
30
|
- Add support for [unzip](https://es-toolkit.slash.page/reference/array/unzip.html). (https://github.com/toss/es-toolkit/pull/130)
|
|
9
31
|
- Add support for [flatten](https://es-toolkit.slash.page/reference/array/flatten.html), which is six times faster than `Array#flat`. (https://github.com/toss/es-toolkit/pull/147)
|
|
10
32
|
|
|
11
|
-
|
|
12
33
|
## Version v1.8.0
|
|
13
34
|
|
|
14
35
|
Released on July 5th, 2024.
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# es-toolkit · [](https://github.com/toss/slash/blob/main/LICENSE) [](https://codecov.io/gh/toss/es-toolkit) [](https://www.npmjs.com/package/es-toolkit) [](https://jsr.io/@es-toolkit/es-toolkit)
|
|
4
4
|
|
|
5
|
-
English | [한국어](https://github.com/toss/es-toolkit/blob/main/README-ko_kr.md)
|
|
5
|
+
English | [한국어](https://github.com/toss/es-toolkit/blob/main/README-ko_kr.md) | [简体中文](https://github.com/toss/es-toolkit/blob/main/README-zh_hans.md)
|
|
6
6
|
|
|
7
7
|
es-toolkit is a state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.
|
|
8
8
|
|
package/dist/array/chunk.mjs
CHANGED
package/dist/array/compact.mjs
CHANGED
package/dist/array/countBy.mjs
CHANGED
package/dist/array/drop.mjs
CHANGED
package/dist/array/dropRight.mjs
CHANGED
package/dist/array/dropWhile.mjs
CHANGED
package/dist/array/fill.mjs
CHANGED
package/dist/array/flatten.mjs
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility type for recursively unpacking nested array types to extract the type of the innermost element
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ExtractNestedArrayType<(number | (number | number[])[])[]>
|
|
6
|
+
* // number
|
|
7
|
+
*
|
|
8
|
+
* ExtractNestedArrayType<(boolean | (string | number[])[])[]>
|
|
9
|
+
* // string | number | boolean
|
|
10
|
+
*/
|
|
11
|
+
type ExtractNestedArrayType<T> = T extends ReadonlyArray<infer U> ? ExtractNestedArrayType<U> : T;
|
|
12
|
+
/**
|
|
13
|
+
* Flattens all depths of a nested array.
|
|
14
|
+
*
|
|
15
|
+
* @template T - The type of elements within the array.
|
|
16
|
+
* @param {T[]} arr - The array to flatten.
|
|
17
|
+
* @returns {Array<ExtractNestedArrayType<T>>} A new array that has been flattened.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const arr = flattenDeep([1, [2, [3]], [4, [5, 6]]]);
|
|
21
|
+
* // Returns: [1, 2, 3, 4, 5, 6]
|
|
22
|
+
*/
|
|
23
|
+
declare function flattenDeep<T>(arr: readonly T[]): Array<ExtractNestedArrayType<T>>;
|
|
24
|
+
|
|
25
|
+
export { flattenDeep };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility type for recursively unpacking nested array types to extract the type of the innermost element
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ExtractNestedArrayType<(number | (number | number[])[])[]>
|
|
6
|
+
* // number
|
|
7
|
+
*
|
|
8
|
+
* ExtractNestedArrayType<(boolean | (string | number[])[])[]>
|
|
9
|
+
* // string | number | boolean
|
|
10
|
+
*/
|
|
11
|
+
type ExtractNestedArrayType<T> = T extends ReadonlyArray<infer U> ? ExtractNestedArrayType<U> : T;
|
|
12
|
+
/**
|
|
13
|
+
* Flattens all depths of a nested array.
|
|
14
|
+
*
|
|
15
|
+
* @template T - The type of elements within the array.
|
|
16
|
+
* @param {T[]} arr - The array to flatten.
|
|
17
|
+
* @returns {Array<ExtractNestedArrayType<T>>} A new array that has been flattened.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const arr = flattenDeep([1, [2, [3]], [4, [5, 6]]]);
|
|
21
|
+
* // Returns: [1, 2, 3, 4, 5, 6]
|
|
22
|
+
*/
|
|
23
|
+
declare function flattenDeep<T>(arr: readonly T[]): Array<ExtractNestedArrayType<T>>;
|
|
24
|
+
|
|
25
|
+
export { flattenDeep };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/array/flattenDeep.ts
|
|
21
|
+
var flattenDeep_exports = {};
|
|
22
|
+
__export(flattenDeep_exports, {
|
|
23
|
+
flattenDeep: () => flattenDeep
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(flattenDeep_exports);
|
|
26
|
+
|
|
27
|
+
// src/array/flatten.ts
|
|
28
|
+
function flatten(arr, depth = 1) {
|
|
29
|
+
const result = [];
|
|
30
|
+
const flooredDepth = Math.floor(depth);
|
|
31
|
+
const recursive = (arr2, currentDepth) => {
|
|
32
|
+
for (const item of arr2) {
|
|
33
|
+
if (Array.isArray(item) && currentDepth < flooredDepth) {
|
|
34
|
+
recursive(item, currentDepth + 1);
|
|
35
|
+
} else {
|
|
36
|
+
result.push(item);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
recursive(arr, 0);
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/array/flattenDeep.ts
|
|
45
|
+
function flattenDeep(arr) {
|
|
46
|
+
return flatten(arr, Infinity);
|
|
47
|
+
}
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
flattenDeep
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=flattenDeep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/array/flattenDeep.ts","../../src/array/flatten.ts"],"sourcesContent":["import { flatten } from './flatten.ts';\n\n/**\n * Utility type for recursively unpacking nested array types to extract the type of the innermost element\n *\n * @example\n * ExtractNestedArrayType<(number | (number | number[])[])[]>\n * // number\n *\n * ExtractNestedArrayType<(boolean | (string | number[])[])[]>\n * // string | number | boolean\n */\ntype ExtractNestedArrayType<T> = T extends ReadonlyArray<infer U> ? ExtractNestedArrayType<U> : T;\n\n/**\n * Flattens all depths of a nested array.\n *\n * @template T - The type of elements within the array.\n * @param {T[]} arr - The array to flatten.\n * @returns {Array<ExtractNestedArrayType<T>>} A new array that has been flattened.\n *\n * @example\n * const arr = flattenDeep([1, [2, [3]], [4, [5, 6]]]);\n * // Returns: [1, 2, 3, 4, 5, 6]\n */\nexport function flattenDeep<T>(arr: readonly T[]): Array<ExtractNestedArrayType<T>> {\n return flatten(arr, Infinity) as Array<ExtractNestedArrayType<T>>;\n}\n","/**\n * Flattens an array up to the specified depth.\n *\n * @template T - The type of elements within the array.\n * @template D - The depth to which the array should be flattened.\n * @param {T[]} arr - The array to flatten.\n * @param {D} depth - The depth level specifying how deep a nested array structure should be flattened. Defaults to 1.\n * @returns {Array<FlatArray<T[], D>>} A new array that has been flattened.\n *\n * @example\n * const arr = flatten([1, [2, 3], [4, [5, 6]]], 1);\n * // Returns: [1, 2, 3, 4, [5, 6]]\n *\n * const arr = flatten([1, [2, 3], [4, [5, 6]]], 2);\n * // Returns: [1, 2, 3, 4, 5, 6]\n */\nexport function flatten<T, D extends number = 1>(arr: readonly T[], depth = 1 as D): Array<FlatArray<T[], D>> {\n const result: Array<FlatArray<T[], D>> = [];\n const flooredDepth = Math.floor(depth);\n\n const recursive = (arr: readonly T[], currentDepth: number) => {\n for (const item of arr) {\n if (Array.isArray(item) && currentDepth < flooredDepth) {\n recursive(item, currentDepth + 1);\n } else {\n result.push(item as FlatArray<T[], D>);\n }\n }\n };\n\n recursive(arr, 0);\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACgBO,SAAS,QAAiC,KAAmB,QAAQ,GAAkC;AAC5G,QAAM,SAAmC,CAAC;AAC1C,QAAM,eAAe,KAAK,MAAM,KAAK;AAErC,QAAM,YAAY,CAACA,MAAmB,iBAAyB;AAC7D,eAAW,QAAQA,MAAK;AACtB,UAAI,MAAM,QAAQ,IAAI,KAAK,eAAe,cAAc;AACtD,kBAAU,MAAM,eAAe,CAAC;AAAA,MAClC,OAAO;AACL,eAAO,KAAK,IAAyB;AAAA,MACvC;AAAA,IACF;AAAA,EACF;AAEA,YAAU,KAAK,CAAC;AAChB,SAAO;AACT;;;ADPO,SAAS,YAAe,KAAqD;AAClF,SAAO,QAAQ,KAAK,QAAQ;AAC9B;","names":["arr"]}
|
package/dist/array/groupBy.mjs
CHANGED
package/dist/array/head.mjs
CHANGED
package/dist/array/index.d.mts
CHANGED
|
@@ -10,6 +10,7 @@ export { dropRightWhile } from './dropRightWhile.mjs';
|
|
|
10
10
|
export { dropWhile } from './dropWhile.mjs';
|
|
11
11
|
export { fill } from './fill.mjs';
|
|
12
12
|
export { flatten } from './flatten.mjs';
|
|
13
|
+
export { flattenDeep } from './flattenDeep.mjs';
|
|
13
14
|
export { forEachRight } from './forEachRight.mjs';
|
|
14
15
|
export { groupBy } from './groupBy.mjs';
|
|
15
16
|
export { intersection } from './intersection.mjs';
|
|
@@ -44,3 +45,6 @@ export { zipWith } from './zipWith.mjs';
|
|
|
44
45
|
export { without } from './without.mjs';
|
|
45
46
|
export { head } from './head.mjs';
|
|
46
47
|
export { tail } from './tail.mjs';
|
|
48
|
+
export { toFilled } from './toFilled.mjs';
|
|
49
|
+
export { last } from './last.mjs';
|
|
50
|
+
export { initial } from './initial.mjs';
|
package/dist/array/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { dropRightWhile } from './dropRightWhile.js';
|
|
|
10
10
|
export { dropWhile } from './dropWhile.js';
|
|
11
11
|
export { fill } from './fill.js';
|
|
12
12
|
export { flatten } from './flatten.js';
|
|
13
|
+
export { flattenDeep } from './flattenDeep.js';
|
|
13
14
|
export { forEachRight } from './forEachRight.js';
|
|
14
15
|
export { groupBy } from './groupBy.js';
|
|
15
16
|
export { intersection } from './intersection.js';
|
|
@@ -44,3 +45,6 @@ export { zipWith } from './zipWith.js';
|
|
|
44
45
|
export { without } from './without.js';
|
|
45
46
|
export { head } from './head.js';
|
|
46
47
|
export { tail } from './tail.js';
|
|
48
|
+
export { toFilled } from './toFilled.js';
|
|
49
|
+
export { last } from './last.js';
|
|
50
|
+
export { initial } from './initial.js';
|
package/dist/array/index.js
CHANGED
|
@@ -32,13 +32,16 @@ __export(array_exports, {
|
|
|
32
32
|
dropWhile: () => dropWhile,
|
|
33
33
|
fill: () => fill,
|
|
34
34
|
flatten: () => flatten,
|
|
35
|
+
flattenDeep: () => flattenDeep,
|
|
35
36
|
forEachRight: () => forEachRight,
|
|
36
37
|
groupBy: () => groupBy,
|
|
37
38
|
head: () => head,
|
|
39
|
+
initial: () => initial,
|
|
38
40
|
intersection: () => intersection,
|
|
39
41
|
intersectionBy: () => intersectionBy,
|
|
40
42
|
intersectionWith: () => intersectionWith,
|
|
41
43
|
keyBy: () => keyBy,
|
|
44
|
+
last: () => last,
|
|
42
45
|
maxBy: () => maxBy,
|
|
43
46
|
minBy: () => minBy,
|
|
44
47
|
orderBy: () => orderBy,
|
|
@@ -51,6 +54,7 @@ __export(array_exports, {
|
|
|
51
54
|
takeRight: () => takeRight,
|
|
52
55
|
takeRightWhile: () => takeRightWhile,
|
|
53
56
|
takeWhile: () => takeWhile,
|
|
57
|
+
toFilled: () => toFilled,
|
|
54
58
|
union: () => union,
|
|
55
59
|
unionBy: () => unionBy,
|
|
56
60
|
unionWith: () => unionWith,
|
|
@@ -182,6 +186,11 @@ function flatten(arr, depth = 1) {
|
|
|
182
186
|
return result;
|
|
183
187
|
}
|
|
184
188
|
|
|
189
|
+
// src/array/flattenDeep.ts
|
|
190
|
+
function flattenDeep(arr) {
|
|
191
|
+
return flatten(arr, Infinity);
|
|
192
|
+
}
|
|
193
|
+
|
|
185
194
|
// src/array/forEachRight.ts
|
|
186
195
|
function forEachRight(arr, callback) {
|
|
187
196
|
for (let i = arr.length - 1; i >= 0; i--) {
|
|
@@ -550,6 +559,31 @@ function tail(arr) {
|
|
|
550
559
|
}
|
|
551
560
|
return result;
|
|
552
561
|
}
|
|
562
|
+
|
|
563
|
+
// src/array/toFilled.ts
|
|
564
|
+
function toFilled(arr, value, start = 0, end = arr.length) {
|
|
565
|
+
const length = arr.length;
|
|
566
|
+
const finalStart = Math.max(start >= 0 ? start : length + start, 0);
|
|
567
|
+
const finalEnd = Math.min(end >= 0 ? end : length + end, length);
|
|
568
|
+
const newArr = arr.slice();
|
|
569
|
+
for (let i = finalStart; i < finalEnd; i++) {
|
|
570
|
+
newArr[i] = value;
|
|
571
|
+
}
|
|
572
|
+
return newArr;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// src/array/last.ts
|
|
576
|
+
function last(arr) {
|
|
577
|
+
return arr[arr.length - 1];
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// src/array/initial.ts
|
|
581
|
+
function initial(arr) {
|
|
582
|
+
if (arr.length <= 1) {
|
|
583
|
+
return [];
|
|
584
|
+
}
|
|
585
|
+
return arr.slice(0, -1);
|
|
586
|
+
}
|
|
553
587
|
// Annotate the CommonJS export names for ESM import in node:
|
|
554
588
|
0 && (module.exports = {
|
|
555
589
|
chunk,
|
|
@@ -564,13 +598,16 @@ function tail(arr) {
|
|
|
564
598
|
dropWhile,
|
|
565
599
|
fill,
|
|
566
600
|
flatten,
|
|
601
|
+
flattenDeep,
|
|
567
602
|
forEachRight,
|
|
568
603
|
groupBy,
|
|
569
604
|
head,
|
|
605
|
+
initial,
|
|
570
606
|
intersection,
|
|
571
607
|
intersectionBy,
|
|
572
608
|
intersectionWith,
|
|
573
609
|
keyBy,
|
|
610
|
+
last,
|
|
574
611
|
maxBy,
|
|
575
612
|
minBy,
|
|
576
613
|
orderBy,
|
|
@@ -583,6 +620,7 @@ function tail(arr) {
|
|
|
583
620
|
takeRight,
|
|
584
621
|
takeRightWhile,
|
|
585
622
|
takeWhile,
|
|
623
|
+
toFilled,
|
|
586
624
|
union,
|
|
587
625
|
unionBy,
|
|
588
626
|
unionWith,
|