@pawells/typescript-common 1.0.0
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/LICENSE +21 -0
- package/README.md +148 -0
- package/build/array/array-chunk.d.ts +10 -0
- package/build/array/array-chunk.d.ts.map +1 -0
- package/build/array/array-chunk.js +19 -0
- package/build/array/array-chunk.js.map +1 -0
- package/build/array/array-compact.d.ts +18 -0
- package/build/array/array-compact.d.ts.map +1 -0
- package/build/array/array-compact.js +22 -0
- package/build/array/array-compact.js.map +1 -0
- package/build/array/array-contains.d.ts +9 -0
- package/build/array/array-contains.d.ts.map +1 -0
- package/build/array/array-contains.js +13 -0
- package/build/array/array-contains.js.map +1 -0
- package/build/array/array-count-by.d.ts +21 -0
- package/build/array/array-count-by.d.ts.map +1 -0
- package/build/array/array-count-by.js +29 -0
- package/build/array/array-count-by.js.map +1 -0
- package/build/array/array-difference.d.ts +25 -0
- package/build/array/array-difference.d.ts.map +1 -0
- package/build/array/array-difference.js +34 -0
- package/build/array/array-difference.js.map +1 -0
- package/build/array/array-element.d.ts +7 -0
- package/build/array/array-element.d.ts.map +1 -0
- package/build/array/array-element.js +2 -0
- package/build/array/array-element.js.map +1 -0
- package/build/array/array-filter.d.ts +37 -0
- package/build/array/array-filter.d.ts.map +1 -0
- package/build/array/array-filter.js +78 -0
- package/build/array/array-filter.js.map +1 -0
- package/build/array/array-flatten.d.ts +16 -0
- package/build/array/array-flatten.d.ts.map +1 -0
- package/build/array/array-flatten.js +20 -0
- package/build/array/array-flatten.js.map +1 -0
- package/build/array/array-group-by.d.ts +13 -0
- package/build/array/array-group-by.d.ts.map +1 -0
- package/build/array/array-group-by.js +24 -0
- package/build/array/array-group-by.js.map +1 -0
- package/build/array/array-intersection.d.ts +25 -0
- package/build/array/array-intersection.d.ts.map +1 -0
- package/build/array/array-intersection.js +39 -0
- package/build/array/array-intersection.js.map +1 -0
- package/build/array/array-partition.d.ts +19 -0
- package/build/array/array-partition.d.ts.map +1 -0
- package/build/array/array-partition.js +32 -0
- package/build/array/array-partition.js.map +1 -0
- package/build/array/array-range.d.ts +18 -0
- package/build/array/array-range.d.ts.map +1 -0
- package/build/array/array-range.js +30 -0
- package/build/array/array-range.js.map +1 -0
- package/build/array/array-sample.d.ts +29 -0
- package/build/array/array-sample.d.ts.map +1 -0
- package/build/array/array-sample.js +19 -0
- package/build/array/array-sample.js.map +1 -0
- package/build/array/array-shuffle.d.ts +8 -0
- package/build/array/array-shuffle.d.ts.map +1 -0
- package/build/array/array-shuffle.js +19 -0
- package/build/array/array-shuffle.js.map +1 -0
- package/build/array/array-sort-by.d.ts +20 -0
- package/build/array/array-sort-by.d.ts.map +1 -0
- package/build/array/array-sort-by.js +31 -0
- package/build/array/array-sort-by.js.map +1 -0
- package/build/array/array-zip.d.ts +22 -0
- package/build/array/array-zip.d.ts.map +1 -0
- package/build/array/array-zip.js +25 -0
- package/build/array/array-zip.js.map +1 -0
- package/build/array/array.test.d.ts +2 -0
- package/build/array/array.test.d.ts.map +1 -0
- package/build/array/array.test.js +347 -0
- package/build/array/array.test.js.map +1 -0
- package/build/array/index.d.ts +27 -0
- package/build/array/index.d.ts.map +1 -0
- package/build/array/index.js +25 -0
- package/build/array/index.js.map +1 -0
- package/build/array/types.d.ts +32 -0
- package/build/array/types.d.ts.map +1 -0
- package/build/array/types.js +2 -0
- package/build/array/types.js.map +1 -0
- package/build/array/unique.d.ts +8 -0
- package/build/array/unique.d.ts.map +1 -0
- package/build/array/unique.js +13 -0
- package/build/array/unique.js.map +1 -0
- package/build/enum/enum-entries.d.ts +11 -0
- package/build/enum/enum-entries.d.ts.map +1 -0
- package/build/enum/enum-entries.js +14 -0
- package/build/enum/enum-entries.js.map +1 -0
- package/build/enum/enum-key-by-value.d.ts +13 -0
- package/build/enum/enum-key-by-value.d.ts.map +1 -0
- package/build/enum/enum-key-by-value.js +21 -0
- package/build/enum/enum-key-by-value.js.map +1 -0
- package/build/enum/enum-keys.d.ts +10 -0
- package/build/enum/enum-keys.d.ts.map +1 -0
- package/build/enum/enum-keys.js +14 -0
- package/build/enum/enum-keys.js.map +1 -0
- package/build/enum/enum-safe-value.d.ts +14 -0
- package/build/enum/enum-safe-value.d.ts.map +1 -0
- package/build/enum/enum-safe-value.js +16 -0
- package/build/enum/enum-safe-value.js.map +1 -0
- package/build/enum/enum-values.d.ts +19 -0
- package/build/enum/enum-values.d.ts.map +1 -0
- package/build/enum/enum-values.js +25 -0
- package/build/enum/enum-values.js.map +1 -0
- package/build/enum/enum.test.d.ts +2 -0
- package/build/enum/enum.test.d.ts.map +1 -0
- package/build/enum/enum.test.js +122 -0
- package/build/enum/enum.test.js.map +1 -0
- package/build/enum/index.d.ts +17 -0
- package/build/enum/index.d.ts.map +1 -0
- package/build/enum/index.js +17 -0
- package/build/enum/index.js.map +1 -0
- package/build/enum/types.d.ts +9 -0
- package/build/enum/types.d.ts.map +1 -0
- package/build/enum/types.js +2 -0
- package/build/enum/types.js.map +1 -0
- package/build/enum/validate-enum-value.d.ts +13 -0
- package/build/enum/validate-enum-value.d.ts.map +1 -0
- package/build/enum/validate-enum-value.js +18 -0
- package/build/enum/validate-enum-value.js.map +1 -0
- package/build/function/compose.d.ts +37 -0
- package/build/function/compose.d.ts.map +1 -0
- package/build/function/compose.js +7 -0
- package/build/function/compose.js.map +1 -0
- package/build/function/debounce.d.ts +25 -0
- package/build/function/debounce.d.ts.map +1 -0
- package/build/function/debounce.js +37 -0
- package/build/function/debounce.js.map +1 -0
- package/build/function/function.test.d.ts +2 -0
- package/build/function/function.test.d.ts.map +1 -0
- package/build/function/function.test.js +158 -0
- package/build/function/function.test.js.map +1 -0
- package/build/function/index.d.ts +17 -0
- package/build/function/index.d.ts.map +1 -0
- package/build/function/index.js +16 -0
- package/build/function/index.js.map +1 -0
- package/build/function/memoize.d.ts +23 -0
- package/build/function/memoize.d.ts.map +1 -0
- package/build/function/memoize.js +34 -0
- package/build/function/memoize.js.map +1 -0
- package/build/function/once.d.ts +17 -0
- package/build/function/once.d.ts.map +1 -0
- package/build/function/once.js +27 -0
- package/build/function/once.js.map +1 -0
- package/build/function/sleep.d.ts +20 -0
- package/build/function/sleep.d.ts.map +1 -0
- package/build/function/sleep.js +22 -0
- package/build/function/sleep.js.map +1 -0
- package/build/function/throttle.d.ts +17 -0
- package/build/function/throttle.d.ts.map +1 -0
- package/build/function/throttle.js +37 -0
- package/build/function/throttle.js.map +1 -0
- package/build/function/types.d.ts +5 -0
- package/build/function/types.d.ts.map +1 -0
- package/build/function/types.js +2 -0
- package/build/function/types.js.map +1 -0
- package/build/index.d.ts +32 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +51 -0
- package/build/index.js.map +1 -0
- package/build/object/assert-object.d.ts +8 -0
- package/build/object/assert-object.d.ts.map +1 -0
- package/build/object/assert-object.js +10 -0
- package/build/object/assert-object.js.map +1 -0
- package/build/object/clone.d.ts +39 -0
- package/build/object/clone.d.ts.map +1 -0
- package/build/object/clone.js +85 -0
- package/build/object/clone.js.map +1 -0
- package/build/object/equals.d.ts +44 -0
- package/build/object/equals.d.ts.map +1 -0
- package/build/object/equals.js +104 -0
- package/build/object/equals.js.map +1 -0
- package/build/object/filter-cached.d.ts +9 -0
- package/build/object/filter-cached.d.ts.map +1 -0
- package/build/object/filter-cached.js +108 -0
- package/build/object/filter-cached.js.map +1 -0
- package/build/object/filter.d.ts +85 -0
- package/build/object/filter.d.ts.map +1 -0
- package/build/object/filter.js +248 -0
- package/build/object/filter.js.map +1 -0
- package/build/object/has-circular-reference.d.ts +8 -0
- package/build/object/has-circular-reference.d.ts.map +1 -0
- package/build/object/has-circular-reference.js +40 -0
- package/build/object/has-circular-reference.js.map +1 -0
- package/build/object/hash.d.ts +20 -0
- package/build/object/hash.d.ts.map +1 -0
- package/build/object/hash.js +39 -0
- package/build/object/hash.js.map +1 -0
- package/build/object/index.d.ts +32 -0
- package/build/object/index.d.ts.map +1 -0
- package/build/object/index.js +30 -0
- package/build/object/index.js.map +1 -0
- package/build/object/key-value-pairs.d.ts +21 -0
- package/build/object/key-value-pairs.d.ts.map +1 -0
- package/build/object/key-value-pairs.js +28 -0
- package/build/object/key-value-pairs.js.map +1 -0
- package/build/object/map-cached.d.ts +9 -0
- package/build/object/map-cached.d.ts.map +1 -0
- package/build/object/map-cached.js +97 -0
- package/build/object/map-cached.js.map +1 -0
- package/build/object/map.d.ts +29 -0
- package/build/object/map.d.ts.map +1 -0
- package/build/object/map.js +40 -0
- package/build/object/map.js.map +1 -0
- package/build/object/merge.d.ts +14 -0
- package/build/object/merge.d.ts.map +1 -0
- package/build/object/merge.js +41 -0
- package/build/object/merge.js.map +1 -0
- package/build/object/object-diff.d.ts +40 -0
- package/build/object/object-diff.d.ts.map +1 -0
- package/build/object/object-diff.js +45 -0
- package/build/object/object-diff.js.map +1 -0
- package/build/object/object-flatten.d.ts +22 -0
- package/build/object/object-flatten.d.ts.map +1 -0
- package/build/object/object-flatten.js +38 -0
- package/build/object/object-flatten.js.map +1 -0
- package/build/object/object-invert.d.ts +20 -0
- package/build/object/object-invert.d.ts.map +1 -0
- package/build/object/object-invert.js +26 -0
- package/build/object/object-invert.js.map +1 -0
- package/build/object/object.test.d.ts +2 -0
- package/build/object/object.test.d.ts.map +1 -0
- package/build/object/object.test.js +432 -0
- package/build/object/object.test.js.map +1 -0
- package/build/object/omit.d.ts +8 -0
- package/build/object/omit.d.ts.map +1 -0
- package/build/object/omit.js +17 -0
- package/build/object/omit.js.map +1 -0
- package/build/object/pick.d.ts +50 -0
- package/build/object/pick.d.ts.map +1 -0
- package/build/object/pick.js +60 -0
- package/build/object/pick.js.map +1 -0
- package/build/object/property-paths.d.ts +115 -0
- package/build/object/property-paths.d.ts.map +1 -0
- package/build/object/property-paths.js +170 -0
- package/build/object/property-paths.js.map +1 -0
- package/build/object/security-utils.d.ts +59 -0
- package/build/object/security-utils.d.ts.map +1 -0
- package/build/object/security-utils.js +165 -0
- package/build/object/security-utils.js.map +1 -0
- package/build/object/sort-keys.d.ts +26 -0
- package/build/object/sort-keys.d.ts.map +1 -0
- package/build/object/sort-keys.js +52 -0
- package/build/object/sort-keys.js.map +1 -0
- package/build/object/types.d.ts +152 -0
- package/build/object/types.d.ts.map +1 -0
- package/build/object/types.js +6 -0
- package/build/object/types.js.map +1 -0
- package/build/string/case-conversion.d.ts +50 -0
- package/build/string/case-conversion.d.ts.map +1 -0
- package/build/string/case-conversion.js +94 -0
- package/build/string/case-conversion.js.map +1 -0
- package/build/string/formatting.d.ts +108 -0
- package/build/string/formatting.d.ts.map +1 -0
- package/build/string/formatting.js +171 -0
- package/build/string/formatting.js.map +1 -0
- package/build/string/index.d.ts +15 -0
- package/build/string/index.d.ts.map +1 -0
- package/build/string/index.js +14 -0
- package/build/string/index.js.map +1 -0
- package/build/string/string.test.d.ts +2 -0
- package/build/string/string.test.d.ts.map +1 -0
- package/build/string/string.test.js +321 -0
- package/build/string/string.test.js.map +1 -0
- package/build/string/transformation.d.ts +18 -0
- package/build/string/transformation.d.ts.map +1 -0
- package/build/string/transformation.js +32 -0
- package/build/string/transformation.js.map +1 -0
- package/build/string/types.d.ts +44 -0
- package/build/string/types.d.ts.map +1 -0
- package/build/string/types.js +2 -0
- package/build/string/types.js.map +1 -0
- package/build/string/validation.d.ts +18 -0
- package/build/string/validation.d.ts.map +1 -0
- package/build/string/validation.js +26 -0
- package/build/string/validation.js.map +1 -0
- package/build/time/elapsed-time/constants.d.ts +10 -0
- package/build/time/elapsed-time/constants.d.ts.map +1 -0
- package/build/time/elapsed-time/constants.js +96 -0
- package/build/time/elapsed-time/constants.js.map +1 -0
- package/build/time/elapsed-time/elapsed-time.d.ts +412 -0
- package/build/time/elapsed-time/elapsed-time.d.ts.map +1 -0
- package/build/time/elapsed-time/elapsed-time.js +652 -0
- package/build/time/elapsed-time/elapsed-time.js.map +1 -0
- package/build/time/elapsed-time/types.d.ts +150 -0
- package/build/time/elapsed-time/types.d.ts.map +1 -0
- package/build/time/elapsed-time/types.js +2 -0
- package/build/time/elapsed-time/types.js.map +1 -0
- package/build/time/elapsed-time/utils.d.ts +18 -0
- package/build/time/elapsed-time/utils.d.ts.map +1 -0
- package/build/time/elapsed-time/utils.js +24 -0
- package/build/time/elapsed-time/utils.js.map +1 -0
- package/build/time/index.d.ts +18 -0
- package/build/time/index.d.ts.map +1 -0
- package/build/time/index.js +17 -0
- package/build/time/index.js.map +1 -0
- package/build/time/stopwatch/entry-types.d.ts +13 -0
- package/build/time/stopwatch/entry-types.d.ts.map +1 -0
- package/build/time/stopwatch/entry-types.js +2 -0
- package/build/time/stopwatch/entry-types.js.map +1 -0
- package/build/time/stopwatch/entry.d.ts +80 -0
- package/build/time/stopwatch/entry.d.ts.map +1 -0
- package/build/time/stopwatch/entry.js +105 -0
- package/build/time/stopwatch/entry.js.map +1 -0
- package/build/time/stopwatch/stopwatch.d.ts +232 -0
- package/build/time/stopwatch/stopwatch.d.ts.map +1 -0
- package/build/time/stopwatch/stopwatch.js +315 -0
- package/build/time/stopwatch/stopwatch.js.map +1 -0
- package/build/time/time.test.d.ts +2 -0
- package/build/time/time.test.d.ts.map +1 -0
- package/build/time/time.test.js +211 -0
- package/build/time/time.test.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Groups array elements by a key generated by a provided function.
|
|
3
|
+
* @param array The array to group.
|
|
4
|
+
* @param keyFn TTransform function that returns the grouping key for each element.
|
|
5
|
+
* @returns An object with keys as group names and values as arrays of grouped elements.
|
|
6
|
+
* @example
|
|
7
|
+
* const items = [{ category: 'fruit', name: 'apple' }, { category: 'vegetable', name: 'carrot' }];
|
|
8
|
+
* const grouped = ArrayGroupBy(items, item => item.category);
|
|
9
|
+
* // grouped.fruit is [{ category: 'fruit', name: 'apple' }]
|
|
10
|
+
*/
|
|
11
|
+
export function ArrayGroupBy(array, keyFn) {
|
|
12
|
+
if (!array) {
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
return array.reduce((acc, item) => {
|
|
16
|
+
const key = keyFn(item);
|
|
17
|
+
if (!acc[key]) {
|
|
18
|
+
acc[key] = [];
|
|
19
|
+
}
|
|
20
|
+
acc[key].push(item);
|
|
21
|
+
return acc;
|
|
22
|
+
}, {});
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=array-group-by.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-group-by.js","sourceRoot":"","sources":["../../src/array/array-group-by.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAAwC,KAAU,EAAE,KAAuB;IACtG,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO,EAAoB,CAAC;IAC7B,CAAC;IAED,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;QACjC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;QACxB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACf,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QACf,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpB,OAAO,GAAG,CAAC;IACZ,CAAC,EAAE,EAAoB,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { TEqualityComparator } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the intersection of two arrays (elements present in both)
|
|
4
|
+
* Optimized O(n+m) complexity using Set-based approach
|
|
5
|
+
*
|
|
6
|
+
* @template T - The type of array elements
|
|
7
|
+
* @param array1 - First array
|
|
8
|
+
* @param array2 - Second array
|
|
9
|
+
* @param comparator - Optional custom equality comparator
|
|
10
|
+
* @returns Array containing elements present in both arrays
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* ArrayIntersection([1, 2, 3], [2, 3, 4]); // [2, 3]
|
|
15
|
+
* ArrayIntersection(
|
|
16
|
+
* [{id: 1}, {id: 2}],
|
|
17
|
+
* [{id: 2}, {id: 3}],
|
|
18
|
+
* (a, b) => a.id === b.id
|
|
19
|
+
* ); // [{id: 2}]
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @complexity O(n+m) where n and m are array lengths
|
|
23
|
+
*/
|
|
24
|
+
export declare function ArrayIntersection<T>(array1: T[], array2: T[], comparator?: TEqualityComparator<T>): T[];
|
|
25
|
+
//# sourceMappingURL=array-intersection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-intersection.d.ts","sourceRoot":"","sources":["../../src/array/array-intersection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAClC,MAAM,EAAE,CAAC,EAAE,EACX,MAAM,EAAE,CAAC,EAAE,EACX,UAAU,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,GACjC,CAAC,EAAE,CAoBL"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the intersection of two arrays (elements present in both)
|
|
3
|
+
* Optimized O(n+m) complexity using Set-based approach
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of array elements
|
|
6
|
+
* @param array1 - First array
|
|
7
|
+
* @param array2 - Second array
|
|
8
|
+
* @param comparator - Optional custom equality comparator
|
|
9
|
+
* @returns Array containing elements present in both arrays
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* ArrayIntersection([1, 2, 3], [2, 3, 4]); // [2, 3]
|
|
14
|
+
* ArrayIntersection(
|
|
15
|
+
* [{id: 1}, {id: 2}],
|
|
16
|
+
* [{id: 2}, {id: 3}],
|
|
17
|
+
* (a, b) => a.id === b.id
|
|
18
|
+
* ); // [{id: 2}]
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @complexity O(n+m) where n and m are array lengths
|
|
22
|
+
*/
|
|
23
|
+
export function ArrayIntersection(array1, array2, comparator) {
|
|
24
|
+
if (!array1 || !array2) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
// If no custom comparator, use Set for O(n+m) performance
|
|
28
|
+
if (!comparator) {
|
|
29
|
+
const set2 = new Set(array2);
|
|
30
|
+
return array1.filter(item => set2.has(item));
|
|
31
|
+
}
|
|
32
|
+
// With custom comparator, still optimize by checking smaller array
|
|
33
|
+
// This reduces comparisons from n*m to min(n,m)*max(n,m)
|
|
34
|
+
const [smaller, larger] = array1.length <= array2.length
|
|
35
|
+
? [array1, array2]
|
|
36
|
+
: [array2, array1];
|
|
37
|
+
return smaller.filter(item => larger.some(otherItem => comparator(item, otherItem)));
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=array-intersection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-intersection.js","sourceRoot":"","sources":["../../src/array/array-intersection.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,iBAAiB,CAChC,MAAW,EACX,MAAW,EACX,UAAmC;IAEnC,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QACxB,OAAO,EAAE,CAAC;IACX,CAAC;IAED,0DAA0D;IAC1D,IAAI,CAAC,UAAU,EAAE,CAAC;QACjB,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;QAC7B,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED,mEAAmE;IACnE,yDAAyD;IACzD,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM;QACvD,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC;QAClB,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEpB,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAC5B,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CACrD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { TPredicate } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Splits an array into two groups: elements that satisfy the predicate and those that do not.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of array elements
|
|
6
|
+
* @param array - The array to partition
|
|
7
|
+
* @param predicate - The condition to test each element against
|
|
8
|
+
* @returns A tuple `[matches, rest]` where `matches` passed the predicate
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const [evens, odds] = ArrayPartition([1, 2, 3, 4, 5], (n) => n % 2 === 0);
|
|
13
|
+
* // evens → [2, 4], odds → [1, 3, 5]
|
|
14
|
+
*
|
|
15
|
+
* const [admins, users] = ArrayPartition(users, (u) => u.role === 'admin');
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function ArrayPartition<T>(array: T[], predicate: TPredicate<T>): [T[], T[]];
|
|
19
|
+
//# sourceMappingURL=array-partition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-partition.d.ts","sourceRoot":"","sources":["../../src/array/array-partition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAelF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits an array into two groups: elements that satisfy the predicate and those that do not.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of array elements
|
|
5
|
+
* @param array - The array to partition
|
|
6
|
+
* @param predicate - The condition to test each element against
|
|
7
|
+
* @returns A tuple `[matches, rest]` where `matches` passed the predicate
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const [evens, odds] = ArrayPartition([1, 2, 3, 4, 5], (n) => n % 2 === 0);
|
|
12
|
+
* // evens → [2, 4], odds → [1, 3, 5]
|
|
13
|
+
*
|
|
14
|
+
* const [admins, users] = ArrayPartition(users, (u) => u.role === 'admin');
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export function ArrayPartition(array, predicate) {
|
|
18
|
+
if (!array)
|
|
19
|
+
return [[], []];
|
|
20
|
+
const matches = [];
|
|
21
|
+
const rest = [];
|
|
22
|
+
for (const item of array) {
|
|
23
|
+
if (predicate(item)) {
|
|
24
|
+
matches.push(item);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
rest.push(item);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return [matches, rest];
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=array-partition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-partition.js","sourceRoot":"","sources":["../../src/array/array-partition.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,cAAc,CAAI,KAAU,EAAE,SAAwB;IACrE,IAAI,CAAC,KAAK;QAAE,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAE5B,MAAM,OAAO,GAAQ,EAAE,CAAC;IACxB,MAAM,IAAI,GAAQ,EAAE,CAAC;IAErB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;YACrB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;IACF,CAAC;IAED,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates an array of numbers from `start` to `end` (exclusive) with an optional `step`.
|
|
3
|
+
*
|
|
4
|
+
* @param start - The first value in the range
|
|
5
|
+
* @param end - The value to stop before (exclusive)
|
|
6
|
+
* @param step - Increment between values (default: `1`; use negative for descending ranges)
|
|
7
|
+
* @returns Array of numbers
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* ArrayRange(0, 5); // [0, 1, 2, 3, 4]
|
|
12
|
+
* ArrayRange(0, 10, 2); // [0, 2, 4, 6, 8]
|
|
13
|
+
* ArrayRange(5, 0, -1); // [5, 4, 3, 2, 1]
|
|
14
|
+
* ArrayRange(0, 1, 0.5); // [0, 0.5]
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function ArrayRange(start: number, end: number, step?: number): number[];
|
|
18
|
+
//# sourceMappingURL=array-range.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-range.d.ts","sourceRoot":"","sources":["../../src/array/array-range.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,SAAI,GAAG,MAAM,EAAE,CAYzE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates an array of numbers from `start` to `end` (exclusive) with an optional `step`.
|
|
3
|
+
*
|
|
4
|
+
* @param start - The first value in the range
|
|
5
|
+
* @param end - The value to stop before (exclusive)
|
|
6
|
+
* @param step - Increment between values (default: `1`; use negative for descending ranges)
|
|
7
|
+
* @returns Array of numbers
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* ArrayRange(0, 5); // [0, 1, 2, 3, 4]
|
|
12
|
+
* ArrayRange(0, 10, 2); // [0, 2, 4, 6, 8]
|
|
13
|
+
* ArrayRange(5, 0, -1); // [5, 4, 3, 2, 1]
|
|
14
|
+
* ArrayRange(0, 1, 0.5); // [0, 0.5]
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export function ArrayRange(start, end, step = 1) {
|
|
18
|
+
if (step === 0)
|
|
19
|
+
return [];
|
|
20
|
+
if (step > 0 && start >= end)
|
|
21
|
+
return [];
|
|
22
|
+
if (step < 0 && start <= end)
|
|
23
|
+
return [];
|
|
24
|
+
const result = [];
|
|
25
|
+
for (let i = start; step > 0 ? i < end : i > end; i += step) {
|
|
26
|
+
result.push(i);
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=array-range.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-range.js","sourceRoot":"","sources":["../../src/array/array-range.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,GAAW,EAAE,IAAI,GAAG,CAAC;IAC9D,IAAI,IAAI,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAC1B,IAAI,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,EAAE,CAAC;IACxC,IAAI,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,EAAE,CAAC;IAExC,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,KAAK,IAAI,CAAC,GAAG,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC;QAC7D,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAChB,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a single random element from an array.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of array elements
|
|
5
|
+
* @param array - The array to sample from
|
|
6
|
+
* @returns A random element, or `undefined` if the array is empty
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* ArraySample([1, 2, 3, 4, 5]); // e.g. 3
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function ArraySample<T>(array: T[]): T | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Returns `n` unique random elements from an array (without replacement).
|
|
16
|
+
* If `n` exceeds the array length, all elements are returned in random order.
|
|
17
|
+
*
|
|
18
|
+
* @template T - The type of array elements
|
|
19
|
+
* @param array - The array to sample from
|
|
20
|
+
* @param n - How many elements to sample
|
|
21
|
+
* @returns An array of `n` randomly selected elements
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* ArraySample([1, 2, 3, 4, 5], 3); // e.g. [4, 1, 3]
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function ArraySample<T>(array: T[], n: number): T[];
|
|
29
|
+
//# sourceMappingURL=array-sample.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-sample.d.ts","sourceRoot":"","sources":["../../src/array/array-sample.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;AAE1D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function ArraySample(array, n) {
|
|
2
|
+
if (!array || array.length === 0) {
|
|
3
|
+
return n !== undefined ? [] : undefined;
|
|
4
|
+
}
|
|
5
|
+
if (n === undefined) {
|
|
6
|
+
return array[Math.floor(Math.random() * array.length)];
|
|
7
|
+
}
|
|
8
|
+
// Fisher-Yates partial shuffle for O(n) sampling
|
|
9
|
+
const copy = [...array];
|
|
10
|
+
const count = Math.min(n, copy.length);
|
|
11
|
+
for (let i = 0; i < count; i++) {
|
|
12
|
+
const j = i + Math.floor(Math.random() * (copy.length - i));
|
|
13
|
+
const tmp = copy[j];
|
|
14
|
+
copy[j] = copy[i];
|
|
15
|
+
copy[i] = tmp;
|
|
16
|
+
}
|
|
17
|
+
return copy.slice(0, count);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=array-sample.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-sample.js","sourceRoot":"","sources":["../../src/array/array-sample.ts"],"names":[],"mappings":"AA8BA,MAAM,UAAU,WAAW,CAAI,KAAU,EAAE,CAAU;IACpD,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACzC,CAAC;IAED,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,iDAAiD;IACjD,MAAM,IAAI,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IACxB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAEvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;QAC5D,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAM,CAAC;QACzB,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAM,CAAC;QACvB,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a shuffled copy of the array using the Fisher-Yates algorithm.
|
|
3
|
+
* @param array The array to shuffle.
|
|
4
|
+
* @returns A new shuffled array.
|
|
5
|
+
* @note Uses Math.random() — not cryptographically secure. Do not use for security-sensitive operations.
|
|
6
|
+
*/
|
|
7
|
+
export declare function ArrayShuffle<T>(array: T[]): T[];
|
|
8
|
+
//# sourceMappingURL=array-shuffle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-shuffle.d.ts","sourceRoot":"","sources":["../../src/array/array-shuffle.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAa/C"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a shuffled copy of the array using the Fisher-Yates algorithm.
|
|
3
|
+
* @param array The array to shuffle.
|
|
4
|
+
* @returns A new shuffled array.
|
|
5
|
+
* @note Uses Math.random() — not cryptographically secure. Do not use for security-sensitive operations.
|
|
6
|
+
*/
|
|
7
|
+
export function ArrayShuffle(array) {
|
|
8
|
+
if (!array)
|
|
9
|
+
return [];
|
|
10
|
+
const result = [...array];
|
|
11
|
+
for (let i = result.length - 1; i > 0; i--) {
|
|
12
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
13
|
+
const temp = result[i];
|
|
14
|
+
result[i] = result[j];
|
|
15
|
+
result[j] = temp;
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=array-shuffle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-shuffle.js","sourceRoot":"","sources":["../../src/array/array-shuffle.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAI,KAAU;IACzC,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IAEtB,MAAM,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IAE1B,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC9C,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACvB,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAM,CAAC;QAC3B,MAAM,CAAC,CAAC,CAAC,GAAG,IAAS,CAAC;IACvB,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { TTransform } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a new array sorted by the value produced by `keyFn`, without mutating the original.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of array elements
|
|
6
|
+
* @param array - The array to sort
|
|
7
|
+
* @param keyFn - Function that extracts the sort key from each element
|
|
8
|
+
* @param direction - Sort direction: `'asc'` (default) or `'desc'`
|
|
9
|
+
* @returns A sorted copy of the array
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* ArraySortBy([{ name: 'Charlie' }, { name: 'Alice' }], (u) => u.name);
|
|
14
|
+
* // [{ name: 'Alice' }, { name: 'Charlie' }]
|
|
15
|
+
*
|
|
16
|
+
* ArraySortBy([3, 1, 2], (n) => n, 'desc'); // [3, 2, 1]
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function ArraySortBy<T>(array: T[], keyFn: TTransform<T, string | number>, direction?: 'asc' | 'desc'): T[];
|
|
20
|
+
//# sourceMappingURL=array-sort-by.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-sort-by.d.ts","sourceRoot":"","sources":["../../src/array/array-sort-by.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC5B,KAAK,EAAE,CAAC,EAAE,EACV,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,EACrC,SAAS,GAAE,KAAK,GAAG,MAAc,GAC/B,CAAC,EAAE,CAWL"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a new array sorted by the value produced by `keyFn`, without mutating the original.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of array elements
|
|
5
|
+
* @param array - The array to sort
|
|
6
|
+
* @param keyFn - Function that extracts the sort key from each element
|
|
7
|
+
* @param direction - Sort direction: `'asc'` (default) or `'desc'`
|
|
8
|
+
* @returns A sorted copy of the array
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* ArraySortBy([{ name: 'Charlie' }, { name: 'Alice' }], (u) => u.name);
|
|
13
|
+
* // [{ name: 'Alice' }, { name: 'Charlie' }]
|
|
14
|
+
*
|
|
15
|
+
* ArraySortBy([3, 1, 2], (n) => n, 'desc'); // [3, 2, 1]
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function ArraySortBy(array, keyFn, direction = 'asc') {
|
|
19
|
+
if (!array)
|
|
20
|
+
return [];
|
|
21
|
+
return [...array].sort((a, b) => {
|
|
22
|
+
const keyA = keyFn(a);
|
|
23
|
+
const keyB = keyFn(b);
|
|
24
|
+
if (keyA < keyB)
|
|
25
|
+
return direction === 'asc' ? -1 : 1;
|
|
26
|
+
if (keyA > keyB)
|
|
27
|
+
return direction === 'asc' ? 1 : -1;
|
|
28
|
+
return 0;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=array-sort-by.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-sort-by.js","sourceRoot":"","sources":["../../src/array/array-sort-by.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,WAAW,CAC1B,KAAU,EACV,KAAqC,EACrC,YAA4B,KAAK;IAEjC,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IAEtB,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC/B,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAEtB,IAAI,IAAI,GAAG,IAAI;YAAE,OAAO,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACrD,IAAI,IAAI,GAAG,IAAI;YAAE,OAAO,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACrD,OAAO,CAAC,CAAC;IACV,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zips multiple arrays together, pairing elements at the same index.
|
|
3
|
+
* The result length is capped at the shortest input array.
|
|
4
|
+
*
|
|
5
|
+
* @param arrays - Two or more arrays to zip
|
|
6
|
+
* @returns Array of tuples — one tuple per index position
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* ArrayZip([1, 2, 3], ['a', 'b', 'c']); // [[1, 'a'], [2, 'b'], [3, 'c']]
|
|
11
|
+
*
|
|
12
|
+
* // Stops at shortest:
|
|
13
|
+
* ArrayZip([1, 2, 3], ['a', 'b']); // [[1, 'a'], [2, 'b']]
|
|
14
|
+
*
|
|
15
|
+
* // Three arrays:
|
|
16
|
+
* ArrayZip([1, 2], ['a', 'b'], [true, false]); // [[1, 'a', true], [2, 'b', false]]
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function ArrayZip<T extends readonly unknown[][]>(...arrays: T): {
|
|
20
|
+
[K in keyof T]: T[K] extends (infer V)[] ? V : never;
|
|
21
|
+
}[];
|
|
22
|
+
//# sourceMappingURL=array-zip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-zip.d.ts","sourceRoot":"","sources":["../../src/array/array-zip.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,EAAE,EACtD,GAAG,MAAM,EAAE,CAAC,GACV;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,KAAK;CAAE,EAAE,CAO5D"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zips multiple arrays together, pairing elements at the same index.
|
|
3
|
+
* The result length is capped at the shortest input array.
|
|
4
|
+
*
|
|
5
|
+
* @param arrays - Two or more arrays to zip
|
|
6
|
+
* @returns Array of tuples — one tuple per index position
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* ArrayZip([1, 2, 3], ['a', 'b', 'c']); // [[1, 'a'], [2, 'b'], [3, 'c']]
|
|
11
|
+
*
|
|
12
|
+
* // Stops at shortest:
|
|
13
|
+
* ArrayZip([1, 2, 3], ['a', 'b']); // [[1, 'a'], [2, 'b']]
|
|
14
|
+
*
|
|
15
|
+
* // Three arrays:
|
|
16
|
+
* ArrayZip([1, 2], ['a', 'b'], [true, false]); // [[1, 'a', true], [2, 'b', false]]
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function ArrayZip(...arrays) {
|
|
20
|
+
if (!arrays.length)
|
|
21
|
+
return [];
|
|
22
|
+
const minLen = Math.min(...arrays.map((a) => a.length));
|
|
23
|
+
return Array.from({ length: minLen }, (_, i) => arrays.map((a) => a[i]));
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=array-zip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-zip.js","sourceRoot":"","sources":["../../src/array/array-zip.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,QAAQ,CACvB,GAAG,MAAS;IAEZ,IAAI,CAAC,MAAM,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IAE9B,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IACxD,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAC9C,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACuC,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.test.d.ts","sourceRoot":"","sources":["../../src/array/array.test.ts"],"names":[],"mappings":""}
|