@ls-stack/utils 3.32.0 → 3.34.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/{lib → dist}/arrayUtils.cjs +14 -0
- package/{lib → dist}/arrayUtils.d.cts +54 -4
- package/{lib → dist}/arrayUtils.d.ts +54 -4
- package/{lib → dist}/arrayUtils.js +5 -1
- package/{lib/chunk-SRVMMYSW.js → dist/chunk-4DVTWCXL.js} +13 -1
- package/{lib/chunk-IY3KYH32.js → dist/chunk-ADM37GSC.js} +1 -1
- package/{lib/chunk-3LZQMZAS.js → dist/chunk-KW55OTUG.js} +5 -1
- package/{lib/chunk-J3ILVKZC.js → dist/chunk-XPOGWCUC.js} +1 -1
- package/{lib → dist}/concurrentCalls.js +2 -2
- package/{lib → dist}/filterObjectOrArrayKeys.js +2 -2
- package/{lib → dist}/serializeXML.cjs +1 -1
- package/{lib → dist}/serializeXML.js +2 -2
- package/{lib → dist}/stringUtils.cjs +5 -0
- package/{lib → dist}/stringUtils.d.cts +2 -1
- package/{lib → dist}/stringUtils.d.ts +2 -1
- package/{lib → dist}/stringUtils.js +3 -1
- package/{lib → dist}/testUtils.js +4 -4
- package/{lib → dist}/yamlStringify.js +2 -2
- package/docs/arrayUtils/-internal-.md +138 -0
- package/docs/arrayUtils/README.md +85 -14
- package/docs/stringUtils/README.md +20 -0
- package/package.json +2 -2
- /package/{lib → dist}/assertions.cjs +0 -0
- /package/{lib → dist}/assertions.d.cts +0 -0
- /package/{lib → dist}/assertions.d.ts +0 -0
- /package/{lib → dist}/assertions.js +0 -0
- /package/{lib → dist}/asyncQueue.cjs +0 -0
- /package/{lib → dist}/asyncQueue.d.cts +0 -0
- /package/{lib → dist}/asyncQueue.d.ts +0 -0
- /package/{lib → dist}/asyncQueue.js +0 -0
- /package/{lib → dist}/awaitDebounce.cjs +0 -0
- /package/{lib → dist}/awaitDebounce.d.cts +0 -0
- /package/{lib → dist}/awaitDebounce.d.ts +0 -0
- /package/{lib → dist}/awaitDebounce.js +0 -0
- /package/{lib → dist}/cache.cjs +0 -0
- /package/{lib → dist}/cache.d.cts +0 -0
- /package/{lib → dist}/cache.d.ts +0 -0
- /package/{lib → dist}/cache.js +0 -0
- /package/{lib → dist}/castValues.cjs +0 -0
- /package/{lib → dist}/castValues.d.cts +0 -0
- /package/{lib → dist}/castValues.d.ts +0 -0
- /package/{lib → dist}/castValues.js +0 -0
- /package/{lib → dist}/chunk-5DZT3Z5Z.js +0 -0
- /package/{lib → dist}/chunk-5MNYPLZI.js +0 -0
- /package/{lib → dist}/chunk-6FIBVC2P.js +0 -0
- /package/{lib → dist}/chunk-7CQPOM5I.js +0 -0
- /package/{lib → dist}/chunk-C2SVCIWE.js +0 -0
- /package/{lib → dist}/chunk-DFXNVEH6.js +0 -0
- /package/{lib → dist}/chunk-GHAQOUA6.js +0 -0
- /package/{lib → dist}/chunk-HTCYUMDR.js +0 -0
- /package/{lib → dist}/chunk-IATIXMCE.js +0 -0
- /package/{lib → dist}/chunk-II4R3VVX.js +0 -0
- /package/{lib → dist}/chunk-JF2MDHOJ.js +0 -0
- /package/{lib → dist}/chunk-JQFUKJU5.js +0 -0
- /package/{lib → dist}/chunk-NW5H5EW7.js +0 -0
- /package/{lib → dist}/chunk-VAAMRG4K.js +0 -0
- /package/{lib → dist}/concurrentCalls.cjs +0 -0
- /package/{lib → dist}/concurrentCalls.d.cts +0 -0
- /package/{lib → dist}/concurrentCalls.d.ts +0 -0
- /package/{lib → dist}/consoleFmt.cjs +0 -0
- /package/{lib → dist}/consoleFmt.d.cts +0 -0
- /package/{lib → dist}/consoleFmt.d.ts +0 -0
- /package/{lib → dist}/consoleFmt.js +0 -0
- /package/{lib → dist}/conversions.cjs +0 -0
- /package/{lib → dist}/conversions.d.cts +0 -0
- /package/{lib → dist}/conversions.d.ts +0 -0
- /package/{lib → dist}/conversions.js +0 -0
- /package/{lib → dist}/createThrottleController.cjs +0 -0
- /package/{lib → dist}/createThrottleController.d.cts +0 -0
- /package/{lib → dist}/createThrottleController.d.ts +0 -0
- /package/{lib → dist}/createThrottleController.js +0 -0
- /package/{lib → dist}/debounce.cjs +0 -0
- /package/{lib → dist}/debounce.d.cts +0 -0
- /package/{lib → dist}/debounce.d.ts +0 -0
- /package/{lib → dist}/debounce.js +0 -0
- /package/{lib → dist}/dedent.cjs +0 -0
- /package/{lib → dist}/dedent.d.cts +0 -0
- /package/{lib → dist}/dedent.d.ts +0 -0
- /package/{lib → dist}/dedent.js +0 -0
- /package/{lib → dist}/deepEqual.cjs +0 -0
- /package/{lib → dist}/deepEqual.d.cts +0 -0
- /package/{lib → dist}/deepEqual.d.ts +0 -0
- /package/{lib → dist}/deepEqual.js +0 -0
- /package/{lib → dist}/enhancedMap.cjs +0 -0
- /package/{lib → dist}/enhancedMap.d.cts +0 -0
- /package/{lib → dist}/enhancedMap.d.ts +0 -0
- /package/{lib → dist}/enhancedMap.js +0 -0
- /package/{lib → dist}/exhaustiveMatch.cjs +0 -0
- /package/{lib → dist}/exhaustiveMatch.d.cts +0 -0
- /package/{lib → dist}/exhaustiveMatch.d.ts +0 -0
- /package/{lib → dist}/exhaustiveMatch.js +0 -0
- /package/{lib → dist}/filterObjectOrArrayKeys.cjs +0 -0
- /package/{lib → dist}/filterObjectOrArrayKeys.d.cts +0 -0
- /package/{lib → dist}/filterObjectOrArrayKeys.d.ts +0 -0
- /package/{lib → dist}/getAutoIncrementId.cjs +0 -0
- /package/{lib → dist}/getAutoIncrementId.d.cts +0 -0
- /package/{lib → dist}/getAutoIncrementId.d.ts +0 -0
- /package/{lib → dist}/getAutoIncrementId.js +0 -0
- /package/{lib → dist}/getCompositeKey.cjs +0 -0
- /package/{lib → dist}/getCompositeKey.d.cts +0 -0
- /package/{lib → dist}/getCompositeKey.d.ts +0 -0
- /package/{lib → dist}/getCompositeKey.js +0 -0
- /package/{lib → dist}/getValueStableKey.cjs +0 -0
- /package/{lib → dist}/getValueStableKey.d.cts +0 -0
- /package/{lib → dist}/getValueStableKey.d.ts +0 -0
- /package/{lib → dist}/getValueStableKey.js +0 -0
- /package/{lib → dist}/hash.cjs +0 -0
- /package/{lib → dist}/hash.d.cts +0 -0
- /package/{lib → dist}/hash.d.ts +0 -0
- /package/{lib → dist}/hash.js +0 -0
- /package/{lib → dist}/interpolate.cjs +0 -0
- /package/{lib → dist}/interpolate.d.cts +0 -0
- /package/{lib → dist}/interpolate.d.ts +0 -0
- /package/{lib → dist}/interpolate.js +0 -0
- /package/{lib → dist}/levenshtein.cjs +0 -0
- /package/{lib → dist}/levenshtein.d.cts +0 -0
- /package/{lib → dist}/levenshtein.d.ts +0 -0
- /package/{lib → dist}/levenshtein.js +0 -0
- /package/{lib → dist}/main.cjs +0 -0
- /package/{lib → dist}/main.d.cts +0 -0
- /package/{lib → dist}/main.d.ts +0 -0
- /package/{lib → dist}/main.js +0 -0
- /package/{lib → dist}/mathUtils.cjs +0 -0
- /package/{lib → dist}/mathUtils.d.cts +0 -0
- /package/{lib → dist}/mathUtils.d.ts +0 -0
- /package/{lib → dist}/mathUtils.js +0 -0
- /package/{lib → dist}/objUtils.cjs +0 -0
- /package/{lib → dist}/objUtils.d.cts +0 -0
- /package/{lib → dist}/objUtils.d.ts +0 -0
- /package/{lib → dist}/objUtils.js +0 -0
- /package/{lib → dist}/parallelAsyncCalls.cjs +0 -0
- /package/{lib → dist}/parallelAsyncCalls.d.cts +0 -0
- /package/{lib → dist}/parallelAsyncCalls.d.ts +0 -0
- /package/{lib → dist}/parallelAsyncCalls.js +0 -0
- /package/{lib → dist}/promiseUtils.cjs +0 -0
- /package/{lib → dist}/promiseUtils.d.cts +0 -0
- /package/{lib → dist}/promiseUtils.d.ts +0 -0
- /package/{lib → dist}/promiseUtils.js +0 -0
- /package/{lib → dist}/retryOnError.cjs +0 -0
- /package/{lib → dist}/retryOnError.d.cts +0 -0
- /package/{lib → dist}/retryOnError.d.ts +0 -0
- /package/{lib → dist}/retryOnError.js +0 -0
- /package/{lib → dist}/runShellCmd.cjs +0 -0
- /package/{lib → dist}/runShellCmd.d.cts +0 -0
- /package/{lib → dist}/runShellCmd.d.ts +0 -0
- /package/{lib → dist}/runShellCmd.js +0 -0
- /package/{lib → dist}/safeJson.cjs +0 -0
- /package/{lib → dist}/safeJson.d.cts +0 -0
- /package/{lib → dist}/safeJson.d.ts +0 -0
- /package/{lib → dist}/safeJson.js +0 -0
- /package/{lib → dist}/saferTyping.cjs +0 -0
- /package/{lib → dist}/saferTyping.d.cts +0 -0
- /package/{lib → dist}/saferTyping.d.ts +0 -0
- /package/{lib → dist}/saferTyping.js +0 -0
- /package/{lib → dist}/serializeXML.d.cts +0 -0
- /package/{lib → dist}/serializeXML.d.ts +0 -0
- /package/{lib → dist}/shallowEqual.cjs +0 -0
- /package/{lib → dist}/shallowEqual.d.cts +0 -0
- /package/{lib → dist}/shallowEqual.d.ts +0 -0
- /package/{lib → dist}/shallowEqual.js +0 -0
- /package/{lib → dist}/sleep.cjs +0 -0
- /package/{lib → dist}/sleep.d.cts +0 -0
- /package/{lib → dist}/sleep.d.ts +0 -0
- /package/{lib → dist}/sleep.js +0 -0
- /package/{lib → dist}/testUtils.cjs +0 -0
- /package/{lib → dist}/testUtils.d.cts +0 -0
- /package/{lib → dist}/testUtils.d.ts +0 -0
- /package/{lib → dist}/throttle.cjs +0 -0
- /package/{lib → dist}/throttle.d.cts +0 -0
- /package/{lib → dist}/throttle.d.ts +0 -0
- /package/{lib → dist}/throttle.js +0 -0
- /package/{lib → dist}/time.cjs +0 -0
- /package/{lib → dist}/time.d.cts +0 -0
- /package/{lib → dist}/time.d.ts +0 -0
- /package/{lib → dist}/time.js +0 -0
- /package/{lib → dist}/timers.cjs +0 -0
- /package/{lib → dist}/timers.d.cts +0 -0
- /package/{lib → dist}/timers.d.ts +0 -0
- /package/{lib → dist}/timers.js +0 -0
- /package/{lib → dist}/tsResult.cjs +0 -0
- /package/{lib → dist}/tsResult.d.cts +0 -0
- /package/{lib → dist}/tsResult.d.ts +0 -0
- /package/{lib → dist}/tsResult.js +0 -0
- /package/{lib → dist}/typeGuards.cjs +0 -0
- /package/{lib → dist}/typeGuards.d.cts +0 -0
- /package/{lib → dist}/typeGuards.d.ts +0 -0
- /package/{lib → dist}/typeGuards.js +0 -0
- /package/{lib → dist}/typeUtils.cjs +0 -0
- /package/{lib → dist}/typeUtils.d.cts +0 -0
- /package/{lib → dist}/typeUtils.d.ts +0 -0
- /package/{lib → dist}/typeUtils.js +0 -0
- /package/{lib → dist}/typingFnUtils.cjs +0 -0
- /package/{lib → dist}/typingFnUtils.d.cts +0 -0
- /package/{lib → dist}/typingFnUtils.d.ts +0 -0
- /package/{lib → dist}/typingFnUtils.js +0 -0
- /package/{lib → dist}/typingTestUtils.cjs +0 -0
- /package/{lib → dist}/typingTestUtils.d.cts +0 -0
- /package/{lib → dist}/typingTestUtils.d.ts +0 -0
- /package/{lib → dist}/typingTestUtils.js +0 -0
- /package/{lib → dist}/typingUtils.cjs +0 -0
- /package/{lib → dist}/typingUtils.d.cts +0 -0
- /package/{lib → dist}/typingUtils.d.ts +0 -0
- /package/{lib → dist}/typingUtils.js +0 -0
- /package/{lib → dist}/yamlStringify.cjs +0 -0
- /package/{lib → dist}/yamlStringify.d.cts +0 -0
- /package/{lib → dist}/yamlStringify.d.ts +0 -0
|
@@ -20,11 +20,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/arrayUtils.ts
|
|
21
21
|
var arrayUtils_exports = {};
|
|
22
22
|
__export(arrayUtils_exports, {
|
|
23
|
+
arrayOps: () => arrayOps,
|
|
23
24
|
arrayWithPrev: () => arrayWithPrev,
|
|
24
25
|
arrayWithPrevAndIndex: () => arrayWithPrevAndIndex,
|
|
25
26
|
filterAndMap: () => filterAndMap,
|
|
26
27
|
findAfterIndex: () => findAfterIndex,
|
|
27
28
|
findBeforeIndex: () => findBeforeIndex,
|
|
29
|
+
getAscIndexOrder: () => getAscIndexOrder,
|
|
28
30
|
hasDuplicates: () => hasDuplicates,
|
|
29
31
|
isInArray: () => isInArray,
|
|
30
32
|
rejectArrayUndefinedValues: () => rejectArrayUndefinedValues,
|
|
@@ -79,6 +81,9 @@ function sortBy(arr, sortByValue, props = "asc") {
|
|
|
79
81
|
return 0;
|
|
80
82
|
});
|
|
81
83
|
}
|
|
84
|
+
function getAscIndexOrder(index) {
|
|
85
|
+
return index === -1 ? Infinity : index ?? Infinity;
|
|
86
|
+
}
|
|
82
87
|
function arrayWithPrev(array) {
|
|
83
88
|
return array.map((item, i) => [item, array[i - 1] ?? null]);
|
|
84
89
|
}
|
|
@@ -155,13 +160,22 @@ function truncateArray(array, maxLength, appendIfTruncated) {
|
|
|
155
160
|
}
|
|
156
161
|
return result;
|
|
157
162
|
}
|
|
163
|
+
function arrayOps(array) {
|
|
164
|
+
return {
|
|
165
|
+
filterAndMap: (mapFilter) => filterAndMap(array, mapFilter),
|
|
166
|
+
sortBy: (sortByValue, props) => sortBy(array, sortByValue, props),
|
|
167
|
+
rejectDuplicates: (getKey) => rejectDuplicates(array, getKey)
|
|
168
|
+
};
|
|
169
|
+
}
|
|
158
170
|
// Annotate the CommonJS export names for ESM import in node:
|
|
159
171
|
0 && (module.exports = {
|
|
172
|
+
arrayOps,
|
|
160
173
|
arrayWithPrev,
|
|
161
174
|
arrayWithPrevAndIndex,
|
|
162
175
|
filterAndMap,
|
|
163
176
|
findAfterIndex,
|
|
164
177
|
findBeforeIndex,
|
|
178
|
+
getAscIndexOrder,
|
|
165
179
|
hasDuplicates,
|
|
166
180
|
isInArray,
|
|
167
181
|
rejectArrayUndefinedValues,
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
declare function filterAndMap<T, R>(array: IterableIterator<T> | readonly T[], mapFilter: (item: T, index: number) => false | R): R[];
|
|
22
22
|
type FilterAndMapReturn<T> = false | T;
|
|
23
23
|
type SortOrder = 'desc' | 'asc';
|
|
24
|
+
type SortByValue<T> = (item: T) => (number | string)[] | number | string;
|
|
25
|
+
type SortByProps = {
|
|
26
|
+
order?: SortOrder | SortOrder[];
|
|
27
|
+
} | SortOrder | SortOrder[];
|
|
24
28
|
/**
|
|
25
29
|
* Sort an array based on a value
|
|
26
30
|
*
|
|
@@ -42,9 +46,25 @@ type SortOrder = 'desc' | 'asc';
|
|
|
42
46
|
* // return a array to sort by multiple values
|
|
43
47
|
* const sortedItems = sortBy(items, (item) => [item.a, item.b]);
|
|
44
48
|
*/
|
|
45
|
-
declare function sortBy<T>(arr: T[], sortByValue:
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
declare function sortBy<T>(arr: T[], sortByValue: SortByValue<T>, props?: SortByProps): T[];
|
|
50
|
+
/**
|
|
51
|
+
* Get the correct 0 based value for sync with other array in ascending order
|
|
52
|
+
*
|
|
53
|
+
* @param index
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const items = [1, 2, 3];
|
|
58
|
+
*
|
|
59
|
+
* const index = sortBy(
|
|
60
|
+
* items,
|
|
61
|
+
* (item) => getAscIndexOrder(
|
|
62
|
+
* followOrder.findIndex((order) => order === item)
|
|
63
|
+
* )
|
|
64
|
+
* );
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
declare function getAscIndexOrder(index: number | undefined): number;
|
|
48
68
|
declare function arrayWithPrev<T>(array: T[]): [current: T, prev: T | null][];
|
|
49
69
|
declare function arrayWithPrevAndIndex<T>(array: T[]): {
|
|
50
70
|
item: T;
|
|
@@ -58,5 +78,35 @@ declare function rejectArrayUndefinedValues<T extends unknown[]>(array: T): T;
|
|
|
58
78
|
declare function hasDuplicates<T>(array: T[], getKey?: (item: T) => unknown): boolean;
|
|
59
79
|
declare function rejectDuplicates<T>(array: T[], getKey?: (item: T) => unknown): T[];
|
|
60
80
|
declare function truncateArray<T>(array: T[], maxLength: number, appendIfTruncated?: T | ((truncatedCount: number) => T)): T[];
|
|
81
|
+
type ArrayOps<T> = {
|
|
82
|
+
/**
|
|
83
|
+
* Filter and map an array
|
|
84
|
+
*
|
|
85
|
+
* @param mapFilter - A function that takes an item and returns a value or `false`
|
|
86
|
+
* to reject the item.
|
|
87
|
+
* @example
|
|
88
|
+
* const items = [1, 2, 3];
|
|
89
|
+
*
|
|
90
|
+
* const enhancedItems = arrayOps(items);
|
|
91
|
+
*
|
|
92
|
+
* enhancedItems.filterAndMap((item) => item === 2 ? false : item);
|
|
93
|
+
*/
|
|
94
|
+
filterAndMap: <R>(mapFilter: (item: T, index: number) => false | R) => R[];
|
|
95
|
+
sortBy: (sortByValue: SortByValue<T>, props: SortByProps) => T[];
|
|
96
|
+
rejectDuplicates: (getKey: (item: T) => unknown) => T[];
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Enhance an array with extra methods
|
|
100
|
+
*
|
|
101
|
+
* @param array
|
|
102
|
+
* @example
|
|
103
|
+
*
|
|
104
|
+
* const enhancedItems = arrayOps(array);
|
|
105
|
+
*
|
|
106
|
+
* enhancedItems.filterAndMap((item) => item === 2 ? false : item);
|
|
107
|
+
* enhancedItems.sortBy((item) => item);
|
|
108
|
+
* enhancedItems.rejectDuplicates((item) => item);
|
|
109
|
+
*/
|
|
110
|
+
declare function arrayOps<T>(array: T[]): ArrayOps<T>;
|
|
61
111
|
|
|
62
|
-
export { type FilterAndMapReturn, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findBeforeIndex, hasDuplicates, isInArray, rejectArrayUndefinedValues, rejectDuplicates, sortBy, truncateArray };
|
|
112
|
+
export { type FilterAndMapReturn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findBeforeIndex, getAscIndexOrder, hasDuplicates, isInArray, rejectArrayUndefinedValues, rejectDuplicates, sortBy, truncateArray };
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
declare function filterAndMap<T, R>(array: IterableIterator<T> | readonly T[], mapFilter: (item: T, index: number) => false | R): R[];
|
|
22
22
|
type FilterAndMapReturn<T> = false | T;
|
|
23
23
|
type SortOrder = 'desc' | 'asc';
|
|
24
|
+
type SortByValue<T> = (item: T) => (number | string)[] | number | string;
|
|
25
|
+
type SortByProps = {
|
|
26
|
+
order?: SortOrder | SortOrder[];
|
|
27
|
+
} | SortOrder | SortOrder[];
|
|
24
28
|
/**
|
|
25
29
|
* Sort an array based on a value
|
|
26
30
|
*
|
|
@@ -42,9 +46,25 @@ type SortOrder = 'desc' | 'asc';
|
|
|
42
46
|
* // return a array to sort by multiple values
|
|
43
47
|
* const sortedItems = sortBy(items, (item) => [item.a, item.b]);
|
|
44
48
|
*/
|
|
45
|
-
declare function sortBy<T>(arr: T[], sortByValue:
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
declare function sortBy<T>(arr: T[], sortByValue: SortByValue<T>, props?: SortByProps): T[];
|
|
50
|
+
/**
|
|
51
|
+
* Get the correct 0 based value for sync with other array in ascending order
|
|
52
|
+
*
|
|
53
|
+
* @param index
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const items = [1, 2, 3];
|
|
58
|
+
*
|
|
59
|
+
* const index = sortBy(
|
|
60
|
+
* items,
|
|
61
|
+
* (item) => getAscIndexOrder(
|
|
62
|
+
* followOrder.findIndex((order) => order === item)
|
|
63
|
+
* )
|
|
64
|
+
* );
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
declare function getAscIndexOrder(index: number | undefined): number;
|
|
48
68
|
declare function arrayWithPrev<T>(array: T[]): [current: T, prev: T | null][];
|
|
49
69
|
declare function arrayWithPrevAndIndex<T>(array: T[]): {
|
|
50
70
|
item: T;
|
|
@@ -58,5 +78,35 @@ declare function rejectArrayUndefinedValues<T extends unknown[]>(array: T): T;
|
|
|
58
78
|
declare function hasDuplicates<T>(array: T[], getKey?: (item: T) => unknown): boolean;
|
|
59
79
|
declare function rejectDuplicates<T>(array: T[], getKey?: (item: T) => unknown): T[];
|
|
60
80
|
declare function truncateArray<T>(array: T[], maxLength: number, appendIfTruncated?: T | ((truncatedCount: number) => T)): T[];
|
|
81
|
+
type ArrayOps<T> = {
|
|
82
|
+
/**
|
|
83
|
+
* Filter and map an array
|
|
84
|
+
*
|
|
85
|
+
* @param mapFilter - A function that takes an item and returns a value or `false`
|
|
86
|
+
* to reject the item.
|
|
87
|
+
* @example
|
|
88
|
+
* const items = [1, 2, 3];
|
|
89
|
+
*
|
|
90
|
+
* const enhancedItems = arrayOps(items);
|
|
91
|
+
*
|
|
92
|
+
* enhancedItems.filterAndMap((item) => item === 2 ? false : item);
|
|
93
|
+
*/
|
|
94
|
+
filterAndMap: <R>(mapFilter: (item: T, index: number) => false | R) => R[];
|
|
95
|
+
sortBy: (sortByValue: SortByValue<T>, props: SortByProps) => T[];
|
|
96
|
+
rejectDuplicates: (getKey: (item: T) => unknown) => T[];
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Enhance an array with extra methods
|
|
100
|
+
*
|
|
101
|
+
* @param array
|
|
102
|
+
* @example
|
|
103
|
+
*
|
|
104
|
+
* const enhancedItems = arrayOps(array);
|
|
105
|
+
*
|
|
106
|
+
* enhancedItems.filterAndMap((item) => item === 2 ? false : item);
|
|
107
|
+
* enhancedItems.sortBy((item) => item);
|
|
108
|
+
* enhancedItems.rejectDuplicates((item) => item);
|
|
109
|
+
*/
|
|
110
|
+
declare function arrayOps<T>(array: T[]): ArrayOps<T>;
|
|
61
111
|
|
|
62
|
-
export { type FilterAndMapReturn, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findBeforeIndex, hasDuplicates, isInArray, rejectArrayUndefinedValues, rejectDuplicates, sortBy, truncateArray };
|
|
112
|
+
export { type FilterAndMapReturn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findBeforeIndex, getAscIndexOrder, hasDuplicates, isInArray, rejectArrayUndefinedValues, rejectDuplicates, sortBy, truncateArray };
|
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
|
+
arrayOps,
|
|
2
3
|
arrayWithPrev,
|
|
3
4
|
arrayWithPrevAndIndex,
|
|
4
5
|
filterAndMap,
|
|
5
6
|
findAfterIndex,
|
|
6
7
|
findBeforeIndex,
|
|
8
|
+
getAscIndexOrder,
|
|
7
9
|
hasDuplicates,
|
|
8
10
|
isInArray,
|
|
9
11
|
rejectArrayUndefinedValues,
|
|
10
12
|
rejectDuplicates,
|
|
11
13
|
sortBy,
|
|
12
14
|
truncateArray
|
|
13
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-4DVTWCXL.js";
|
|
14
16
|
import "./chunk-C2SVCIWE.js";
|
|
15
17
|
import "./chunk-JF2MDHOJ.js";
|
|
16
18
|
export {
|
|
19
|
+
arrayOps,
|
|
17
20
|
arrayWithPrev,
|
|
18
21
|
arrayWithPrevAndIndex,
|
|
19
22
|
filterAndMap,
|
|
20
23
|
findAfterIndex,
|
|
21
24
|
findBeforeIndex,
|
|
25
|
+
getAscIndexOrder,
|
|
22
26
|
hasDuplicates,
|
|
23
27
|
isInArray,
|
|
24
28
|
rejectArrayUndefinedValues,
|
|
@@ -39,6 +39,9 @@ function sortBy(arr, sortByValue, props = "asc") {
|
|
|
39
39
|
return 0;
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
+
function getAscIndexOrder(index) {
|
|
43
|
+
return index === -1 ? Infinity : index ?? Infinity;
|
|
44
|
+
}
|
|
42
45
|
function arrayWithPrev(array) {
|
|
43
46
|
return array.map((item, i) => [item, array[i - 1] ?? null]);
|
|
44
47
|
}
|
|
@@ -115,10 +118,18 @@ function truncateArray(array, maxLength, appendIfTruncated) {
|
|
|
115
118
|
}
|
|
116
119
|
return result;
|
|
117
120
|
}
|
|
121
|
+
function arrayOps(array) {
|
|
122
|
+
return {
|
|
123
|
+
filterAndMap: (mapFilter) => filterAndMap(array, mapFilter),
|
|
124
|
+
sortBy: (sortByValue, props) => sortBy(array, sortByValue, props),
|
|
125
|
+
rejectDuplicates: (getKey) => rejectDuplicates(array, getKey)
|
|
126
|
+
};
|
|
127
|
+
}
|
|
118
128
|
|
|
119
129
|
export {
|
|
120
130
|
filterAndMap,
|
|
121
131
|
sortBy,
|
|
132
|
+
getAscIndexOrder,
|
|
122
133
|
arrayWithPrev,
|
|
123
134
|
arrayWithPrevAndIndex,
|
|
124
135
|
isInArray,
|
|
@@ -127,5 +138,6 @@ export {
|
|
|
127
138
|
rejectArrayUndefinedValues,
|
|
128
139
|
hasDuplicates,
|
|
129
140
|
rejectDuplicates,
|
|
130
|
-
truncateArray
|
|
141
|
+
truncateArray,
|
|
142
|
+
arrayOps
|
|
131
143
|
};
|
|
@@ -42,6 +42,9 @@ function truncateString(str, length, ellipsis = "\u2026") {
|
|
|
42
42
|
if (str.length <= length) return str;
|
|
43
43
|
return str.slice(0, length - 1) + ellipsis;
|
|
44
44
|
}
|
|
45
|
+
function removeANSIColors(str) {
|
|
46
|
+
return str.replace(/\u001b\[\d+m/g, "");
|
|
47
|
+
}
|
|
45
48
|
|
|
46
49
|
export {
|
|
47
50
|
concatStrings,
|
|
@@ -53,5 +56,6 @@ export {
|
|
|
53
56
|
convertToCamelCase,
|
|
54
57
|
convertToSentenceCase,
|
|
55
58
|
convertToTitleCase,
|
|
56
|
-
truncateString
|
|
59
|
+
truncateString,
|
|
60
|
+
removeANSIColors
|
|
57
61
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
truncateString
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KW55OTUG.js";
|
|
4
4
|
import {
|
|
5
5
|
sleep
|
|
6
6
|
} from "./chunk-5DZT3Z5Z.js";
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from "./chunk-VAAMRG4K.js";
|
|
10
10
|
import {
|
|
11
11
|
truncateArray
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-4DVTWCXL.js";
|
|
13
13
|
import {
|
|
14
14
|
invariant
|
|
15
15
|
} from "./chunk-C2SVCIWE.js";
|
|
@@ -69,7 +69,7 @@ function serializeXML(node, options) {
|
|
|
69
69
|
function serializeWithLevel(node, options = {}, level) {
|
|
70
70
|
const {
|
|
71
71
|
indent,
|
|
72
|
-
escapeText: globalEscapeText =
|
|
72
|
+
escapeText: globalEscapeText = false,
|
|
73
73
|
validateTagName = true,
|
|
74
74
|
invalidNodes = "throw"
|
|
75
75
|
} = options;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
filterAndMap
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4DVTWCXL.js";
|
|
4
4
|
import "./chunk-C2SVCIWE.js";
|
|
5
5
|
import {
|
|
6
6
|
isTruthy
|
|
@@ -32,7 +32,7 @@ function serializeXML(node, options) {
|
|
|
32
32
|
function serializeWithLevel(node, options = {}, level) {
|
|
33
33
|
const {
|
|
34
34
|
indent,
|
|
35
|
-
escapeText: globalEscapeText =
|
|
35
|
+
escapeText: globalEscapeText = false,
|
|
36
36
|
validateTagName = true,
|
|
37
37
|
invalidNodes = "throw"
|
|
38
38
|
} = options;
|
|
@@ -29,6 +29,7 @@ __export(stringUtils_exports, {
|
|
|
29
29
|
formatNum: () => formatNum,
|
|
30
30
|
isSnakeCase: () => isSnakeCase,
|
|
31
31
|
joinStrings: () => joinStrings,
|
|
32
|
+
removeANSIColors: () => removeANSIColors,
|
|
32
33
|
truncateString: () => truncateString
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(stringUtils_exports);
|
|
@@ -75,6 +76,9 @@ function truncateString(str, length, ellipsis = "\u2026") {
|
|
|
75
76
|
if (str.length <= length) return str;
|
|
76
77
|
return str.slice(0, length - 1) + ellipsis;
|
|
77
78
|
}
|
|
79
|
+
function removeANSIColors(str) {
|
|
80
|
+
return str.replace(/\u001b\[\d+m/g, "");
|
|
81
|
+
}
|
|
78
82
|
// Annotate the CommonJS export names for ESM import in node:
|
|
79
83
|
0 && (module.exports = {
|
|
80
84
|
concatStrings,
|
|
@@ -86,5 +90,6 @@ function truncateString(str, length, ellipsis = "\u2026") {
|
|
|
86
90
|
formatNum,
|
|
87
91
|
isSnakeCase,
|
|
88
92
|
joinStrings,
|
|
93
|
+
removeANSIColors,
|
|
89
94
|
truncateString
|
|
90
95
|
});
|
|
@@ -21,5 +21,6 @@ declare function convertToCamelCase(str: string): string;
|
|
|
21
21
|
declare function convertToSentenceCase(str: string): string;
|
|
22
22
|
declare function convertToTitleCase(str: string): string;
|
|
23
23
|
declare function truncateString(str: string, length: number, ellipsis?: string): string;
|
|
24
|
+
declare function removeANSIColors(str: string): string;
|
|
24
25
|
|
|
25
|
-
export { concatStrings, convertToCamelCase, convertToPascalCase, convertToSentenceCase, convertToSnakeCase, convertToTitleCase, formatNum, isSnakeCase, joinStrings, truncateString };
|
|
26
|
+
export { concatStrings, convertToCamelCase, convertToPascalCase, convertToSentenceCase, convertToSnakeCase, convertToTitleCase, formatNum, isSnakeCase, joinStrings, removeANSIColors, truncateString };
|
|
@@ -21,5 +21,6 @@ declare function convertToCamelCase(str: string): string;
|
|
|
21
21
|
declare function convertToSentenceCase(str: string): string;
|
|
22
22
|
declare function convertToTitleCase(str: string): string;
|
|
23
23
|
declare function truncateString(str: string, length: number, ellipsis?: string): string;
|
|
24
|
+
declare function removeANSIColors(str: string): string;
|
|
24
25
|
|
|
25
|
-
export { concatStrings, convertToCamelCase, convertToPascalCase, convertToSentenceCase, convertToSnakeCase, convertToTitleCase, formatNum, isSnakeCase, joinStrings, truncateString };
|
|
26
|
+
export { concatStrings, convertToCamelCase, convertToPascalCase, convertToSentenceCase, convertToSnakeCase, convertToTitleCase, formatNum, isSnakeCase, joinStrings, removeANSIColors, truncateString };
|
|
@@ -8,8 +8,9 @@ import {
|
|
|
8
8
|
formatNum,
|
|
9
9
|
isSnakeCase,
|
|
10
10
|
joinStrings,
|
|
11
|
+
removeANSIColors,
|
|
11
12
|
truncateString
|
|
12
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-KW55OTUG.js";
|
|
13
14
|
export {
|
|
14
15
|
concatStrings,
|
|
15
16
|
convertToCamelCase,
|
|
@@ -20,5 +21,6 @@ export {
|
|
|
20
21
|
formatNum,
|
|
21
22
|
isSnakeCase,
|
|
22
23
|
joinStrings,
|
|
24
|
+
removeANSIColors,
|
|
23
25
|
truncateString
|
|
24
26
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
yamlStringify
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ADM37GSC.js";
|
|
4
4
|
import {
|
|
5
5
|
omit,
|
|
6
6
|
pick
|
|
@@ -11,18 +11,18 @@ import {
|
|
|
11
11
|
} from "./chunk-JQFUKJU5.js";
|
|
12
12
|
import {
|
|
13
13
|
filterObjectOrArrayKeys
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-XPOGWCUC.js";
|
|
15
15
|
import {
|
|
16
16
|
defer
|
|
17
17
|
} from "./chunk-DFXNVEH6.js";
|
|
18
18
|
import {
|
|
19
19
|
clampMin
|
|
20
20
|
} from "./chunk-HTCYUMDR.js";
|
|
21
|
-
import "./chunk-
|
|
21
|
+
import "./chunk-KW55OTUG.js";
|
|
22
22
|
import {
|
|
23
23
|
arrayWithPrevAndIndex,
|
|
24
24
|
filterAndMap
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-4DVTWCXL.js";
|
|
26
26
|
import {
|
|
27
27
|
isObject
|
|
28
28
|
} from "./chunk-C2SVCIWE.js";
|
|
@@ -8,6 +8,144 @@
|
|
|
8
8
|
|
|
9
9
|
## Type Aliases
|
|
10
10
|
|
|
11
|
+
### ArrayOps\<T\>
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
type ArrayOps<T> = object;
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Defined in: [packages/utils/src/arrayUtils.ts:259](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L259)
|
|
18
|
+
|
|
19
|
+
#### Type Parameters
|
|
20
|
+
|
|
21
|
+
##### T
|
|
22
|
+
|
|
23
|
+
`T`
|
|
24
|
+
|
|
25
|
+
#### Properties
|
|
26
|
+
|
|
27
|
+
##### filterAndMap()
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
filterAndMap: <R>(mapFilter) => R[];
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Defined in: [packages/utils/src/arrayUtils.ts:272](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L272)
|
|
34
|
+
|
|
35
|
+
Filter and map an array
|
|
36
|
+
|
|
37
|
+
###### Type Parameters
|
|
38
|
+
|
|
39
|
+
###### R
|
|
40
|
+
|
|
41
|
+
`R`
|
|
42
|
+
|
|
43
|
+
###### Parameters
|
|
44
|
+
|
|
45
|
+
###### mapFilter
|
|
46
|
+
|
|
47
|
+
(`item`, `index`) => `false` \| `R`
|
|
48
|
+
|
|
49
|
+
A function that takes an item and returns a value or `false`
|
|
50
|
+
to reject the item.
|
|
51
|
+
|
|
52
|
+
###### Returns
|
|
53
|
+
|
|
54
|
+
`R`[]
|
|
55
|
+
|
|
56
|
+
###### Example
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
const items = [1, 2, 3];
|
|
60
|
+
|
|
61
|
+
const enhancedItems = arrayOps(items);
|
|
62
|
+
|
|
63
|
+
enhancedItems.filterAndMap((item) => item === 2 ? false : item);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
##### rejectDuplicates()
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
rejectDuplicates: (getKey) => T[];
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Defined in: [packages/utils/src/arrayUtils.ts:274](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L274)
|
|
73
|
+
|
|
74
|
+
###### Parameters
|
|
75
|
+
|
|
76
|
+
###### getKey
|
|
77
|
+
|
|
78
|
+
(`item`) => `unknown`
|
|
79
|
+
|
|
80
|
+
###### Returns
|
|
81
|
+
|
|
82
|
+
`T`[]
|
|
83
|
+
|
|
84
|
+
##### sortBy()
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
sortBy: (sortByValue, props) => T[];
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Defined in: [packages/utils/src/arrayUtils.ts:273](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L273)
|
|
91
|
+
|
|
92
|
+
###### Parameters
|
|
93
|
+
|
|
94
|
+
###### sortByValue
|
|
95
|
+
|
|
96
|
+
[`SortByValue`](#sortbyvalue)\<`T`\>
|
|
97
|
+
|
|
98
|
+
###### props
|
|
99
|
+
|
|
100
|
+
[`SortByProps`](#sortbyprops)
|
|
101
|
+
|
|
102
|
+
###### Returns
|
|
103
|
+
|
|
104
|
+
`T`[]
|
|
105
|
+
|
|
106
|
+
***
|
|
107
|
+
|
|
108
|
+
### SortByProps
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
type SortByProps =
|
|
112
|
+
| {
|
|
113
|
+
order?: SortOrder | SortOrder[];
|
|
114
|
+
}
|
|
115
|
+
| SortOrder
|
|
116
|
+
| SortOrder[];
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Defined in: [packages/utils/src/arrayUtils.ts:48](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L48)
|
|
120
|
+
|
|
121
|
+
***
|
|
122
|
+
|
|
123
|
+
### SortByValue()\<T\>
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
type SortByValue<T> = (item) => (number | string)[] | number | string;
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Defined in: [packages/utils/src/arrayUtils.ts:46](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L46)
|
|
130
|
+
|
|
131
|
+
#### Type Parameters
|
|
132
|
+
|
|
133
|
+
##### T
|
|
134
|
+
|
|
135
|
+
`T`
|
|
136
|
+
|
|
137
|
+
#### Parameters
|
|
138
|
+
|
|
139
|
+
##### item
|
|
140
|
+
|
|
141
|
+
`T`
|
|
142
|
+
|
|
143
|
+
#### Returns
|
|
144
|
+
|
|
145
|
+
(`number` \| `string`)[] \| `number` \| `string`
|
|
146
|
+
|
|
147
|
+
***
|
|
148
|
+
|
|
11
149
|
### SortOrder
|
|
12
150
|
|
|
13
151
|
```ts
|