complete-common 2.10.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.
@@ -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,S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18
  export declare function assertArrayNumber(value: unknown, msg: string): asserts value is unknown[];
19
+ /**
20
+ * Helper function to throw an error if the provided value is not an array with every element being
21
+ * an object (i.e. a TypeScript record).
22
+ */
23
+ export declare function assertArrayObject(value: unknown, msg: string): asserts value is Array<Record<string, unknown>>;
19
24
  /**
20
25
  * Helper function to throw an error if the provided value is not an array with every element being
21
26
  * a string.
@@ -16,6 +16,11 @@ export declare function assertArrayBoolean(value: unknown, msg: string): asserts
16
16
  * a number.
17
17
  */
18
18
  export declare function assertArrayNumber(value: unknown, msg: string): asserts value is unknown[];
19
+ /**
20
+ * Helper function to throw an error if the provided value is not an array with every element being
21
+ * an object (i.e. a TypeScript record).
22
+ */
23
+ export declare function assertArrayObject(value: unknown, msg: string): asserts value is Array<Record<string, unknown>>;
19
24
  /**
20
25
  * Helper function to throw an error if the provided value is not an array with every element being
21
26
  * a string.
@@ -16,6 +16,11 @@ export declare function assertArrayBoolean(value: unknown, msg: string): asserts
16
16
  * a number.
17
17
  */
18
18
  export declare function assertArrayNumber(value: unknown, msg: string): asserts value is unknown[];
19
+ /**
20
+ * Helper function to throw an error if the provided value is not an array with every element being
21
+ * an object (i.e. a TypeScript record).
22
+ */
23
+ export declare function assertArrayObject(value: unknown, msg: string): asserts value is Array<Record<string, unknown>>;
19
24
  /**
20
25
  * Helper function to throw an error if the provided value is not an array with every element being
21
26
  * a string.
@@ -1 +1 @@
1
- {"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/functions/assert.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAIjE,+EAA+E;AAC/E,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,OAAO,EAAE,CAI5B;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,O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K,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,MAAM,CAMzB;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CACtB,CAAC,SAAS,QAAQ,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EAEtD,KAAK,EAAE,OAAO,EACd,WAAW,EAAE,CAAC,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,YAAY,CAAC,CAAC,CAAC,CAIlC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,KAAK,EAAE,CAAC,EACR,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GACxB,CAAC,MAAM,CAAC,GACR;IACE,4EAA4E;CAC7E,GACJ,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,CAInC;AAED,+EAA+E;AAC/E,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,MAAM,CAIzB;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAI1C;AAED,+EAA+E;AAC/E,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,MAAM,CAIzB;AAED,kGAAkG;AAClG,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,MAAM,CAMzB"}
package/dist/index.cjs CHANGED
@@ -53,6 +53,12 @@ function assertArrayNumber(value, msg) {
53
53
  throw new TypeError(msg);
54
54
  }
55
55
  }
56
+ function assertArrayObject(value, msg) {
57
+ assertArray(value, msg);
58
+ if (value.some((element) => !isObject(element))) {
59
+ throw new TypeError(msg);
60
+ }
61
+ }
56
62
  function assertArrayString(value, msg) {
57
63
  assertArray(value, msg);
58
64
  if (value.some((element) => typeof element !== "string")) {
@@ -192,6 +198,11 @@ function filterMap(array, func) {
192
198
  }
193
199
  return filteredArray;
194
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
+ }
195
206
  function getRandomArrayElement(array, exceptions = []) {
196
207
  if (array.length === 0) {
197
208
  throw new Error(
@@ -596,6 +607,7 @@ exports.arrayRemoveInPlace = arrayRemoveInPlace;
596
607
  exports.assertArray = assertArray;
597
608
  exports.assertArrayBoolean = assertArrayBoolean;
598
609
  exports.assertArrayNumber = assertArrayNumber;
610
+ exports.assertArrayObject = assertArrayObject;
599
611
  exports.assertArrayString = assertArrayString;
600
612
  exports.assertBoolean = assertBoolean;
601
613
  exports.assertDefined = assertDefined;
@@ -615,6 +627,7 @@ exports.eRange = eRange;
615
627
  exports.emptyArray = emptyArray;
616
628
  exports.escapeHTMLCharacters = escapeHTMLCharacters;
617
629
  exports.filterMap = filterMap;
630
+ exports.filterMapAsync = filterMapAsync;
618
631
  exports.getElapsedSeconds = getElapsedSeconds;
619
632
  exports.getEnumEntries = getEnumEntries;
620
633
  exports.getEnumKeys = getEnumKeys;
package/dist/index.mjs CHANGED
@@ -51,6 +51,12 @@ function assertArrayNumber(value, msg) {
51
51
  throw new TypeError(msg);
52
52
  }
53
53
  }
54
+ function assertArrayObject(value, msg) {
55
+ assertArray(value, msg);
56
+ if (value.some((element) => !isObject(element))) {
57
+ throw new TypeError(msg);
58
+ }
59
+ }
54
60
  function assertArrayString(value, msg) {
55
61
  assertArray(value, msg);
56
62
  if (value.some((element) => typeof element !== "string")) {
@@ -190,6 +196,11 @@ function filterMap(array, func) {
190
196
  }
191
197
  return filteredArray;
192
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
+ }
193
204
  function getRandomArrayElement(array, exceptions = []) {
194
205
  if (array.length === 0) {
195
206
  throw new Error(
@@ -580,4 +591,4 @@ function* tupleKeys(tuple) {
580
591
 
581
592
  const ReadonlyMap = Map;
582
593
 
583
- export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveAllInPlace, arrayRemoveInPlace, assertArray, assertArrayBoolean, assertArrayNumber, 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.10.0",
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": "24.10.1",
35
- "complete-node": "12.3.0",
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.48.0",
38
+ "typescript-eslint": "8.51.0",
39
39
  "unbuild": "3.6.1"
40
40
  }
41
41
  }
@@ -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
  *
@@ -48,6 +48,21 @@ export function assertArrayNumber(
48
48
  }
49
49
  }
50
50
 
51
+ /**
52
+ * Helper function to throw an error if the provided value is not an array with every element being
53
+ * an object (i.e. a TypeScript record).
54
+ */
55
+ export function assertArrayObject(
56
+ value: unknown,
57
+ msg: string,
58
+ ): asserts value is Array<Record<string, unknown>> {
59
+ assertArray(value, msg);
60
+
61
+ if (value.some((element) => !isObject(element))) {
62
+ throw new TypeError(msg);
63
+ }
64
+ }
65
+
51
66
  /**
52
67
  * Helper function to throw an error if the provided value is not an array with every element being
53
68
  * a string.