@fgv/ts-utils 2.0.2-alpha.0 → 2.1.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/CHANGELOG.json +30 -0
- package/CHANGELOG.md +14 -1
- package/dist/ts-utils.d.ts +7 -7
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/packlets/base/utils.d.ts +7 -7
- package/lib/packlets/base/utils.d.ts.map +1 -1
- package/lib/packlets/base/utils.js +4 -4
- package/lib/packlets/base/utils.js.map +1 -1
- package/package.json +27 -27
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-utils",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "2.1.0",
|
|
6
|
+
"tag": "@fgv/ts-utils_v2.1.0",
|
|
7
|
+
"date": "Tue, 31 Oct 2023 19:56:26 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"none": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "gitignore tweaks"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"comment": "bump versions"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"comment": "build changes"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"comment": "bump dependencies"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"comment": "version upgrades"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"comment": "relax mapToRecord from Map to ReadonlyMap"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"comment": "bump version"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
4
34
|
{
|
|
5
35
|
"version": "2.0.0",
|
|
6
36
|
"tag": "@fgv/ts-utils_v2.0.0",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
# Change Log - @fgv/ts-utils
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Tue, 31 Oct 2023 19:56:26 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 2.1.0
|
|
6
|
+
Tue, 31 Oct 2023 19:56:26 GMT
|
|
7
|
+
|
|
8
|
+
### Updates
|
|
9
|
+
|
|
10
|
+
- gitignore tweaks
|
|
11
|
+
- bump versions
|
|
12
|
+
- build changes
|
|
13
|
+
- bump dependencies
|
|
14
|
+
- version upgrades
|
|
15
|
+
- relax mapToRecord from Map to ReadonlyMap
|
|
16
|
+
- bump version
|
|
4
17
|
|
|
5
18
|
## 2.0.0
|
|
6
19
|
Mon, 10 Apr 2023 03:33:11 GMT
|
package/dist/ts-utils.d.ts
CHANGED
|
@@ -1559,14 +1559,14 @@ declare interface Formattable {
|
|
|
1559
1559
|
export declare function mapSuccess<T>(results: Iterable<Result<T>>): Result<T[]>;
|
|
1560
1560
|
|
|
1561
1561
|
/**
|
|
1562
|
-
* Applies a factory method to convert a `
|
|
1562
|
+
* Applies a factory method to convert a `ReadonlyMap<TK, TS>` into a `Record<TK, TD>`.
|
|
1563
1563
|
* @param src - The `Map` object to be converted.
|
|
1564
1564
|
* @param factory - The factory method used to convert elements.
|
|
1565
1565
|
* @returns {@link Success} with the resulting `Record<TK, TD>` if conversion succeeds, or
|
|
1566
1566
|
* {@link Failure} with an error message if an error occurs.
|
|
1567
1567
|
* @public
|
|
1568
1568
|
*/
|
|
1569
|
-
export declare function mapToRecord<TS, TD, TK extends string = string>(src:
|
|
1569
|
+
export declare function mapToRecord<TS, TD, TK extends string = string>(src: ReadonlyMap<TK, TS>, factory: KeyedThingFactory<TS, TD, TK>): Result<Record<TK, TD>>;
|
|
1570
1570
|
|
|
1571
1571
|
/**
|
|
1572
1572
|
* @public
|
|
@@ -2028,24 +2028,24 @@ declare interface Formattable {
|
|
|
2028
2028
|
declare function optionalField<T, TC = undefined>(name: string, converter: Converter<T, TC>): Converter<T | undefined, TC>;
|
|
2029
2029
|
|
|
2030
2030
|
/**
|
|
2031
|
-
* Applies a factory method to convert an optional `
|
|
2032
|
-
* @param src - The `
|
|
2031
|
+
* Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>`
|
|
2032
|
+
* @param src - The `ReadonlyMap` object to be converted, or `undefined`.
|
|
2033
2033
|
* @param factory - The factory method used to convert elements.
|
|
2034
2034
|
* @returns {@link Success} with the resulting record (empty if `src` is `undefined`) if conversion succeeds.
|
|
2035
2035
|
* Returns {@link Failure} with a message if an error occurs.
|
|
2036
2036
|
* @public
|
|
2037
2037
|
*/
|
|
2038
|
-
export declare function optionalMapToPossiblyEmptyRecord<TS, TD, TK extends string = string>(src:
|
|
2038
|
+
export declare function optionalMapToPossiblyEmptyRecord<TS, TD, TK extends string = string>(src: ReadonlyMap<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Record<TK, TD>>;
|
|
2039
2039
|
|
|
2040
2040
|
/**
|
|
2041
|
-
* Applies a factory method to convert an optional `
|
|
2041
|
+
* Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>` or `undefined`.
|
|
2042
2042
|
* @param src - The `Map` object to be converted, or `undefined`.
|
|
2043
2043
|
* @param factory - The factory method used to convert elements.
|
|
2044
2044
|
* @returns {@link Success} with the resulting record if conversion succeeds, or {@link Success} with `undefined` if
|
|
2045
2045
|
* `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.
|
|
2046
2046
|
* @public
|
|
2047
2047
|
*/
|
|
2048
|
-
export declare function optionalMapToRecord<TS, TD, TK extends string = string>(src:
|
|
2048
|
+
export declare function optionalMapToRecord<TS, TD, TK extends string = string>(src: ReadonlyMap<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Record<TK, TD> | undefined>;
|
|
2049
2049
|
|
|
2050
2050
|
/**
|
|
2051
2051
|
* A {@link Converter} which converts an optional `number` value.
|
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -84,31 +84,31 @@ export declare function optionalRecordToMap<TS, TD, TK extends string = string>(
|
|
|
84
84
|
*/
|
|
85
85
|
export declare function optionalRecordToPossiblyEmptyMap<TS, TD, TK extends string = string>(src: Record<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Map<TK, TD>>;
|
|
86
86
|
/**
|
|
87
|
-
* Applies a factory method to convert a `
|
|
87
|
+
* Applies a factory method to convert a `ReadonlyMap<TK, TS>` into a `Record<TK, TD>`.
|
|
88
88
|
* @param src - The `Map` object to be converted.
|
|
89
89
|
* @param factory - The factory method used to convert elements.
|
|
90
90
|
* @returns {@link Success} with the resulting `Record<TK, TD>` if conversion succeeds, or
|
|
91
91
|
* {@link Failure} with an error message if an error occurs.
|
|
92
92
|
* @public
|
|
93
93
|
*/
|
|
94
|
-
export declare function mapToRecord<TS, TD, TK extends string = string>(src:
|
|
94
|
+
export declare function mapToRecord<TS, TD, TK extends string = string>(src: ReadonlyMap<TK, TS>, factory: KeyedThingFactory<TS, TD, TK>): Result<Record<TK, TD>>;
|
|
95
95
|
/**
|
|
96
|
-
* Applies a factory method to convert an optional `
|
|
96
|
+
* Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>` or `undefined`.
|
|
97
97
|
* @param src - The `Map` object to be converted, or `undefined`.
|
|
98
98
|
* @param factory - The factory method used to convert elements.
|
|
99
99
|
* @returns {@link Success} with the resulting record if conversion succeeds, or {@link Success} with `undefined` if
|
|
100
100
|
* `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.
|
|
101
101
|
* @public
|
|
102
102
|
*/
|
|
103
|
-
export declare function optionalMapToRecord<TS, TD, TK extends string = string>(src:
|
|
103
|
+
export declare function optionalMapToRecord<TS, TD, TK extends string = string>(src: ReadonlyMap<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Record<TK, TD> | undefined>;
|
|
104
104
|
/**
|
|
105
|
-
* Applies a factory method to convert an optional `
|
|
106
|
-
* @param src - The `
|
|
105
|
+
* Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>`
|
|
106
|
+
* @param src - The `ReadonlyMap` object to be converted, or `undefined`.
|
|
107
107
|
* @param factory - The factory method used to convert elements.
|
|
108
108
|
* @returns {@link Success} with the resulting record (empty if `src` is `undefined`) if conversion succeeds.
|
|
109
109
|
* Returns {@link Failure} with a message if an error occurs.
|
|
110
110
|
* @public
|
|
111
111
|
*/
|
|
112
|
-
export declare function optionalMapToPossiblyEmptyRecord<TS, TD, TK extends string = string>(src:
|
|
112
|
+
export declare function optionalMapToPossiblyEmptyRecord<TS, TD, TK extends string = string>(src: ReadonlyMap<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Record<TK, TD>>;
|
|
113
113
|
export {};
|
|
114
114
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/utils.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAAiB,MAAM,UAAU,CAAC;AAEjD;;;;;;;GAOG;AAEH,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,GAAG,IAAI,MAAM,CAAC,CAEhG;AAED;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAQ3F;AAED;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,C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
|
exports.optionalRecordToPossiblyEmptyMap = optionalRecordToPossiblyEmptyMap;
|
|
152
152
|
/**
|
|
153
|
-
* Applies a factory method to convert a `
|
|
153
|
+
* Applies a factory method to convert a `ReadonlyMap<TK, TS>` into a `Record<TK, TD>`.
|
|
154
154
|
* @param src - The `Map` object to be converted.
|
|
155
155
|
* @param factory - The factory method used to convert elements.
|
|
156
156
|
* @returns {@link Success} with the resulting `Record<TK, TD>` if conversion succeeds, or
|
|
@@ -174,7 +174,7 @@ function mapToRecord(src, factory) {
|
|
|
174
174
|
}
|
|
175
175
|
exports.mapToRecord = mapToRecord;
|
|
176
176
|
/**
|
|
177
|
-
* Applies a factory method to convert an optional `
|
|
177
|
+
* Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>` or `undefined`.
|
|
178
178
|
* @param src - The `Map` object to be converted, or `undefined`.
|
|
179
179
|
* @param factory - The factory method used to convert elements.
|
|
180
180
|
* @returns {@link Success} with the resulting record if conversion succeeds, or {@link Success} with `undefined` if
|
|
@@ -186,8 +186,8 @@ function optionalMapToRecord(src, factory) {
|
|
|
186
186
|
}
|
|
187
187
|
exports.optionalMapToRecord = optionalMapToRecord;
|
|
188
188
|
/**
|
|
189
|
-
* Applies a factory method to convert an optional `
|
|
190
|
-
* @param src - The `
|
|
189
|
+
* Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>`
|
|
190
|
+
* @param src - The `ReadonlyMap` object to be converted, or `undefined`.
|
|
191
191
|
* @param factory - The factory method used to convert elements.
|
|
192
192
|
* @returns {@link Success} with the resulting record (empty if `src` is `undefined`) if conversion succeeds.
|
|
193
193
|
* Returns {@link Failure} with a message if an error occurs.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/packlets/base/utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,qCAAiD;AAEjD;;;;;;;GAOG;AACH,wD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EtC,MAAM,MAAM,GAAmB,EAAoB,CAAC;IACpD,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE;QACrB,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;YACxB,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3C,IAAI,UAAU,CAAC,SAAS,EAAE,EAAE;gBAC1B,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC;aACnC;iBAAM;gBACL,OAAO,IAAA,aAAI,EAAC,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;aACjD;SACF;KACF;IACD,OAAO,IAAA,gBAAO,EAAC,MAAM,CAAC,CAAC;AACzB,CAAC;AAhBD,kCAgBC;AAED;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CACjC,GAA4B,EAC5B,OAAsC;IAEtC,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,IAAA,gBAAO,EAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAC5E,CAAC;AALD,kDAKC;AAED;;;;;;;GAOG;AACH,SAAgB,gCAAgC,CAC9C,GAA4B,EAC5B,OAAsC;IAEtC,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,IAAA,gBAAO,EAAC,EAAoB,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACvF,CAAC;AALD,4EAKC","sourcesContent":["/*\r\n * Copyright (c) 2020 Erik Fortune\r\n *\r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n *\r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n *\r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\nimport { Result, fail, succeed } from './result';\r\n\r\n/**\r\n * Helper type-guard function to report whether a specified key is present in\r\n * a supplied object.\r\n * @param key - The key to be tested.\r\n * @param item - The object to be tested.\r\n * @returns Returns `true` if the key is present, `false` otherwise.\r\n * @public\r\n */\r\n// eslint-disable-next-line @typescript-eslint/ban-types\r\nexport function isKeyOf<T extends object>(key: string | number | symbol, item: T): key is keyof T {\r\n return item.hasOwnProperty(key);\r\n}\r\n\r\n/**\r\n * Simple implicit pick function, which picks a set of properties from a supplied\r\n * object. Ignores picked properties that do not exist regardless of type signature.\r\n * @param from - The object from which keys are to be picked.\r\n * @param include - The keys of the properties to be picked from `from`.\r\n * @returns A new object containing the requested properties from `from`, where present.\r\n * @public\r\n */\r\nexport function pick<T extends object, K extends keyof T>(from: T, include: K[]): Pick<T, K> {\r\n const rtrn: Partial<Pick<T, K>> = {};\r\n for (const key of include) {\r\n if (key in from) {\r\n rtrn[key] = from[key];\r\n }\r\n }\r\n return rtrn as Pick<T, K>;\r\n}\r\n\r\n/**\r\n * Simple implicit omit function, which picks all of the properties from a supplied\r\n * object except those specified for exclusion.\r\n * @param from - The object from which keys are to be picked.\r\n * @param exclude - The keys of the properties to be excluded from the returned object.\r\n * @returns A new object containing all of the properties from `from` that were not\r\n * explicitly excluded.\r\n * @public\r\n */\r\nexport function omit<T extends object, K extends keyof T>(from: T, exclude: K[]): Omit<T, K> {\r\n const rtrn: Partial<Omit<T, K>> = {};\r\n for (const entry of Object.entries(from).filter((e) => !exclude.includes(e[0] as keyof T as K))) {\r\n rtrn[entry[0] as unknown as keyof Omit<T, K>] = entry[1];\r\n }\r\n\r\n return rtrn as Omit<T, K>;\r\n}\r\n\r\n/**\r\n * Gets the value of a property specified by key from an arbitrary object,\r\n * or a default value if the property does not exist.\r\n * @param key - The key specifying the property to be retrieved.\r\n * @param item - The object from which the property is to be retrieved.\r\n * @param defaultValue - An optional default value to be returned if the property\r\n * is not present (default `undefined`).\r\n * @returns The value of the requested property, or the default value if the\r\n * requested property does not exist.\r\n * @public\r\n */\r\nexport function getValueOfPropertyOrDefault<T extends object>(\r\n key: string | number | symbol,\r\n item: T,\r\n defaultValue?: unknown\r\n): unknown | undefined {\r\n return isKeyOf(key, item) ? item[key] : defaultValue;\r\n}\r\n\r\n/**\r\n * Gets the type of a property specified by key from an arbitrary object.\r\n * @param key - The key specifying the property to be tested.\r\n * @param item - The object from which the property is to be tested.\r\n * @returns The type of the requested property, or `undefined` if the\r\n * property does not exist.\r\n * @example\r\n * Returns `'undefined'` (a string) if the property exists but has the value\r\n * undefined but `undefined` (the literal) if the property does not exist.\r\n * @public\r\n */\r\nexport function getTypeOfProperty<T extends object>(\r\n key: string | number | symbol,\r\n item: T\r\n):\r\n | 'string'\r\n | 'number'\r\n | 'bigint'\r\n | 'boolean'\r\n | 'symbol'\r\n | 'undefined'\r\n | 'undefined'\r\n | 'object'\r\n | 'function'\r\n | undefined {\r\n return isKeyOf(key, item) ? typeof item[key] : undefined;\r\n}\r\n\r\n/**\r\n * Type for factory methods which convert a key-value pair to a new unique value.\r\n * @public\r\n */\r\ntype KeyedThingFactory<TS, TD, TK extends string = string> = (key: TK, thing: TS) => Result<TD>;\r\n\r\n/**\r\n * Applies a factory method to convert a `Record<TK, TS>` into a `Map<TK, TD>`.\r\n * @param src - The `Record` to be converted.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map on success, or {@link Failure} with a\r\n * message if an error occurs.\r\n * @public\r\n */\r\nexport function recordToMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS>,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD>> {\r\n const map = new Map<TK, TD>();\r\n for (const key in src) {\r\n if (src[key] !== undefined) {\r\n const itemResult = factory(key, src[key]);\r\n if (itemResult.isSuccess()) {\r\n map.set(key, itemResult.value);\r\n } else {\r\n return fail(`${key}: ${itemResult.message}`);\r\n }\r\n }\r\n }\r\n return succeed(map);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`, or `undefined`.\r\n * @param src - The `Record` to be converted, or undefined.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map if conversion succeeds, or {@link Success} with `undefined`\r\n * if `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalRecordToMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD> | undefined> {\r\n return src === undefined ? succeed(undefined) : recordToMap(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`\r\n * @param src - The `Record` to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map (empty if `src` is `undefined`) if conversion succeeds.\r\n * Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalRecordToPossiblyEmptyMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD>> {\r\n return src === undefined ? succeed(new Map<TK, TD>()) : recordToMap(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert a `Map<TK, TS>` into a `Record<TK, TD>`.\r\n * @param src - The `Map` object to be converted.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting `Record<TK, TD>` if conversion succeeds, or\r\n * {@link Failure} with an error message if an error occurs.\r\n * @public\r\n */\r\nexport function mapToRecord<TS, TD, TK extends string = string>(\r\n src: Map<TK, TS>,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD>> {\r\n const record: Record<TK, TD> = {} as Record<TK, TD>;\r\n for (const kvp of src) {\r\n if (kvp[1] !== undefined) {\r\n const itemResult = factory(kvp[0], kvp[1]);\r\n if (itemResult.isSuccess()) {\r\n record[kvp[0]] = itemResult.value;\r\n } else {\r\n return fail(`${kvp[0]}: ${itemResult.message}`);\r\n }\r\n }\r\n }\r\n return succeed(record);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Map<string, TS>` into a `Record<string, TD>` or `undefined`.\r\n * @param src - The `Map` object to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting record if conversion succeeds, or {@link Success} with `undefined` if\r\n * `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalMapToRecord<TS, TD, TK extends string = string>(\r\n src: Map<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD> | undefined> {\r\n return src === undefined ? succeed(undefined) : mapToRecord(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Map<string, TS>` into a `Record<string, TD>`\r\n * @param src - The `Map` object to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting record (empty if `src` is `undefined`) if conversion succeeds.\r\n * Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalMapToPossiblyEmptyRecord<TS, TD, TK extends string = string>(\r\n src: Map<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD>> {\r\n return src === undefined ? succeed({} as Record<TK, TD>) : mapToRecord(src, factory);\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/packlets/base/utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,qCAAiD;AAEjD;;;;;;;GAOG;AACH,wDAAwD;AACxD,SAAgB,OAAO,CAAmB,GAA6B,EAAE,IAAO;IAC9E,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;AAClC,CAAC;AAFD,0BAEC;AAED;;;;;;;GAOG;AACH,SAAgB,IAAI,CAAsC,IAAO,EAAE,OAAY;IAC7E,MAAM,IAAI,GAAwB,EAAE,CAAC;IACrC,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;QACzB,IAAI,GAAG,IAAI,IAAI,EAAE;YACf,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;SACvB;KACF;IACD,OAAO,IAAkB,CAAC;AAC5B,CAAC;AARD,oBAQC;AAED;;;;;;;;GAQG;AACH,SAAgB,IAAI,CAAsC,IAAO,EAAE,OAAY;IAC7E,MAAM,IAAI,GAAwB,EAAE,CAAC;IACrC,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAiB,CAAC,CAAC,EAAE;QAC/F,IAAI,CAAC,KAAK,CAAC,CAAC,CAAgC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;KAC1D;IAED,OAAO,IAAkB,CAAC;AAC5B,CAAC;AAPD,oBAOC;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,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,IAAA,gBAAO,EAAC,EAAoB,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACvF,CAAC;AALD,4EAKC","sourcesContent":["/*\r\n * Copyright (c) 2020 Erik Fortune\r\n *\r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n *\r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n *\r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\nimport { Result, fail, succeed } from './result';\r\n\r\n/**\r\n * Helper type-guard function to report whether a specified key is present in\r\n * a supplied object.\r\n * @param key - The key to be tested.\r\n * @param item - The object to be tested.\r\n * @returns Returns `true` if the key is present, `false` otherwise.\r\n * @public\r\n */\r\n// eslint-disable-next-line @typescript-eslint/ban-types\r\nexport function isKeyOf<T extends object>(key: string | number | symbol, item: T): key is keyof T {\r\n return item.hasOwnProperty(key);\r\n}\r\n\r\n/**\r\n * Simple implicit pick function, which picks a set of properties from a supplied\r\n * object. Ignores picked properties that do not exist regardless of type signature.\r\n * @param from - The object from which keys are to be picked.\r\n * @param include - The keys of the properties to be picked from `from`.\r\n * @returns A new object containing the requested properties from `from`, where present.\r\n * @public\r\n */\r\nexport function pick<T extends object, K extends keyof T>(from: T, include: K[]): Pick<T, K> {\r\n const rtrn: Partial<Pick<T, K>> = {};\r\n for (const key of include) {\r\n if (key in from) {\r\n rtrn[key] = from[key];\r\n }\r\n }\r\n return rtrn as Pick<T, K>;\r\n}\r\n\r\n/**\r\n * Simple implicit omit function, which picks all of the properties from a supplied\r\n * object except those specified for exclusion.\r\n * @param from - The object from which keys are to be picked.\r\n * @param exclude - The keys of the properties to be excluded from the returned object.\r\n * @returns A new object containing all of the properties from `from` that were not\r\n * explicitly excluded.\r\n * @public\r\n */\r\nexport function omit<T extends object, K extends keyof T>(from: T, exclude: K[]): Omit<T, K> {\r\n const rtrn: Partial<Omit<T, K>> = {};\r\n for (const entry of Object.entries(from).filter((e) => !exclude.includes(e[0] as keyof T as K))) {\r\n rtrn[entry[0] as unknown as keyof Omit<T, K>] = entry[1];\r\n }\r\n\r\n return rtrn as Omit<T, K>;\r\n}\r\n\r\n/**\r\n * Gets the value of a property specified by key from an arbitrary object,\r\n * or a default value if the property does not exist.\r\n * @param key - The key specifying the property to be retrieved.\r\n * @param item - The object from which the property is to be retrieved.\r\n * @param defaultValue - An optional default value to be returned if the property\r\n * is not present (default `undefined`).\r\n * @returns The value of the requested property, or the default value if the\r\n * requested property does not exist.\r\n * @public\r\n */\r\nexport function getValueOfPropertyOrDefault<T extends object>(\r\n key: string | number | symbol,\r\n item: T,\r\n defaultValue?: unknown\r\n): unknown | undefined {\r\n return isKeyOf(key, item) ? item[key] : defaultValue;\r\n}\r\n\r\n/**\r\n * Gets the type of a property specified by key from an arbitrary object.\r\n * @param key - The key specifying the property to be tested.\r\n * @param item - The object from which the property is to be tested.\r\n * @returns The type of the requested property, or `undefined` if the\r\n * property does not exist.\r\n * @example\r\n * Returns `'undefined'` (a string) if the property exists but has the value\r\n * undefined but `undefined` (the literal) if the property does not exist.\r\n * @public\r\n */\r\nexport function getTypeOfProperty<T extends object>(\r\n key: string | number | symbol,\r\n item: T\r\n):\r\n | 'string'\r\n | 'number'\r\n | 'bigint'\r\n | 'boolean'\r\n | 'symbol'\r\n | 'undefined'\r\n | 'undefined'\r\n | 'object'\r\n | 'function'\r\n | undefined {\r\n return isKeyOf(key, item) ? typeof item[key] : undefined;\r\n}\r\n\r\n/**\r\n * Type for factory methods which convert a key-value pair to a new unique value.\r\n * @public\r\n */\r\ntype KeyedThingFactory<TS, TD, TK extends string = string> = (key: TK, thing: TS) => Result<TD>;\r\n\r\n/**\r\n * Applies a factory method to convert a `Record<TK, TS>` into a `Map<TK, TD>`.\r\n * @param src - The `Record` to be converted.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map on success, or {@link Failure} with a\r\n * message if an error occurs.\r\n * @public\r\n */\r\nexport function recordToMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS>,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD>> {\r\n const map = new Map<TK, TD>();\r\n for (const key in src) {\r\n if (src[key] !== undefined) {\r\n const itemResult = factory(key, src[key]);\r\n if (itemResult.isSuccess()) {\r\n map.set(key, itemResult.value);\r\n } else {\r\n return fail(`${key}: ${itemResult.message}`);\r\n }\r\n }\r\n }\r\n return succeed(map);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`, or `undefined`.\r\n * @param src - The `Record` to be converted, or undefined.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map if conversion succeeds, or {@link Success} with `undefined`\r\n * if `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalRecordToMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD> | undefined> {\r\n return src === undefined ? succeed(undefined) : recordToMap(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`\r\n * @param src - The `Record` to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map (empty if `src` is `undefined`) if conversion succeeds.\r\n * Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalRecordToPossiblyEmptyMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD>> {\r\n return src === undefined ? succeed(new Map<TK, TD>()) : recordToMap(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert a `ReadonlyMap<TK, TS>` into a `Record<TK, TD>`.\r\n * @param src - The `Map` object to be converted.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting `Record<TK, TD>` if conversion succeeds, or\r\n * {@link Failure} with an error message if an error occurs.\r\n * @public\r\n */\r\nexport function mapToRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS>,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD>> {\r\n const record: Record<TK, TD> = {} as Record<TK, TD>;\r\n for (const kvp of src) {\r\n if (kvp[1] !== undefined) {\r\n const itemResult = factory(kvp[0], kvp[1]);\r\n if (itemResult.isSuccess()) {\r\n record[kvp[0]] = itemResult.value;\r\n } else {\r\n return fail(`${kvp[0]}: ${itemResult.message}`);\r\n }\r\n }\r\n }\r\n return succeed(record);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>` or `undefined`.\r\n * @param src - The `Map` object to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting record if conversion succeeds, or {@link Success} with `undefined` if\r\n * `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalMapToRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD> | undefined> {\r\n return src === undefined ? succeed(undefined) : mapToRecord(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>`\r\n * @param src - The `ReadonlyMap` object to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting record (empty if `src` is `undefined`) if conversion succeeds.\r\n * Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalMapToPossiblyEmptyRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD>> {\r\n return src === undefined ? succeed({} as Record<TK, TD>) : mapToRecord(src, factory);\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Assorted Typescript Utilities",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "dist/ts-utils.d.ts",
|
|
@@ -27,39 +27,39 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/ErikFortune/fgv#readme",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@jest/expect-utils": "^29.
|
|
31
|
-
"@microsoft/api-documenter": "^7.
|
|
32
|
-
"@microsoft/api-extractor": "^7.
|
|
33
|
-
"@types/jest": "^29.5.
|
|
34
|
-
"@types/luxon": "^3.3.
|
|
35
|
-
"@types/mustache": "^4.2.
|
|
36
|
-
"@types/node": "^20.
|
|
37
|
-
"@types/papaparse": "^5.3.
|
|
38
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
39
|
-
"@typescript-eslint/parser": "^
|
|
40
|
-
"eslint": "^8.
|
|
30
|
+
"@jest/expect-utils": "^29.7.0",
|
|
31
|
+
"@microsoft/api-documenter": "^7.23.10",
|
|
32
|
+
"@microsoft/api-extractor": "^7.38.1",
|
|
33
|
+
"@types/jest": "^29.5.7",
|
|
34
|
+
"@types/luxon": "^3.3.3",
|
|
35
|
+
"@types/mustache": "^4.2.4",
|
|
36
|
+
"@types/node": "^20.8.9",
|
|
37
|
+
"@types/papaparse": "^5.3.10",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^6.9.1",
|
|
39
|
+
"@typescript-eslint/parser": "^6.9.1",
|
|
40
|
+
"eslint": "^8.52.0",
|
|
41
41
|
"eslint-config-standard": "^17.1.0",
|
|
42
|
-
"eslint-plugin-import": "^2.
|
|
42
|
+
"eslint-plugin-import": "^2.29.0",
|
|
43
43
|
"eslint-plugin-node": "^11.1.0",
|
|
44
44
|
"eslint-plugin-promise": "^6.1.1",
|
|
45
|
-
"jest": "^29.
|
|
46
|
-
"jest-extended": "^4.0.
|
|
47
|
-
"jest-matcher-utils": "^29.
|
|
48
|
-
"rimraf": "^5.0.
|
|
49
|
-
"ts-jest": "^29.1.
|
|
45
|
+
"jest": "^29.7.0",
|
|
46
|
+
"jest-extended": "^4.0.2",
|
|
47
|
+
"jest-matcher-utils": "^29.7.0",
|
|
48
|
+
"rimraf": "^5.0.5",
|
|
49
|
+
"ts-jest": "^29.1.1",
|
|
50
50
|
"ts-node": "^10.9.1",
|
|
51
|
-
"typescript": "^5.
|
|
52
|
-
"eslint-plugin-n": "^16.
|
|
53
|
-
"jest-snapshot": "~29.
|
|
54
|
-
"@rushstack/heft": "~0.
|
|
55
|
-
"@rushstack/heft-node-rig": "~2.
|
|
56
|
-
"@rushstack/eslint-config": "~3.
|
|
57
|
-
"@types/heft-jest": "1.0.
|
|
58
|
-
"@rushstack/heft-jest-plugin": "~0.
|
|
51
|
+
"typescript": "^5.2.2",
|
|
52
|
+
"eslint-plugin-n": "^16.2.0",
|
|
53
|
+
"jest-snapshot": "~29.7.0",
|
|
54
|
+
"@rushstack/heft": "~0.63.0",
|
|
55
|
+
"@rushstack/heft-node-rig": "~2.3.8",
|
|
56
|
+
"@rushstack/eslint-config": "~3.4.1",
|
|
57
|
+
"@types/heft-jest": "1.0.5",
|
|
58
|
+
"@rushstack/heft-jest-plugin": "~0.10.2",
|
|
59
59
|
"eslint-plugin-tsdoc": "~0.2.17"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"luxon": "^3.3
|
|
62
|
+
"luxon": "^3.4.3",
|
|
63
63
|
"mustache": "^4.2.0",
|
|
64
64
|
"papaparse": "^5.4.1"
|
|
65
65
|
}
|