complete-common 2.17.0 → 2.18.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 +0 -11
- package/dist/functions/array.d.mts +0 -11
- package/dist/functions/array.d.ts +0 -11
- package/dist/functions/array.d.ts.map +1 -1
- package/dist/functions/object.d.cts +8 -0
- package/dist/functions/object.d.mts +8 -0
- package/dist/functions/object.d.ts +8 -0
- package/dist/functions/object.d.ts.map +1 -1
- package/dist/index.cjs +5 -25
- package/dist/index.mjs +5 -25
- package/package.json +1 -1
- package/src/functions/array.ts +0 -45
- package/src/functions/object.ts +15 -0
|
@@ -153,17 +153,6 @@ export declare function isArrayString(variable: unknown): variable is string[];
|
|
|
153
153
|
* (This is an abstraction around `Promise.all`.)
|
|
154
154
|
*/
|
|
155
155
|
export declare function mapAsync<T, U>(array: readonly T[], callback: (element: T, index: number, array: readonly T[]) => Promise<U>): Promise<readonly U[]>;
|
|
156
|
-
/**
|
|
157
|
-
* Helper function to perform an asynchronous map. This is the same thing as the `mapAsync`
|
|
158
|
-
* function, but allows for limiting the number of array elements that should be worked on at a
|
|
159
|
-
* time. This is useful to prevent the system from running out of memory in situations with large
|
|
160
|
-
* arrays and/or expensive functions.
|
|
161
|
-
*
|
|
162
|
-
* @param array The array to map.
|
|
163
|
-
* @param limit The maximum number of concurrent executions that should happen at once.
|
|
164
|
-
* @param callback The map function.
|
|
165
|
-
*/
|
|
166
|
-
export declare function mapAsyncLimit<T, U>(array: readonly T[], limit: number, callback: (item: T) => Promise<U>): Promise<readonly U[]>;
|
|
167
156
|
/** Initializes an array with all elements containing the specified default value. */
|
|
168
157
|
export declare function newArray<T>(length: number, value: T): readonly T[];
|
|
169
158
|
/** Helper function to sum every value in an array together. */
|
|
@@ -153,17 +153,6 @@ export declare function isArrayString(variable: unknown): variable is string[];
|
|
|
153
153
|
* (This is an abstraction around `Promise.all`.)
|
|
154
154
|
*/
|
|
155
155
|
export declare function mapAsync<T, U>(array: readonly T[], callback: (element: T, index: number, array: readonly T[]) => Promise<U>): Promise<readonly U[]>;
|
|
156
|
-
/**
|
|
157
|
-
* Helper function to perform an asynchronous map. This is the same thing as the `mapAsync`
|
|
158
|
-
* function, but allows for limiting the number of array elements that should be worked on at a
|
|
159
|
-
* time. This is useful to prevent the system from running out of memory in situations with large
|
|
160
|
-
* arrays and/or expensive functions.
|
|
161
|
-
*
|
|
162
|
-
* @param array The array to map.
|
|
163
|
-
* @param limit The maximum number of concurrent executions that should happen at once.
|
|
164
|
-
* @param callback The map function.
|
|
165
|
-
*/
|
|
166
|
-
export declare function mapAsyncLimit<T, U>(array: readonly T[], limit: number, callback: (item: T) => Promise<U>): Promise<readonly U[]>;
|
|
167
156
|
/** Initializes an array with all elements containing the specified default value. */
|
|
168
157
|
export declare function newArray<T>(length: number, value: T): readonly T[];
|
|
169
158
|
/** Helper function to sum every value in an array together. */
|
|
@@ -153,17 +153,6 @@ export declare function isArrayString(variable: unknown): variable is string[];
|
|
|
153
153
|
* (This is an abstraction around `Promise.all`.)
|
|
154
154
|
*/
|
|
155
155
|
export declare function mapAsync<T, U>(array: readonly T[], callback: (element: T, index: number, array: readonly T[]) => Promise<U>): Promise<readonly U[]>;
|
|
156
|
-
/**
|
|
157
|
-
* Helper function to perform an asynchronous map. This is the same thing as the `mapAsync`
|
|
158
|
-
* function, but allows for limiting the number of array elements that should be worked on at a
|
|
159
|
-
* time. This is useful to prevent the system from running out of memory in situations with large
|
|
160
|
-
* arrays and/or expensive functions.
|
|
161
|
-
*
|
|
162
|
-
* @param array The array to map.
|
|
163
|
-
* @param limit The maximum number of concurrent executions that should happen at once.
|
|
164
|
-
* @param callback The map function.
|
|
165
|
-
*/
|
|
166
|
-
export declare function mapAsyncLimit<T, U>(array: readonly T[], limit: number, callback: (item: T) => Promise<U>): Promise<readonly U[]>;
|
|
167
156
|
/** Initializes an array with all elements containing the specified default value. */
|
|
168
157
|
export declare function newArray<T>(length: number, value: T): readonly T[];
|
|
169
158
|
/** Helper function to sum every value in an array together. */
|
|
@@ -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,gBAAgB,EAAE,SAAS,CAAC,EAAE,GAChC,OAAO,CAeT;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAElC,KAAK,EAAE,CAAC,EAAE,EACV,GAAG,gBAAgB,EAAE,SAAS,CAAC,EAAE,GAChC,SAAS,CAAC,EAAE,CAYd;AAED,0EAA0E;AAE1E,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAEjD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,SAAS,EAAE,CACT,OAAO,EAAE,CAAC,EACV,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,SAAS,C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AO,CAAC,SAAS,CAAC,EAAE,CAAC,CAKvB;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"}
|
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
|
|
7
|
+
import type { WidenLiteral } from "../types/WidenLiteral.js";
|
|
8
|
+
/**
|
|
9
|
+
* Safely gets a value from a widened object.
|
|
10
|
+
*
|
|
11
|
+
* This is useful when normal indexing produces a type error from an object that uses an `as const`
|
|
12
|
+
* assertion.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getWidenedObjectValue<T extends Record<string, unknown>>(object: T, key: WidenLiteral<keyof T>): T[keyof T] | undefined;
|
|
7
15
|
/**
|
|
8
16
|
* Helper function to get the values in an object that match an arbitrary condition. Similar to the
|
|
9
17
|
* `Array.filter` method, but works for objects.
|
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
|
|
7
|
+
import type { WidenLiteral } from "../types/WidenLiteral.js";
|
|
8
|
+
/**
|
|
9
|
+
* Safely gets a value from a widened object.
|
|
10
|
+
*
|
|
11
|
+
* This is useful when normal indexing produces a type error from an object that uses an `as const`
|
|
12
|
+
* assertion.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getWidenedObjectValue<T extends Record<string, unknown>>(object: T, key: WidenLiteral<keyof T>): T[keyof T] | undefined;
|
|
7
15
|
/**
|
|
8
16
|
* Helper function to get the values in an object that match an arbitrary condition. Similar to the
|
|
9
17
|
* `Array.filter` method, but works for objects.
|
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
|
|
7
|
+
import type { WidenLiteral } from "../types/WidenLiteral.js";
|
|
8
|
+
/**
|
|
9
|
+
* Safely gets a value from a widened object.
|
|
10
|
+
*
|
|
11
|
+
* This is useful when normal indexing produces a type error from an object that uses an `as const`
|
|
12
|
+
* assertion.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getWidenedObjectValue<T extends Record<string, unknown>>(object: T, key: WidenLiteral<keyof T>): T[keyof T] | undefined;
|
|
7
15
|
/**
|
|
8
16
|
* Helper function to get the values in an object that match an arbitrary condition. Similar to the
|
|
9
17
|
* `Array.filter` method, but works for objects.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/functions/object.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/functions/object.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrE,MAAM,EAAE,CAAC,EACT,GAAG,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,GACzB,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAGxB;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,EAChE,MAAM,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,EAC5B,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,GAC/B,SAAS,CAAC,EAAE,CAad;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC,EAChE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EACpB,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,GAChC,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAOtB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,EAC/D,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GACnB,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAQnB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAClC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAClC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAQzC"}
|
package/dist/index.cjs
CHANGED
|
@@ -276,30 +276,6 @@ async function mapAsync(array, callback) {
|
|
|
276
276
|
);
|
|
277
277
|
return await Promise.all(promises);
|
|
278
278
|
}
|
|
279
|
-
async function mapAsyncLimit(array, limit, callback) {
|
|
280
|
-
if (limit < 1) {
|
|
281
|
-
throw new RangeError("The limit argument must be at least 1.");
|
|
282
|
-
}
|
|
283
|
-
const results = [];
|
|
284
|
-
let currentIndex = 0;
|
|
285
|
-
let hasFailed = false;
|
|
286
|
-
async function worker() {
|
|
287
|
-
while (currentIndex < array.length && !hasFailed) {
|
|
288
|
-
const index = currentIndex;
|
|
289
|
-
currentIndex++;
|
|
290
|
-
try {
|
|
291
|
-
results[index] = await callback(array[index]);
|
|
292
|
-
} catch (error) {
|
|
293
|
-
hasFailed = true;
|
|
294
|
-
throw error;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
await Promise.all(
|
|
299
|
-
Array.from({ length: Math.min(limit, array.length) }, worker)
|
|
300
|
-
);
|
|
301
|
-
return results;
|
|
302
|
-
}
|
|
303
279
|
function newArray(length, value) {
|
|
304
280
|
return Array.from({ length }, () => value);
|
|
305
281
|
}
|
|
@@ -331,6 +307,10 @@ function clamp(num, min, max) {
|
|
|
331
307
|
return Math.max(min, Math.min(num, max));
|
|
332
308
|
}
|
|
333
309
|
|
|
310
|
+
function getWidenedObjectValue(object, key) {
|
|
311
|
+
const widenedObject = object;
|
|
312
|
+
return widenedObject[key];
|
|
313
|
+
}
|
|
334
314
|
function objectFilter(object, predicate) {
|
|
335
315
|
const array = [];
|
|
336
316
|
for (const key in object) {
|
|
@@ -696,6 +676,7 @@ exports.getNumConsecutiveDiacritics = getNumConsecutiveDiacritics;
|
|
|
696
676
|
exports.getRandomArrayElement = getRandomArrayElement;
|
|
697
677
|
exports.getRandomArrayIndex = getRandomArrayIndex;
|
|
698
678
|
exports.getRandomInt = getRandomInt;
|
|
679
|
+
exports.getWidenedObjectValue = getWidenedObjectValue;
|
|
699
680
|
exports.hasDiacritic = hasDiacritic;
|
|
700
681
|
exports.hasEmoji = hasEmoji;
|
|
701
682
|
exports.hasWhitespace = hasWhitespace;
|
|
@@ -719,7 +700,6 @@ exports.isUpperCase = isUpperCase;
|
|
|
719
700
|
exports.kebabCaseToCamelCase = kebabCaseToCamelCase;
|
|
720
701
|
exports.kebabCaseToPascalCase = kebabCaseToPascalCase;
|
|
721
702
|
exports.mapAsync = mapAsync;
|
|
722
|
-
exports.mapAsyncLimit = mapAsyncLimit;
|
|
723
703
|
exports.mapFilter = mapFilter;
|
|
724
704
|
exports.mapFind = mapFind;
|
|
725
705
|
exports.newArray = newArray;
|
package/dist/index.mjs
CHANGED
|
@@ -274,30 +274,6 @@ async function mapAsync(array, callback) {
|
|
|
274
274
|
);
|
|
275
275
|
return await Promise.all(promises);
|
|
276
276
|
}
|
|
277
|
-
async function mapAsyncLimit(array, limit, callback) {
|
|
278
|
-
if (limit < 1) {
|
|
279
|
-
throw new RangeError("The limit argument must be at least 1.");
|
|
280
|
-
}
|
|
281
|
-
const results = [];
|
|
282
|
-
let currentIndex = 0;
|
|
283
|
-
let hasFailed = false;
|
|
284
|
-
async function worker() {
|
|
285
|
-
while (currentIndex < array.length && !hasFailed) {
|
|
286
|
-
const index = currentIndex;
|
|
287
|
-
currentIndex++;
|
|
288
|
-
try {
|
|
289
|
-
results[index] = await callback(array[index]);
|
|
290
|
-
} catch (error) {
|
|
291
|
-
hasFailed = true;
|
|
292
|
-
throw error;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
await Promise.all(
|
|
297
|
-
Array.from({ length: Math.min(limit, array.length) }, worker)
|
|
298
|
-
);
|
|
299
|
-
return results;
|
|
300
|
-
}
|
|
301
277
|
function newArray(length, value) {
|
|
302
278
|
return Array.from({ length }, () => value);
|
|
303
279
|
}
|
|
@@ -329,6 +305,10 @@ function clamp(num, min, max) {
|
|
|
329
305
|
return Math.max(min, Math.min(num, max));
|
|
330
306
|
}
|
|
331
307
|
|
|
308
|
+
function getWidenedObjectValue(object, key) {
|
|
309
|
+
const widenedObject = object;
|
|
310
|
+
return widenedObject[key];
|
|
311
|
+
}
|
|
332
312
|
function objectFilter(object, predicate) {
|
|
333
313
|
const array = [];
|
|
334
314
|
for (const key in object) {
|
|
@@ -650,4 +630,4 @@ function* tupleKeys(tuple) {
|
|
|
650
630
|
|
|
651
631
|
const ReadonlyMap = Map;
|
|
652
632
|
|
|
653
|
-
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, filterAsync, 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, mapAsync,
|
|
633
|
+
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, filterAsync, filterMap, filterMapAsync, getElapsedSeconds, getEnumEntries, getEnumKeys, getEnumValues, getNumConsecutiveDiacritics, getRandomArrayElement, getRandomArrayIndex, getRandomInt, getWidenedObjectValue, hasDiacritic, hasEmoji, hasWhitespace, iRange, includes, includesAny, interfaceSatisfiesEnum, isASCII, isArray, isArrayBoolean, isArrayNumber, isArrayString, isEnumValue, isFirstLetterCapitalized, isKebabCase, isKeyOf, isLowerCase, isObject, isSemanticVersion, isUpperCase, kebabCaseToCamelCase, kebabCaseToPascalCase, mapAsync, mapFilter, mapFind, newArray, noop, normalizeString, objectFilter, objectKeysToSet, objectMap, objectToMap, objectToReverseMap, objectValuesToSet, parseFloatSafe, parseIntSafe, parseSemanticVersion, removeLinesBetweenMarkers, removeLinesMatching, removeNonPrintableCharacters, removeWhitespace, repeat, setAdd, setHas, sortCaseInsensitive, sumArray, titleCaseToKebabCase, todo, trimPrefix, trimSuffix, truncateString, tupleEntries, tupleKeys };
|
package/package.json
CHANGED
package/src/functions/array.ts
CHANGED
|
@@ -360,51 +360,6 @@ export async function mapAsync<T, U>(
|
|
|
360
360
|
return await Promise.all(promises);
|
|
361
361
|
}
|
|
362
362
|
|
|
363
|
-
/**
|
|
364
|
-
* Helper function to perform an asynchronous map. This is the same thing as the `mapAsync`
|
|
365
|
-
* function, but allows for limiting the number of array elements that should be worked on at a
|
|
366
|
-
* time. This is useful to prevent the system from running out of memory in situations with large
|
|
367
|
-
* arrays and/or expensive functions.
|
|
368
|
-
*
|
|
369
|
-
* @param array The array to map.
|
|
370
|
-
* @param limit The maximum number of concurrent executions that should happen at once.
|
|
371
|
-
* @param callback The map function.
|
|
372
|
-
*/
|
|
373
|
-
export async function mapAsyncLimit<T, U>(
|
|
374
|
-
array: readonly T[],
|
|
375
|
-
limit: number,
|
|
376
|
-
callback: (item: T) => Promise<U>,
|
|
377
|
-
): Promise<readonly U[]> {
|
|
378
|
-
if (limit < 1) {
|
|
379
|
-
throw new RangeError("The limit argument must be at least 1.");
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
const results: U[] = [];
|
|
383
|
-
let currentIndex = 0;
|
|
384
|
-
let hasFailed = false;
|
|
385
|
-
|
|
386
|
-
async function worker() {
|
|
387
|
-
// Stop processing if the queue is empty or if another worker failed.
|
|
388
|
-
while (currentIndex < array.length && !hasFailed) {
|
|
389
|
-
const index = currentIndex;
|
|
390
|
-
currentIndex++;
|
|
391
|
-
try {
|
|
392
|
-
// eslint-disable-next-line no-await-in-loop, @typescript-eslint/no-non-null-assertion
|
|
393
|
-
results[index] = await callback(array[index]!);
|
|
394
|
-
} catch (error) {
|
|
395
|
-
hasFailed = true; // Signal other workers to stop taking new items.
|
|
396
|
-
throw error; // Bubble the error up to Promise.all.
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
await Promise.all(
|
|
402
|
-
Array.from({ length: Math.min(limit, array.length) }, worker),
|
|
403
|
-
);
|
|
404
|
-
|
|
405
|
-
return results;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
363
|
/** Initializes an array with all elements containing the specified default value. */
|
|
409
364
|
export function newArray<T>(length: number, value: T): readonly T[] {
|
|
410
365
|
return Array.from({ length }, () => value);
|
package/src/functions/object.ts
CHANGED
|
@@ -5,6 +5,21 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
|
|
8
|
+
import type { WidenLiteral } from "../types/WidenLiteral.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Safely gets a value from a widened object.
|
|
12
|
+
*
|
|
13
|
+
* This is useful when normal indexing produces a type error from an object that uses an `as const`
|
|
14
|
+
* assertion.
|
|
15
|
+
*/
|
|
16
|
+
export function getWidenedObjectValue<T extends Record<string, unknown>>(
|
|
17
|
+
object: T,
|
|
18
|
+
key: WidenLiteral<keyof T>,
|
|
19
|
+
): T[keyof T] | undefined {
|
|
20
|
+
const widenedObject = object as Record<PropertyKey, T[keyof T]>;
|
|
21
|
+
return widenedObject[key as PropertyKey];
|
|
22
|
+
}
|
|
8
23
|
|
|
9
24
|
/**
|
|
10
25
|
* Helper function to get the values in an object that match an arbitrary condition. Similar to the
|