complete-common 2.15.0 → 2.16.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 +2 -2
- package/dist/functions/array.d.mts +2 -2
- package/dist/functions/array.d.ts +2 -2
- package/dist/functions/array.d.ts.map +1 -1
- package/dist/functions/object.d.cts +7 -2
- package/dist/functions/object.d.mts +7 -2
- package/dist/functions/object.d.ts +7 -2
- package/dist/functions/object.d.ts.map +1 -1
- package/dist/index.cjs +13 -4
- package/dist/index.mjs +13 -5
- package/package.json +1 -1
- package/src/functions/array.ts +4 -4
- package/src/functions/object.ts +18 -2
|
@@ -76,7 +76,7 @@ export declare function filterAsync<T>(array: readonly T[], predicate: (element:
|
|
|
76
76
|
* This is named `filterMap` after the Rust function:
|
|
77
77
|
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
78
78
|
*/
|
|
79
|
-
export declare function filterMap<OldT, NewT>(array: readonly OldT[],
|
|
79
|
+
export declare function filterMap<OldT, NewT>(array: readonly OldT[], predicate: (element: OldT) => NewT | undefined): readonly NewT[];
|
|
80
80
|
/**
|
|
81
81
|
* Helper function to perform a filter and a map at the same time. Similar to `Array.map`, provide a
|
|
82
82
|
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
@@ -96,7 +96,7 @@ export declare function filterMap<OldT, NewT>(array: readonly OldT[], func: (ele
|
|
|
96
96
|
*
|
|
97
97
|
* (This is an abstraction around `Promise.all`.)
|
|
98
98
|
*/
|
|
99
|
-
export declare function filterMapAsync<OldT, NewT>(array: readonly OldT[],
|
|
99
|
+
export declare function filterMapAsync<OldT, NewT>(array: readonly OldT[], predicate: (element: OldT, index: number, array: readonly OldT[]) => Promise<NewT | undefined>): Promise<readonly NewT[]>;
|
|
100
100
|
/**
|
|
101
101
|
* Helper function to get a random element from the provided array.
|
|
102
102
|
*
|
|
@@ -76,7 +76,7 @@ export declare function filterAsync<T>(array: readonly T[], predicate: (element:
|
|
|
76
76
|
* This is named `filterMap` after the Rust function:
|
|
77
77
|
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
78
78
|
*/
|
|
79
|
-
export declare function filterMap<OldT, NewT>(array: readonly OldT[],
|
|
79
|
+
export declare function filterMap<OldT, NewT>(array: readonly OldT[], predicate: (element: OldT) => NewT | undefined): readonly NewT[];
|
|
80
80
|
/**
|
|
81
81
|
* Helper function to perform a filter and a map at the same time. Similar to `Array.map`, provide a
|
|
82
82
|
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
@@ -96,7 +96,7 @@ export declare function filterMap<OldT, NewT>(array: readonly OldT[], func: (ele
|
|
|
96
96
|
*
|
|
97
97
|
* (This is an abstraction around `Promise.all`.)
|
|
98
98
|
*/
|
|
99
|
-
export declare function filterMapAsync<OldT, NewT>(array: readonly OldT[],
|
|
99
|
+
export declare function filterMapAsync<OldT, NewT>(array: readonly OldT[], predicate: (element: OldT, index: number, array: readonly OldT[]) => Promise<NewT | undefined>): Promise<readonly NewT[]>;
|
|
100
100
|
/**
|
|
101
101
|
* Helper function to get a random element from the provided array.
|
|
102
102
|
*
|
|
@@ -76,7 +76,7 @@ export declare function filterAsync<T>(array: readonly T[], predicate: (element:
|
|
|
76
76
|
* This is named `filterMap` after the Rust function:
|
|
77
77
|
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
78
78
|
*/
|
|
79
|
-
export declare function filterMap<OldT, NewT>(array: readonly OldT[],
|
|
79
|
+
export declare function filterMap<OldT, NewT>(array: readonly OldT[], predicate: (element: OldT) => NewT | undefined): readonly NewT[];
|
|
80
80
|
/**
|
|
81
81
|
* Helper function to perform a filter and a map at the same time. Similar to `Array.map`, provide a
|
|
82
82
|
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
@@ -96,7 +96,7 @@ export declare function filterMap<OldT, NewT>(array: readonly OldT[], func: (ele
|
|
|
96
96
|
*
|
|
97
97
|
* (This is an abstraction around `Promise.all`.)
|
|
98
98
|
*/
|
|
99
|
-
export declare function filterMapAsync<OldT, NewT>(array: readonly OldT[],
|
|
99
|
+
export declare function filterMapAsync<OldT, NewT>(array: readonly OldT[], predicate: (element: OldT, index: number, array: readonly OldT[]) => Promise<NewT | undefined>): Promise<readonly NewT[]>;
|
|
100
100
|
/**
|
|
101
101
|
* Helper function to get a random element from the provided array.
|
|
102
102
|
*
|
|
@@ -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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@@ -6,13 +6,18 @@
|
|
|
6
6
|
import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
|
|
7
7
|
/**
|
|
8
8
|
* Helper function to get the values in an object that match an arbitrary condition. Similar to the
|
|
9
|
-
* `Array.
|
|
9
|
+
* `Array.filter` method, but works for objects.
|
|
10
10
|
*
|
|
11
11
|
* This is efficient such that it avoids converting the object values into an array.
|
|
12
12
|
*/
|
|
13
13
|
export declare function objectFilter<K extends string | number | symbol, V>(object: ReadonlyRecord<K, V>, predicate: (value: V) => boolean): readonly V[];
|
|
14
14
|
/**
|
|
15
|
-
* Helper function to
|
|
15
|
+
* Helper function to map the values in an object to another object with new values. Similar to the
|
|
16
|
+
* `Array.map` method, but works for objects.
|
|
17
|
+
*/
|
|
18
|
+
export declare function objectMap<K extends string | number | symbol, V, U>(object: Record<K, V>, callback: (key: K, value: V) => U): ReadonlyRecord<K, U>;
|
|
19
|
+
/**
|
|
20
|
+
* Helper function to convert an object to a `Map`.
|
|
16
21
|
*
|
|
17
22
|
* This is useful when you need to construct a type safe object with the `satisfies` operator, but
|
|
18
23
|
* then later on you need to query it in a way where you expect the return value to be T or
|
|
@@ -6,13 +6,18 @@
|
|
|
6
6
|
import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
|
|
7
7
|
/**
|
|
8
8
|
* Helper function to get the values in an object that match an arbitrary condition. Similar to the
|
|
9
|
-
* `Array.
|
|
9
|
+
* `Array.filter` method, but works for objects.
|
|
10
10
|
*
|
|
11
11
|
* This is efficient such that it avoids converting the object values into an array.
|
|
12
12
|
*/
|
|
13
13
|
export declare function objectFilter<K extends string | number | symbol, V>(object: ReadonlyRecord<K, V>, predicate: (value: V) => boolean): readonly V[];
|
|
14
14
|
/**
|
|
15
|
-
* Helper function to
|
|
15
|
+
* Helper function to map the values in an object to another object with new values. Similar to the
|
|
16
|
+
* `Array.map` method, but works for objects.
|
|
17
|
+
*/
|
|
18
|
+
export declare function objectMap<K extends string | number | symbol, V, U>(object: Record<K, V>, callback: (key: K, value: V) => U): ReadonlyRecord<K, U>;
|
|
19
|
+
/**
|
|
20
|
+
* Helper function to convert an object to a `Map`.
|
|
16
21
|
*
|
|
17
22
|
* This is useful when you need to construct a type safe object with the `satisfies` operator, but
|
|
18
23
|
* then later on you need to query it in a way where you expect the return value to be T or
|
|
@@ -6,13 +6,18 @@
|
|
|
6
6
|
import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
|
|
7
7
|
/**
|
|
8
8
|
* Helper function to get the values in an object that match an arbitrary condition. Similar to the
|
|
9
|
-
* `Array.
|
|
9
|
+
* `Array.filter` method, but works for objects.
|
|
10
10
|
*
|
|
11
11
|
* This is efficient such that it avoids converting the object values into an array.
|
|
12
12
|
*/
|
|
13
13
|
export declare function objectFilter<K extends string | number | symbol, V>(object: ReadonlyRecord<K, V>, predicate: (value: V) => boolean): readonly V[];
|
|
14
14
|
/**
|
|
15
|
-
* Helper function to
|
|
15
|
+
* Helper function to map the values in an object to another object with new values. Similar to the
|
|
16
|
+
* `Array.map` method, but works for objects.
|
|
17
|
+
*/
|
|
18
|
+
export declare function objectMap<K extends string | number | symbol, V, U>(object: Record<K, V>, callback: (key: K, value: V) => U): ReadonlyRecord<K, U>;
|
|
19
|
+
/**
|
|
20
|
+
* Helper function to convert an object to a `Map`.
|
|
16
21
|
*
|
|
17
22
|
* This is useful when you need to construct a type safe object with the `satisfies` operator, but
|
|
18
23
|
* then later on you need to query it in a way where you expect the return value to be T or
|
|
@@ -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;AAEjE;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,EAChE,MAAM,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,EAC5B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,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
|
@@ -194,19 +194,19 @@ async function filterAsync(array, predicate) {
|
|
|
194
194
|
);
|
|
195
195
|
return array.filter((_, index) => results[index] === true);
|
|
196
196
|
}
|
|
197
|
-
function filterMap(array,
|
|
197
|
+
function filterMap(array, predicate) {
|
|
198
198
|
const filteredArray = [];
|
|
199
199
|
for (const element of array) {
|
|
200
|
-
const newElement =
|
|
200
|
+
const newElement = predicate(element);
|
|
201
201
|
if (newElement !== void 0) {
|
|
202
202
|
filteredArray.push(newElement);
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
return filteredArray;
|
|
206
206
|
}
|
|
207
|
-
async function filterMapAsync(array,
|
|
207
|
+
async function filterMapAsync(array, predicate) {
|
|
208
208
|
const promises = array.map(
|
|
209
|
-
async (element, index) => await
|
|
209
|
+
async (element, index) => await predicate(element, index, array)
|
|
210
210
|
);
|
|
211
211
|
const results = await Promise.all(promises);
|
|
212
212
|
return results.filter((item) => item !== void 0);
|
|
@@ -310,6 +310,14 @@ function objectFilter(object, predicate) {
|
|
|
310
310
|
}
|
|
311
311
|
return array;
|
|
312
312
|
}
|
|
313
|
+
function objectMap(object, callback) {
|
|
314
|
+
const entries = Object.entries(object);
|
|
315
|
+
const mappedEntries = entries.map(([key, value]) => [
|
|
316
|
+
key,
|
|
317
|
+
callback(key, value)
|
|
318
|
+
]);
|
|
319
|
+
return Object.fromEntries(mappedEntries);
|
|
320
|
+
}
|
|
313
321
|
function objectToMap(object) {
|
|
314
322
|
const map = /* @__PURE__ */ new Map();
|
|
315
323
|
for (const [key, value] of Object.entries(object)) {
|
|
@@ -685,6 +693,7 @@ exports.noop = noop;
|
|
|
685
693
|
exports.normalizeString = normalizeString;
|
|
686
694
|
exports.objectFilter = objectFilter;
|
|
687
695
|
exports.objectKeysToSet = objectKeysToSet;
|
|
696
|
+
exports.objectMap = objectMap;
|
|
688
697
|
exports.objectToMap = objectToMap;
|
|
689
698
|
exports.objectToReverseMap = objectToReverseMap;
|
|
690
699
|
exports.objectValuesToSet = objectValuesToSet;
|
package/dist/index.mjs
CHANGED
|
@@ -192,19 +192,19 @@ async function filterAsync(array, predicate) {
|
|
|
192
192
|
);
|
|
193
193
|
return array.filter((_, index) => results[index] === true);
|
|
194
194
|
}
|
|
195
|
-
function filterMap(array,
|
|
195
|
+
function filterMap(array, predicate) {
|
|
196
196
|
const filteredArray = [];
|
|
197
197
|
for (const element of array) {
|
|
198
|
-
const newElement =
|
|
198
|
+
const newElement = predicate(element);
|
|
199
199
|
if (newElement !== void 0) {
|
|
200
200
|
filteredArray.push(newElement);
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
return filteredArray;
|
|
204
204
|
}
|
|
205
|
-
async function filterMapAsync(array,
|
|
205
|
+
async function filterMapAsync(array, predicate) {
|
|
206
206
|
const promises = array.map(
|
|
207
|
-
async (element, index) => await
|
|
207
|
+
async (element, index) => await predicate(element, index, array)
|
|
208
208
|
);
|
|
209
209
|
const results = await Promise.all(promises);
|
|
210
210
|
return results.filter((item) => item !== void 0);
|
|
@@ -308,6 +308,14 @@ function objectFilter(object, predicate) {
|
|
|
308
308
|
}
|
|
309
309
|
return array;
|
|
310
310
|
}
|
|
311
|
+
function objectMap(object, callback) {
|
|
312
|
+
const entries = Object.entries(object);
|
|
313
|
+
const mappedEntries = entries.map(([key, value]) => [
|
|
314
|
+
key,
|
|
315
|
+
callback(key, value)
|
|
316
|
+
]);
|
|
317
|
+
return Object.fromEntries(mappedEntries);
|
|
318
|
+
}
|
|
311
319
|
function objectToMap(object) {
|
|
312
320
|
const map = /* @__PURE__ */ new Map();
|
|
313
321
|
for (const [key, value] of Object.entries(object)) {
|
|
@@ -609,4 +617,4 @@ function* tupleKeys(tuple) {
|
|
|
609
617
|
|
|
610
618
|
const ReadonlyMap = Map;
|
|
611
619
|
|
|
612
|
-
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, mapFilter, mapFind, newArray, noop, normalizeString, objectFilter, objectKeysToSet, objectToMap, objectToReverseMap, objectValuesToSet, parseFloatSafe, parseIntSafe, parseSemanticVersion, removeLinesBetweenMarkers, removeLinesMatching, removeNonPrintableCharacters, removeWhitespace, repeat, setAdd, setHas, sortCaseInsensitive, sumArray, titleCaseToKebabCase, todo, trimPrefix, trimSuffix, truncateString, tupleEntries, tupleKeys };
|
|
620
|
+
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, 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
|
@@ -177,12 +177,12 @@ export async function filterAsync<T>(
|
|
|
177
177
|
*/
|
|
178
178
|
export function filterMap<OldT, NewT>(
|
|
179
179
|
array: readonly OldT[],
|
|
180
|
-
|
|
180
|
+
predicate: (element: OldT) => NewT | undefined,
|
|
181
181
|
): readonly NewT[] {
|
|
182
182
|
const filteredArray: NewT[] = [];
|
|
183
183
|
|
|
184
184
|
for (const element of array) {
|
|
185
|
-
const newElement =
|
|
185
|
+
const newElement = predicate(element);
|
|
186
186
|
if (newElement !== undefined) {
|
|
187
187
|
filteredArray.push(newElement);
|
|
188
188
|
}
|
|
@@ -212,14 +212,14 @@ export function filterMap<OldT, NewT>(
|
|
|
212
212
|
*/
|
|
213
213
|
export async function filterMapAsync<OldT, NewT>(
|
|
214
214
|
array: readonly OldT[],
|
|
215
|
-
|
|
215
|
+
predicate: (
|
|
216
216
|
element: OldT,
|
|
217
217
|
index: number,
|
|
218
218
|
array: readonly OldT[],
|
|
219
219
|
) => Promise<NewT | undefined>,
|
|
220
220
|
): Promise<readonly NewT[]> {
|
|
221
221
|
const promises = array.map(
|
|
222
|
-
async (element, index) => await
|
|
222
|
+
async (element, index) => await predicate(element, index, array),
|
|
223
223
|
);
|
|
224
224
|
const results = await Promise.all(promises);
|
|
225
225
|
return results.filter((item) => item !== undefined);
|
package/src/functions/object.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Helper function to get the values in an object that match an arbitrary condition. Similar to the
|
|
11
|
-
* `Array.
|
|
11
|
+
* `Array.filter` method, but works for objects.
|
|
12
12
|
*
|
|
13
13
|
* This is efficient such that it avoids converting the object values into an array.
|
|
14
14
|
*/
|
|
@@ -31,7 +31,23 @@ export function objectFilter<K extends string | number | symbol, V>(
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* Helper function to
|
|
34
|
+
* Helper function to map the values in an object to another object with new values. Similar to the
|
|
35
|
+
* `Array.map` method, but works for objects.
|
|
36
|
+
*/
|
|
37
|
+
export function objectMap<K extends string | number | symbol, V, U>(
|
|
38
|
+
object: Record<K, V>,
|
|
39
|
+
callback: (key: K, value: V) => U,
|
|
40
|
+
): ReadonlyRecord<K, U> {
|
|
41
|
+
const entries = Object.entries(object);
|
|
42
|
+
const mappedEntries = entries.map(([key, value]) => [
|
|
43
|
+
key,
|
|
44
|
+
callback(key as K, value as V),
|
|
45
|
+
]);
|
|
46
|
+
return Object.fromEntries(mappedEntries) as Record<K, U>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Helper function to convert an object to a `Map`.
|
|
35
51
|
*
|
|
36
52
|
* This is useful when you need to construct a type safe object with the `satisfies` operator, but
|
|
37
53
|
* then later on you need to query it in a way where you expect the return value to be T or
|