@fgv/ts-utils 5.1.0-27 → 5.1.0-28

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.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/packlets/base/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAU,IAAI,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,UAAU,OAAO,CAAmB,GAA6B,EAAE,IAAO;IAC9E,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;AAClC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,IAAI,CAAsC,IAAO,EAAE,OAAY;IAC7E,MAAM,IAAI,GAAwB,EAAE,CAAC;IACrC,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;YAChB,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IACD,OAAO,IAAkB,CAAC;AAC5B,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,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,CAAC;QAChG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAgC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,IAAkB,CAAC;AAC5B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aA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CAAC;YAC3C,IAAI,UAAU,CAAC,SAAS,EAAE,EAAE,CAAC;gBAC3B,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC;YACpC,CAAC;iBAAM,CAAC;gBACN,OAAO,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;AACzB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CACjC,GAAoC,EACpC,OAAsC;IAEtC,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gCAAgC,CAC9C,GAAoC,EACpC,OAAsC;IAEtC,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,EAAoB,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACvF,CAAC","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\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 * Type-safe(ish) key extractor for typed records.\r\n * @param obj - The record from which keys are to be extracted.\r\n * @returns The keys of the record as an array.\r\n * @public\r\n */\r\nexport function keysForRecord<TK extends string>(obj: Record<TK, unknown>): TK[] {\r\n return Object.keys(obj) as TK[];\r\n}\r\n\r\n/**\r\n * Type-safe(ish) value extractor for typed records.\r\n * @param obj - The record from which values are to be extracted.\r\n * @returns The values of the record as an array.\r\n * @public\r\n */\r\nexport function valuesForRecord<TK extends string, TV>(obj: Record<TK, TV>): TV[] {\r\n return Object.values(obj) as TV[];\r\n}\r\n\r\n/**\r\n * Type-safe(ish) entries extractor for typed records.\r\n * @param obj - The record from which entries are to be extracted.\r\n * @returns The entries of the record as an array of `[key, value]` tuples.\r\n * @public\r\n */\r\nexport function entriesForRecord<TK extends string, TV>(obj: Record<TK, TV>): Array<[TK, TV]> {\r\n return Object.entries(obj) as Array<[TK, TV]>;\r\n}\r\n\r\n/**\r\n * Type-safe(ish) record constructor from an iterable of `[key, value]` tuples.\r\n * @param entries - The iterable of `[key, value]` tuples from which to construct the record.\r\n * @returns A record constructed from the supplied entries.\r\n * @public\r\n */\r\nexport function recordFromEntries<TK extends string, TV>(entries: Iterable<[TK, TV]>): Record<TK, TV> {\r\n return Object.fromEntries(entries) as Record<TK, TV>;\r\n}\r\n\r\n/**\r\n * Helper type to extract the element type and preserve readonly status.\r\n * @public\r\n */\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nexport type EnsureArrayResult<T> = T extends readonly (infer _U)[] ? T : T[];\r\n\r\n/**\r\n * Ensures the input is an array. If already an array, returns it as-is.\r\n * If a single item, wraps it in an array.\r\n * Preserves readonly status of input arrays.\r\n * @param items - A single item or an array of items.\r\n * @returns The input array unchanged, or a new array containing the single item.\r\n * @public\r\n */\r\nexport function ensureArray<T>(items: T): EnsureArrayResult<T> {\r\n return (Array.isArray(items) ? items : [items]) as EnsureArrayResult<T>;\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"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/packlets/base/utils.ts"],"names":[],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,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;AACzB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CACjC,GAAoC,EACpC,OAAsC;IAEtC,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gCAAgC,CAC9C,GAAoC,EACpC,OAAsC;IAEtC,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,EAAoB,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACvF,CAAC","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 * Union of all values in an array/tuple type, preserving literal types if possible.\r\n * If T is not an array/tuple, results in `never`.\r\n * @public\r\n */\r\nexport type OneOf<T> = T extends readonly unknown[] ? T[number] : never;\r\n\r\n/**\r\n * Union of all string values in an array/tuple type, preserving literal types if possible.\r\n * If T is not an array/tuple, results in `never`.\r\n * @public\r\n */\r\nexport type StringOneOf<T> = Extract<OneOf<T>, string>;\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\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 * Type-safe(ish) key extractor for typed records.\r\n * @param obj - The record from which keys are to be extracted.\r\n * @returns The keys of the record as an array.\r\n * @public\r\n */\r\nexport function keysForRecord<TK extends string>(obj: Record<TK, unknown>): TK[] {\r\n return Object.keys(obj) as TK[];\r\n}\r\n\r\n/**\r\n * Type-safe(ish) value extractor for typed records.\r\n * @param obj - The record from which values are to be extracted.\r\n * @returns The values of the record as an array.\r\n * @public\r\n */\r\nexport function valuesForRecord<TK extends string, TV>(obj: Record<TK, TV>): TV[] {\r\n return Object.values(obj) as TV[];\r\n}\r\n\r\n/**\r\n * Type-safe(ish) entries extractor for typed records.\r\n * @param obj - The record from which entries are to be extracted.\r\n * @returns The entries of the record as an array of `[key, value]` tuples.\r\n * @public\r\n */\r\nexport function entriesForRecord<TK extends string, TV>(obj: Record<TK, TV>): Array<[TK, TV]> {\r\n return Object.entries(obj) as Array<[TK, TV]>;\r\n}\r\n\r\n/**\r\n * Type-safe(ish) record constructor from an iterable of `[key, value]` tuples.\r\n * @param entries - The iterable of `[key, value]` tuples from which to construct the record.\r\n * @returns A record constructed from the supplied entries.\r\n * @public\r\n */\r\nexport function recordFromEntries<TK extends string, TV>(entries: Iterable<[TK, TV]>): Record<TK, TV> {\r\n return Object.fromEntries(entries) as Record<TK, TV>;\r\n}\r\n\r\n/**\r\n * Helper type to extract the element type and preserve readonly status.\r\n * @public\r\n */\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nexport type EnsureArrayResult<T> = T extends readonly (infer _U)[] ? T : T[];\r\n\r\n/**\r\n * Ensures the input is an array. If already an array, returns it as-is.\r\n * If a single item, wraps it in an array.\r\n * Preserves readonly status of input arrays.\r\n * @param items - A single item or an array of items.\r\n * @returns The input array unchanged, or a new array containing the single item.\r\n * @public\r\n */\r\nexport function ensureArray<T>(items: T): EnsureArrayResult<T> {\r\n return (Array.isArray(items) ? items : [items]) as EnsureArrayResult<T>;\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"]}
@@ -4934,6 +4934,13 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
4934
4934
  */
4935
4935
  export declare function omit<T extends object, K extends keyof T>(from: T, exclude: K[]): Omit<T, K>;
4936
4936
 
4937
+ /**
4938
+ * Union of all values in an array/tuple type, preserving literal types if possible.
4939
+ * If T is not an array/tuple, results in `never`.
4940
+ * @public
4941
+ */
4942
+ export declare type OneOf<T> = T extends readonly unknown[] ? T[number] : never;
4943
+
4937
4944
  /**
4938
4945
  * A helper function to create a {@link Converter | Converter} for polymorphic values.
4939
4946
  * Returns a converter which invokes the wrapped converters in sequence, returning the
@@ -5845,6 +5852,13 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
5845
5852
  message?: string;
5846
5853
  }
5847
5854
 
5855
+ /**
5856
+ * Union of all string values in an array/tuple type, preserving literal types if possible.
5857
+ * If T is not an array/tuple, results in `never`.
5858
+ * @public
5859
+ */
5860
+ export declare type StringOneOf<T> = Extract<OneOf<T>, string>;
5861
+
5848
5862
  /**
5849
5863
  * An in-place {@link Validation.Validator | Validator} for `string` values.
5850
5864
  * @public
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.57.7"
8
+ "packageVersion": "7.58.7"
9
9
  }
10
10
  ]
11
11
  }
@@ -1,4 +1,16 @@
1
1
  import { Result } from './result';
2
+ /**
3
+ * Union of all values in an array/tuple type, preserving literal types if possible.
4
+ * If T is not an array/tuple, results in `never`.
5
+ * @public
6
+ */
7
+ export type OneOf<T> = T extends readonly unknown[] ? T[number] : never;
8
+ /**
9
+ * Union of all string values in an array/tuple type, preserving literal types if possible.
10
+ * If T is not an array/tuple, results in `never`.
11
+ * @public
12
+ */
13
+ export type StringOneOf<T> = Extract<OneOf<T>, string>;
2
14
  /**
3
15
  * Helper type-guard function to report whether a specified key is present in
4
16
  * a supplied object.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../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,EAAE,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,IAAA,gBAAO,EAAC,MAAM,CAAC,CAAC;AACzB,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CACjC,GAAoC,EACpC,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;AAED;;;;;;;GAOG;AACH,SAAgB,gCAAgC,CAC9C,GAAoC,EACpC,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","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\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 * Type-safe(ish) key extractor for typed records.\r\n * @param obj - The record from which keys are to be extracted.\r\n * @returns The keys of the record as an array.\r\n * @public\r\n */\r\nexport function keysForRecord<TK extends string>(obj: Record<TK, unknown>): TK[] {\r\n return Object.keys(obj) as TK[];\r\n}\r\n\r\n/**\r\n * Type-safe(ish) value extractor for typed records.\r\n * @param obj - The record from which values are to be extracted.\r\n * @returns The values of the record as an array.\r\n * @public\r\n */\r\nexport function valuesForRecord<TK extends string, TV>(obj: Record<TK, TV>): TV[] {\r\n return Object.values(obj) as TV[];\r\n}\r\n\r\n/**\r\n * Type-safe(ish) entries extractor for typed records.\r\n * @param obj - The record from which entries are to be extracted.\r\n * @returns The entries of the record as an array of `[key, value]` tuples.\r\n * @public\r\n */\r\nexport function entriesForRecord<TK extends string, TV>(obj: Record<TK, TV>): Array<[TK, TV]> {\r\n return Object.entries(obj) as Array<[TK, TV]>;\r\n}\r\n\r\n/**\r\n * Type-safe(ish) record constructor from an iterable of `[key, value]` tuples.\r\n * @param entries - The iterable of `[key, value]` tuples from which to construct the record.\r\n * @returns A record constructed from the supplied entries.\r\n * @public\r\n */\r\nexport function recordFromEntries<TK extends string, TV>(entries: Iterable<[TK, TV]>): Record<TK, TV> {\r\n return Object.fromEntries(entries) as Record<TK, TV>;\r\n}\r\n\r\n/**\r\n * Helper type to extract the element type and preserve readonly status.\r\n * @public\r\n */\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nexport type EnsureArrayResult<T> = T extends readonly (infer _U)[] ? T : T[];\r\n\r\n/**\r\n * Ensures the input is an array. If already an array, returns it as-is.\r\n * If a single item, wraps it in an array.\r\n * Preserves readonly status of input arrays.\r\n * @param items - A single item or an array of items.\r\n * @returns The input array unchanged, or a new array containing the single item.\r\n * @public\r\n */\r\nexport function ensureArray<T>(items: T): EnsureArrayResult<T> {\r\n return (Array.isArray(items) ? items : [items]) as EnsureArrayResult<T>;\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"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/packlets/base/utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;AA0BH,0BAEC;AAUD,oBAQC;AAWD,oBAOC;AAQD,sCAEC;AAQD,0CAEC;AAQD,4CAEC;AAQD,8CAEC;AAiBD,kCAEC;AAaD,kEAMC;AAaD,8CAeC;AAgBD,kCAgBC;AAUD,kDAKC;AAUD,4EAKC;AAUD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ACH,CAAC;IACD,OAAO,IAAA,gBAAO,EAAC,MAAM,CAAC,CAAC;AACzB,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CACjC,GAAoC,EACpC,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;AAED;;;;;;;GAOG;AACH,SAAgB,gCAAgC,CAC9C,GAAoC,EACpC,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","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 * Union of all values in an array/tuple type, preserving literal types if possible.\r\n * If T is not an array/tuple, results in `never`.\r\n * @public\r\n */\r\nexport type OneOf<T> = T extends readonly unknown[] ? T[number] : never;\r\n\r\n/**\r\n * Union of all string values in an array/tuple type, preserving literal types if possible.\r\n * If T is not an array/tuple, results in `never`.\r\n * @public\r\n */\r\nexport type StringOneOf<T> = Extract<OneOf<T>, string>;\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\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 * Type-safe(ish) key extractor for typed records.\r\n * @param obj - The record from which keys are to be extracted.\r\n * @returns The keys of the record as an array.\r\n * @public\r\n */\r\nexport function keysForRecord<TK extends string>(obj: Record<TK, unknown>): TK[] {\r\n return Object.keys(obj) as TK[];\r\n}\r\n\r\n/**\r\n * Type-safe(ish) value extractor for typed records.\r\n * @param obj - The record from which values are to be extracted.\r\n * @returns The values of the record as an array.\r\n * @public\r\n */\r\nexport function valuesForRecord<TK extends string, TV>(obj: Record<TK, TV>): TV[] {\r\n return Object.values(obj) as TV[];\r\n}\r\n\r\n/**\r\n * Type-safe(ish) entries extractor for typed records.\r\n * @param obj - The record from which entries are to be extracted.\r\n * @returns The entries of the record as an array of `[key, value]` tuples.\r\n * @public\r\n */\r\nexport function entriesForRecord<TK extends string, TV>(obj: Record<TK, TV>): Array<[TK, TV]> {\r\n return Object.entries(obj) as Array<[TK, TV]>;\r\n}\r\n\r\n/**\r\n * Type-safe(ish) record constructor from an iterable of `[key, value]` tuples.\r\n * @param entries - The iterable of `[key, value]` tuples from which to construct the record.\r\n * @returns A record constructed from the supplied entries.\r\n * @public\r\n */\r\nexport function recordFromEntries<TK extends string, TV>(entries: Iterable<[TK, TV]>): Record<TK, TV> {\r\n return Object.fromEntries(entries) as Record<TK, TV>;\r\n}\r\n\r\n/**\r\n * Helper type to extract the element type and preserve readonly status.\r\n * @public\r\n */\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nexport type EnsureArrayResult<T> = T extends readonly (infer _U)[] ? T : T[];\r\n\r\n/**\r\n * Ensures the input is an array. If already an array, returns it as-is.\r\n * If a single item, wraps it in an array.\r\n * Preserves readonly status of input arrays.\r\n * @param items - A single item or an array of items.\r\n * @returns The input array unchanged, or a new array containing the single item.\r\n * @public\r\n */\r\nexport function ensureArray<T>(items: T): EnsureArrayResult<T> {\r\n return (Array.isArray(items) ? items : [items]) as EnsureArrayResult<T>;\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": "5.1.0-27",
3
+ "version": "5.1.0-28",
4
4
  "description": "Assorted Typescript Utilities",
5
5
  "main": "lib/index.js",
6
6
  "module": "dist/index.js",
@@ -54,8 +54,8 @@
54
54
  "@rushstack/heft-jest-plugin": "1.2.6",
55
55
  "eslint-plugin-tsdoc": "~0.5.2",
56
56
  "typedoc": "~0.28.16",
57
- "@fgv/heft-dual-rig": "5.1.0-27",
58
- "@fgv/typedoc-compact-theme": "5.1.0-27"
57
+ "@fgv/heft-dual-rig": "5.1.0-28",
58
+ "@fgv/typedoc-compact-theme": "5.1.0-28"
59
59
  },
60
60
  "repository": {
61
61
  "type": "git",