complete-common 2.11.0 → 2.12.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/dist/functions/array.d.cts +20 -0
- package/dist/functions/array.d.mts +20 -0
- package/dist/functions/array.d.ts +20 -0
- package/dist/functions/array.d.ts.map +1 -1
- package/dist/index.cjs +6 -0
- package/dist/index.mjs +6 -1
- package/package.json +5 -5
- package/src/functions/array.ts +28 -0
|
@@ -63,6 +63,26 @@ export declare function emptyArray(array: unknown[]): void;
|
|
|
63
63
|
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
64
64
|
*/
|
|
65
65
|
export declare function filterMap<OldT, NewT>(array: readonly OldT[], func: (element: OldT) => NewT | undefined): readonly NewT[];
|
|
66
|
+
/**
|
|
67
|
+
* Helper function to perform a filter and a map at the same time. Similar to `Array.map`, provide a
|
|
68
|
+
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
69
|
+
* this function cannot be used in situations where `undefined` can be a valid array element.)
|
|
70
|
+
*
|
|
71
|
+
* This function is useful because the `Array.map` method will always produce an array with the same
|
|
72
|
+
* amount of elements as the original array.
|
|
73
|
+
*
|
|
74
|
+
* This is named `filterMap` after the Rust function:
|
|
75
|
+
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
76
|
+
*
|
|
77
|
+
* This is the asynchronous version, which can be used like this:
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* const results = await asyncFilterMap(things, someFunc);
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* (This is an abstraction around `Promise.all`.)
|
|
84
|
+
*/
|
|
85
|
+
export declare function filterMapAsync<OldT, NewT>(array: readonly OldT[], func: (element: OldT) => Promise<NewT | undefined>): Promise<readonly NewT[]>;
|
|
66
86
|
/**
|
|
67
87
|
* Helper function to get a random element from the provided array.
|
|
68
88
|
*
|
|
@@ -63,6 +63,26 @@ export declare function emptyArray(array: unknown[]): void;
|
|
|
63
63
|
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
64
64
|
*/
|
|
65
65
|
export declare function filterMap<OldT, NewT>(array: readonly OldT[], func: (element: OldT) => NewT | undefined): readonly NewT[];
|
|
66
|
+
/**
|
|
67
|
+
* Helper function to perform a filter and a map at the same time. Similar to `Array.map`, provide a
|
|
68
|
+
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
69
|
+
* this function cannot be used in situations where `undefined` can be a valid array element.)
|
|
70
|
+
*
|
|
71
|
+
* This function is useful because the `Array.map` method will always produce an array with the same
|
|
72
|
+
* amount of elements as the original array.
|
|
73
|
+
*
|
|
74
|
+
* This is named `filterMap` after the Rust function:
|
|
75
|
+
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
76
|
+
*
|
|
77
|
+
* This is the asynchronous version, which can be used like this:
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* const results = await asyncFilterMap(things, someFunc);
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* (This is an abstraction around `Promise.all`.)
|
|
84
|
+
*/
|
|
85
|
+
export declare function filterMapAsync<OldT, NewT>(array: readonly OldT[], func: (element: OldT) => Promise<NewT | undefined>): Promise<readonly NewT[]>;
|
|
66
86
|
/**
|
|
67
87
|
* Helper function to get a random element from the provided array.
|
|
68
88
|
*
|
|
@@ -63,6 +63,26 @@ export declare function emptyArray(array: unknown[]): void;
|
|
|
63
63
|
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
64
64
|
*/
|
|
65
65
|
export declare function filterMap<OldT, NewT>(array: readonly OldT[], func: (element: OldT) => NewT | undefined): readonly NewT[];
|
|
66
|
+
/**
|
|
67
|
+
* Helper function to perform a filter and a map at the same time. Similar to `Array.map`, provide a
|
|
68
|
+
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
69
|
+
* this function cannot be used in situations where `undefined` can be a valid array element.)
|
|
70
|
+
*
|
|
71
|
+
* This function is useful because the `Array.map` method will always produce an array with the same
|
|
72
|
+
* amount of elements as the original array.
|
|
73
|
+
*
|
|
74
|
+
* This is named `filterMap` after the Rust function:
|
|
75
|
+
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
76
|
+
*
|
|
77
|
+
* This is the asynchronous version, which can be used like this:
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* const results = await asyncFilterMap(things, someFunc);
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* (This is an abstraction around `Promise.all`.)
|
|
84
|
+
*/
|
|
85
|
+
export declare function filterMapAsync<OldT, NewT>(array: readonly OldT[], func: (element: OldT) => Promise<NewT | undefined>): Promise<readonly NewT[]>;
|
|
66
86
|
/**
|
|
67
87
|
* Helper function to get a random element from the provided array.
|
|
68
88
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/functions/array.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAI7D;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EACvC,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC,GACjC,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC,CAQ7B;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,MAAM,EAAE,SAAS,CAAC,EAAE,EACpB,MAAM,EAAE,SAAS,CAAC,EAAE,GACnB,OAAO,CAST;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,aAAa,EAAE,SAAS,CAAC,EAAE,EAC3B,GAAG,gBAAgB,EAAE,SAAS,CAAC,EAAE,GAChC,SAAS,CAAC,EAAE,CAWd;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAErC,KAAK,EAAE,CAAC,EAAE,EACV,GAAG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,EAAE,SAAS,CAAC,EAAE,EACnB,GAAG,cAAc,EAAE,SAAS,CAAC,EAAE,GAC9B,OAAO,CAET;AAED,uFAAuF;AACvF,wBAAgB,OAAO,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,OAAO,EAAE,CAEhE;AAED,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,OAAO,EAAE,CAMvE;AAED,iFAAiF;AACjF,wBAAgB,aAAa,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,MAAM,EAAE,CAMrE;AAED,iFAAiF;AACjF,wBAAgB,aAAa,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,MAAM,EAAE,CAMrE;AAED,qFAAqF;AACrF,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC,EAAE,CAElE;AAED,+DAA+D;AAC/D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAEzD"}
|
package/dist/index.cjs
CHANGED
|
@@ -198,6 +198,11 @@ function filterMap(array, func) {
|
|
|
198
198
|
}
|
|
199
199
|
return filteredArray;
|
|
200
200
|
}
|
|
201
|
+
async function filterMapAsync(array, func) {
|
|
202
|
+
const promises = array.map(async (element) => await func(element));
|
|
203
|
+
const results = await Promise.all(promises);
|
|
204
|
+
return results.filter((item) => item !== void 0);
|
|
205
|
+
}
|
|
201
206
|
function getRandomArrayElement(array, exceptions = []) {
|
|
202
207
|
if (array.length === 0) {
|
|
203
208
|
throw new Error(
|
|
@@ -622,6 +627,7 @@ exports.eRange = eRange;
|
|
|
622
627
|
exports.emptyArray = emptyArray;
|
|
623
628
|
exports.escapeHTMLCharacters = escapeHTMLCharacters;
|
|
624
629
|
exports.filterMap = filterMap;
|
|
630
|
+
exports.filterMapAsync = filterMapAsync;
|
|
625
631
|
exports.getElapsedSeconds = getElapsedSeconds;
|
|
626
632
|
exports.getEnumEntries = getEnumEntries;
|
|
627
633
|
exports.getEnumKeys = getEnumKeys;
|
package/dist/index.mjs
CHANGED
|
@@ -196,6 +196,11 @@ function filterMap(array, func) {
|
|
|
196
196
|
}
|
|
197
197
|
return filteredArray;
|
|
198
198
|
}
|
|
199
|
+
async function filterMapAsync(array, func) {
|
|
200
|
+
const promises = array.map(async (element) => await func(element));
|
|
201
|
+
const results = await Promise.all(promises);
|
|
202
|
+
return results.filter((item) => item !== void 0);
|
|
203
|
+
}
|
|
199
204
|
function getRandomArrayElement(array, exceptions = []) {
|
|
200
205
|
if (array.length === 0) {
|
|
201
206
|
throw new Error(
|
|
@@ -586,4 +591,4 @@ function* tupleKeys(tuple) {
|
|
|
586
591
|
|
|
587
592
|
const ReadonlyMap = Map;
|
|
588
593
|
|
|
589
|
-
export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveAllInPlace, arrayRemoveInPlace, assertArray, assertArrayBoolean, assertArrayNumber, assertArrayObject, assertArrayString, assertBoolean, assertDefined, assertEnumValue, assertInteger, assertIs, assertNotNull, assertNumber, assertObject, assertString, assertStringNotEmpty, capitalizeFirstLetter, clamp, combineSets, copySet, eRange, emptyArray, escapeHTMLCharacters, filterMap, getElapsedSeconds, getEnumEntries, getEnumKeys, getEnumValues, getNumConsecutiveDiacritics, getRandomArrayElement, getRandomArrayIndex, getRandomInt, hasDiacritic, hasEmoji, hasWhitespace, iRange, includes, includesAny, interfaceSatisfiesEnum, isASCII, isArray, isArrayBoolean, isArrayNumber, isArrayString, isEnumValue, isFirstLetterCapitalized, isKebabCase, isKeyOf, isLowerCase, isObject, isSemanticVersion, isUpperCase, kebabCaseToCamelCase, kebabCaseToPascalCase, mapFilter, mapFind, newArray, noop, normalizeString, objectFilter, objectKeysToSet, objectToMap, objectToReverseMap, objectValuesToSet, parseFloatSafe, parseIntSafe, parseSemanticVersion, removeLinesBetweenMarkers, removeLinesMatching, removeNonPrintableCharacters, removeWhitespace, repeat, setAdd, setHas, sortCaseInsensitive, sumArray, todo, trimPrefix, trimSuffix, truncateString, tupleEntries, tupleKeys };
|
|
594
|
+
export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveAllInPlace, arrayRemoveInPlace, assertArray, assertArrayBoolean, assertArrayNumber, assertArrayObject, assertArrayString, assertBoolean, assertDefined, assertEnumValue, assertInteger, assertIs, assertNotNull, assertNumber, assertObject, assertString, assertStringNotEmpty, capitalizeFirstLetter, clamp, combineSets, copySet, eRange, emptyArray, escapeHTMLCharacters, filterMap, filterMapAsync, getElapsedSeconds, getEnumEntries, getEnumKeys, getEnumValues, getNumConsecutiveDiacritics, getRandomArrayElement, getRandomArrayIndex, getRandomInt, hasDiacritic, hasEmoji, hasWhitespace, iRange, includes, includesAny, interfaceSatisfiesEnum, isASCII, isArray, isArrayBoolean, isArrayNumber, isArrayString, isEnumValue, isFirstLetterCapitalized, isKebabCase, isKeyOf, isLowerCase, isObject, isSemanticVersion, isUpperCase, kebabCaseToCamelCase, kebabCaseToPascalCase, mapFilter, mapFind, newArray, noop, normalizeString, objectFilter, objectKeysToSet, objectToMap, objectToReverseMap, objectValuesToSet, parseFloatSafe, parseIntSafe, parseSemanticVersion, removeLinesBetweenMarkers, removeLinesMatching, removeNonPrintableCharacters, removeWhitespace, repeat, setAdd, setHas, sortCaseInsensitive, sumArray, todo, trimPrefix, trimSuffix, truncateString, tupleEntries, tupleKeys };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "complete-common",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"description": "Helper functions for TypeScript projects.",
|
|
5
5
|
"homepage": "https://complete-ts.github.io/",
|
|
6
6
|
"bugs": {
|
|
@@ -28,14 +28,14 @@
|
|
|
28
28
|
"build": "tsx ./scripts/build.ts",
|
|
29
29
|
"docs": "typedoc",
|
|
30
30
|
"lint": "tsx ./scripts/lint.ts",
|
|
31
|
-
"test": "tsx --test"
|
|
31
|
+
"test": "tsx --test \"src/**/*.test.ts\""
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@types/node": "
|
|
35
|
-
"complete-node": "
|
|
34
|
+
"@types/node": "25.0.3",
|
|
35
|
+
"complete-node": "16.2.0",
|
|
36
36
|
"eslint-plugin-sort-exports": "0.9.1",
|
|
37
37
|
"typescript": "5.9.3",
|
|
38
|
-
"typescript-eslint": "8.
|
|
38
|
+
"typescript-eslint": "8.51.0",
|
|
39
39
|
"unbuild": "3.6.1"
|
|
40
40
|
}
|
|
41
41
|
}
|
package/src/functions/array.ts
CHANGED
|
@@ -163,6 +163,34 @@ export function filterMap<OldT, NewT>(
|
|
|
163
163
|
return filteredArray;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Helper function to perform a filter and a map at the same time. Similar to `Array.map`, provide a
|
|
168
|
+
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
169
|
+
* this function cannot be used in situations where `undefined` can be a valid array element.)
|
|
170
|
+
*
|
|
171
|
+
* This function is useful because the `Array.map` method will always produce an array with the same
|
|
172
|
+
* amount of elements as the original array.
|
|
173
|
+
*
|
|
174
|
+
* This is named `filterMap` after the Rust function:
|
|
175
|
+
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
176
|
+
*
|
|
177
|
+
* This is the asynchronous version, which can be used like this:
|
|
178
|
+
*
|
|
179
|
+
* ```ts
|
|
180
|
+
* const results = await asyncFilterMap(things, someFunc);
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
183
|
+
* (This is an abstraction around `Promise.all`.)
|
|
184
|
+
*/
|
|
185
|
+
export async function filterMapAsync<OldT, NewT>(
|
|
186
|
+
array: readonly OldT[],
|
|
187
|
+
func: (element: OldT) => Promise<NewT | undefined>,
|
|
188
|
+
): Promise<readonly NewT[]> {
|
|
189
|
+
const promises = array.map(async (element) => await func(element));
|
|
190
|
+
const results = await Promise.all(promises);
|
|
191
|
+
return results.filter((item) => item !== undefined);
|
|
192
|
+
}
|
|
193
|
+
|
|
166
194
|
/**
|
|
167
195
|
* Helper function to get a random element from the provided array.
|
|
168
196
|
*
|