@jakubmazanec/ts-utils 1.0.0-next.338dfe4 → 1.0.1-39b9d1a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js.map +1 -1
- package/dist/types/AtLeastOneRequired.js.map +1 -1
- package/dist/types/DeepPartial.js.map +1 -1
- package/dist/types/DeepReadonly.js.map +1 -1
- package/dist/types/If.js.map +1 -1
- package/dist/types/IsEqual.js.map +1 -1
- package/dist/types/NonArray.js.map +1 -1
- package/dist/types/NonArrayLike.js.map +1 -1
- package/dist/types/OptionalKeys.js.map +1 -1
- package/dist/types/Parameters.js.map +1 -1
- package/dist/types/Primitive.js.map +1 -1
- package/dist/types/RequiredKeys.js.map +1 -1
- package/dist/types/ReturnType.js.map +1 -1
- package/dist/types/TupleToUnion.js.map +1 -1
- package/dist/types/UnionToIntersection.js.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/assert.js.map +1 -1
- package/dist/utils/is.js.map +1 -1
- package/dist/utils/isNonNullable.js.map +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/main.ts"],"sourcesContent":["export * from './types.js';\nexport * from './utils.js';\n"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"sources":["../src/main.ts"],"sourcesContent":["export * from './types.js';\nexport * from './utils.js';\n"],"names":[],"mappings":"AAAA,cAAc,aAAa;AAC3B,cAAc,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/AtLeastOneRequired.ts"],"sourcesContent":["/**\n * Constructs new type from `T` so that at least one property from the set of properties `P` is required:\n *\n * ```TypeScript\n * import { AtLeastOneRequired } from '@ori/ts-utils';\n *\n * type FooOrBar = AtLeastOneRequired<{foo: string; bar: string; qux: string}, 'foo' | 'bar'>;\n *\n * const fooOrBar1: FooOrBar = {\n * foo: 'this is required',\n * qux: 'this always required',\n * };\n *\n * const fooOrBar2: FooOrBar = {\n * bar: 'or this is required',\n * qux: 'this always required',\n * };\n *\n * const fooOrBar3: FooOrBar = {\n * foo: 'we can have foo',\n * bar: 'and bar',\n * qux: 'this always required',\n * };\n *\n * const fooOrBar4: FooOrBar = {\n * // no foo nor bar\n * qux: 'this always required',\n * }; // error TS2322: Type '{ qux: string; }' is not assignable to type 'FooOrBar'\n * ```\n *\n * @typeParam T Base for the new type\n * @typeParam P String literal or union of string literals specifying properties of `T`\n */\nexport type AtLeastOneRequired<T, P extends keyof T = keyof T> = {\n [K in P]-?: Partial<Pick<T, Exclude<P, K>>> & Required<Pick<T, K>>;\n}[P] &\n Pick<T, Exclude<keyof T, P>>;\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../src/types/AtLeastOneRequired.ts"],"sourcesContent":["/**\n * Constructs new type from `T` so that at least one property from the set of properties `P` is required:\n *\n * ```TypeScript\n * import { AtLeastOneRequired } from '@ori/ts-utils';\n *\n * type FooOrBar = AtLeastOneRequired<{foo: string; bar: string; qux: string}, 'foo' | 'bar'>;\n *\n * const fooOrBar1: FooOrBar = {\n * foo: 'this is required',\n * qux: 'this always required',\n * };\n *\n * const fooOrBar2: FooOrBar = {\n * bar: 'or this is required',\n * qux: 'this always required',\n * };\n *\n * const fooOrBar3: FooOrBar = {\n * foo: 'we can have foo',\n * bar: 'and bar',\n * qux: 'this always required',\n * };\n *\n * const fooOrBar4: FooOrBar = {\n * // no foo nor bar\n * qux: 'this always required',\n * }; // error TS2322: Type '{ qux: string; }' is not assignable to type 'FooOrBar'\n * ```\n *\n * @typeParam T Base for the new type\n * @typeParam P String literal or union of string literals specifying properties of `T`\n */\nexport type AtLeastOneRequired<T, P extends keyof T = keyof T> = {\n [K in P]-?: Partial<Pick<T, Exclude<P, K>>> & Required<Pick<T, K>>;\n}[P] &\n Pick<T, Exclude<keyof T, P>>;\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCC,GACD,WAG+B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/DeepPartial.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-interface -- needed */\n\nimport type {Primitive} from './Primitive.js';\n\n/**\n * Same as built-in `Partial`, but works recursively. Useful when 1) you have a config object to which you need to merge another object, which would be a deep partial of a default object, or 2) you need to test or mock complex object, but most of its keys would be redundant for this purpose.\n *\n * ```TypeScript\n * import { DeepPartial } from '@ori/ts-utils';\n * import { UiSettings } from './UiSettings';\n *\n * let settings: UiSettings = {\n * lineNumbers: true,\n * scrollbar: {\n * useShadows: false,\n * vertical: 'visible',\n * horizontal: 'auto',\n * },\n * minimap: {\n * enabled: false,\n * },\n * folding: {\n * enabled: true,\n * },\n * };\n *\n * function updateSettings(newSettings: DeepPartial<UiSettings>) {\n * return { ...settings, ...newSettings };\n * }\n *\n * settings = updateSettings({ minimap: { enabled: true } });\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type DeepPartial<T> = T extends Date | Primitive | RegExp\n ? T\n : T extends Map<infer KeyType, infer ValueType>\n ? DeepPartialMap<KeyType, ValueType>\n : T extends Set<infer ItemType>\n ? DeepPartialSet<ItemType>\n : T extends ReadonlyMap<infer KeyType, infer ValueType>\n ? DeepPartialReadonlyMap<KeyType, ValueType>\n : T extends ReadonlySet<infer ItemType>\n ? DeepPartialReadonlySet<ItemType>\n : T extends (...args: any[]) => unknown\n ? T | undefined\n : T extends object\n ? T extends Array<infer I> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156\n ? I[] extends T // Test for arrays (non-tuples) specifically\n ? Array<DeepPartial<I | undefined>> // Recreate relevant array type to prevent eager evaluation of circular reference\n : DeepPartialObject<T> // Tuples behave properly\n : DeepPartialObject<T>\n : unknown;\n\n/**\n * Helper type for {@linkcode DeepPartial}.\n */\ninterface DeepPartialMap<KeyType, ValueType>\n extends Map<DeepPartial<KeyType>, DeepPartial<ValueType>> {}\n\n/**\n * Helper type for {@linkcode DeepPartial}.\n */\ninterface DeepPartialSet<T> extends Set<DeepPartial<T>> {}\n\n/**\n * Helper type for {@linkcode DeepPartial}.\n */\ninterface DeepPartialReadonlyMap<KeyType, ValueType>\n extends ReadonlyMap<DeepPartial<KeyType>, DeepPartial<ValueType>> {}\n\n/**\n * Helper type for {@linkcode DeepPartial}.\n */\ninterface DeepPartialReadonlySet<T> extends ReadonlySet<DeepPartial<T>> {}\n\n/**\n * Helper type for {@linkcode DeepPartial}.\n */\ntype DeepPartialObject<ObjectType extends object> = {\n [KeyType in keyof ObjectType]?: DeepPartial<ObjectType[KeyType]>;\n};\n"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/types/DeepPartial.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-interface -- needed */\n\nimport type {Primitive} from './Primitive.js';\n\n/**\n * Same as built-in `Partial`, but works recursively. Useful when 1) you have a config object to which you need to merge another object, which would be a deep partial of a default object, or 2) you need to test or mock complex object, but most of its keys would be redundant for this purpose.\n *\n * ```TypeScript\n * import { DeepPartial } from '@ori/ts-utils';\n * import { UiSettings } from './UiSettings';\n *\n * let settings: UiSettings = {\n * lineNumbers: true,\n * scrollbar: {\n * useShadows: false,\n * vertical: 'visible',\n * horizontal: 'auto',\n * },\n * minimap: {\n * enabled: false,\n * },\n * folding: {\n * enabled: true,\n * },\n * };\n *\n * function updateSettings(newSettings: DeepPartial<UiSettings>) {\n * return { ...settings, ...newSettings };\n * }\n *\n * settings = updateSettings({ minimap: { enabled: true } });\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type DeepPartial<T> = T extends Date | Primitive | RegExp\n ? T\n : T extends Map<infer KeyType, infer ValueType>\n ? DeepPartialMap<KeyType, ValueType>\n : T extends Set<infer ItemType>\n ? DeepPartialSet<ItemType>\n : T extends ReadonlyMap<infer KeyType, infer ValueType>\n ? DeepPartialReadonlyMap<KeyType, ValueType>\n : T extends ReadonlySet<infer ItemType>\n ? DeepPartialReadonlySet<ItemType>\n : T extends (...args: any[]) => unknown\n ? T | undefined\n : T extends object\n ? T extends Array<infer I> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156\n ? I[] extends T // Test for arrays (non-tuples) specifically\n ? Array<DeepPartial<I | undefined>> // Recreate relevant array type to prevent eager evaluation of circular reference\n : DeepPartialObject<T> // Tuples behave properly\n : DeepPartialObject<T>\n : unknown;\n\n/**\n * Helper type for {@linkcode DeepPartial}.\n */\ninterface DeepPartialMap<KeyType, ValueType>\n extends Map<DeepPartial<KeyType>, DeepPartial<ValueType>> {}\n\n/**\n * Helper type for {@linkcode DeepPartial}.\n */\ninterface DeepPartialSet<T> extends Set<DeepPartial<T>> {}\n\n/**\n * Helper type for {@linkcode DeepPartial}.\n */\ninterface DeepPartialReadonlyMap<KeyType, ValueType>\n extends ReadonlyMap<DeepPartial<KeyType>, DeepPartial<ValueType>> {}\n\n/**\n * Helper type for {@linkcode DeepPartial}.\n */\ninterface DeepPartialReadonlySet<T> extends ReadonlySet<DeepPartial<T>> {}\n\n/**\n * Helper type for {@linkcode DeepPartial}.\n */\ntype DeepPartialObject<ObjectType extends object> = {\n [KeyType in keyof ObjectType]?: DeepPartial<ObjectType[KeyType]>;\n};\n"],"names":[],"mappings":"AAAA,sGAAsG,GAEtG,WAgFE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/DeepReadonly.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- needed */\n\nimport type {Primitive} from './Primitive.js';\n\n/**\n * Same as built-in `Readonly`, but works recursively:\n *\n * ```TypeScript\n * import { DeepReadonly } from '@ori/ts-utils';\n *\n * const rawData = {\n * foo: ['bar'],\n * };\n *\n * const data: DeepReadonly<typeof rawData> = rawData;\n *\n * data.foo.push('bar'); // error TS2339: Property 'push' does not exist on type 'readonly string[]'\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type DeepReadonly<T> = T extends Primitive | ((...args: any[]) => unknown)\n ? T\n : T extends ReadonlyMap<infer K, infer V>\n ? DeepReadonlyMap<K, V>\n : T extends ReadonlySet<infer I>\n ? DeepReadonlySet<I>\n : T extends object\n ? DeepReadonlyObject<T>\n : unknown;\n\n/**\n * Helper type for {@linkcode DeepReadonly}.\n */\ntype DeepReadonlyMap<K, V> = ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>;\n\n/**\n * Helper type for {@linkcode DeepReadonly}.\n */\ntype DeepReadonlySet<I> = ReadonlySet<DeepReadonly<I>>;\n\n/**\n * Helper type for {@linkcode DeepReadonly}.\n */\ntype DeepReadonlyObject<O extends object> = {\n readonly [K in keyof O]: DeepReadonly<O[K]>;\n};\n"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/types/DeepReadonly.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- needed */\n\nimport type {Primitive} from './Primitive.js';\n\n/**\n * Same as built-in `Readonly`, but works recursively:\n *\n * ```TypeScript\n * import { DeepReadonly } from '@ori/ts-utils';\n *\n * const rawData = {\n * foo: ['bar'],\n * };\n *\n * const data: DeepReadonly<typeof rawData> = rawData;\n *\n * data.foo.push('bar'); // error TS2339: Property 'push' does not exist on type 'readonly string[]'\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type DeepReadonly<T> = T extends Primitive | ((...args: any[]) => unknown)\n ? T\n : T extends ReadonlyMap<infer K, infer V>\n ? DeepReadonlyMap<K, V>\n : T extends ReadonlySet<infer I>\n ? DeepReadonlySet<I>\n : T extends object\n ? DeepReadonlyObject<T>\n : unknown;\n\n/**\n * Helper type for {@linkcode DeepReadonly}.\n */\ntype DeepReadonlyMap<K, V> = ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>;\n\n/**\n * Helper type for {@linkcode DeepReadonly}.\n */\ntype DeepReadonlySet<I> = ReadonlySet<DeepReadonly<I>>;\n\n/**\n * Helper type for {@linkcode DeepReadonly}.\n */\ntype DeepReadonlyObject<O extends object> = {\n readonly [K in keyof O]: DeepReadonly<O[K]>;\n};\n"],"names":[],"mappings":"AAAA,+DAA+D,GAE/D,WA4CE"}
|
package/dist/types/If.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/If.ts"],"sourcesContent":["/**\n * `If<X, Y, T, F>` is shorthand for conditional type `X extends Y ? T : F`:\n *\n * ```TypeScript\n * // these two types are equivalent:\n * type NonNullable<T> = T extends null | undefined ? never : T;\n * type NonNullable<T> = If<T, null | undefined, never, T>;\n * ```\n *\n * @typeParam X Type on the left of the `extends`\n * @typeParam Y Type on the right of the `extends`\n * @typeParam T Type returned when `X` is assignable to `Y`\n * @typeParam F Type returned when `X` isn't assignable to `Y`\n */\nexport type If<X, Y, T, F> = X extends Y ? T : F;\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../src/types/If.ts"],"sourcesContent":["/**\n * `If<X, Y, T, F>` is shorthand for conditional type `X extends Y ? T : F`:\n *\n * ```TypeScript\n * // these two types are equivalent:\n * type NonNullable<T> = T extends null | undefined ? never : T;\n * type NonNullable<T> = If<T, null | undefined, never, T>;\n * ```\n *\n * @typeParam X Type on the left of the `extends`\n * @typeParam Y Type on the right of the `extends`\n * @typeParam T Type returned when `X` is assignable to `Y`\n * @typeParam F Type returned when `X` isn't assignable to `Y`\n */\nexport type If<X, Y, T, F> = X extends Y ? T : F;\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;CAaC,GACD,WAAiD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/IsEqual.ts"],"sourcesContent":["/**\n * Allows you to test if two types are the same:\n *\n * ```TypeScript\n * type Result = IsEqual<string, number> // `typeof Result` is `false`\n * ```\n *\n * ```TypeScript\n * type Result = IsEqual<{foo: string}, {foo: string}> // `typeof Result` is `true`\n * ```\n *\n * @typeParam A1 First type to compare\n * @typeParam A2 Second type to compare\n */\nexport type IsEqual<A1, A2> = IsStrictlyEqual<Unite<A1>, Unite<A2>>;\n\n/**\n * Helper type for {@linkcode IsEqual}.\n */\ntype IsStrictlyEqual<A1, A2> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1\n ? true\n : false\n ? true\n : false;\n\n/**\n * Helper type for {@linkcode IsEqual}.\n */\ntype Unite<T> = T extends Record<string, unknown> ? {[K in keyof T]: T[K]} : T;\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../src/types/IsEqual.ts"],"sourcesContent":["/**\n * Allows you to test if two types are the same:\n *\n * ```TypeScript\n * type Result = IsEqual<string, number> // `typeof Result` is `false`\n * ```\n *\n * ```TypeScript\n * type Result = IsEqual<{foo: string}, {foo: string}> // `typeof Result` is `true`\n * ```\n *\n * @typeParam A1 First type to compare\n * @typeParam A2 Second type to compare\n */\nexport type IsEqual<A1, A2> = IsStrictlyEqual<Unite<A1>, Unite<A2>>;\n\n/**\n * Helper type for {@linkcode IsEqual}.\n */\ntype IsStrictlyEqual<A1, A2> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1\n ? true\n : false\n ? true\n : false;\n\n/**\n * Helper type for {@linkcode IsEqual}.\n */\ntype Unite<T> = T extends Record<string, unknown> ? {[K in keyof T]: T[K]} : T;\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;CAaC,GACD,WAc+E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/NonArray.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- needed */\n\nexport type NonArray<T> = T extends any[] ? never : T;\n"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/types/NonArray.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- needed */\n\nexport type NonArray<T> = T extends any[] ? never : T;\n"],"names":[],"mappings":"AAAA,+DAA+D,GAE/D,WAAsD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/NonArrayLike.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- needed */\n\nexport type NonArrayLike<T> = T extends ArrayLike<any> ? never : T;\n"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/types/NonArrayLike.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- needed */\n\nexport type NonArrayLike<T> = T extends ArrayLike<any> ? never : T;\n"],"names":[],"mappings":"AAAA,+DAA+D,GAE/D,WAAmE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/OptionalKeys.ts"],"sourcesContent":["/**\n * Extracts the optional keys of type `T`:\n *\n * ```TypeScript\n * type Result = OptionalKeys<{ foo?: number; bar?: string; baz: boolean; }>; // `typeof Result` is `'foo' | 'bar`\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type OptionalKeys<T extends object> = Exclude<\n {\n [K in keyof T]: T extends Record<K, T[K]> ? never : K;\n }[keyof T],\n undefined\n>;\n"],"names":[],"mappings":"AAAA;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../src/types/OptionalKeys.ts"],"sourcesContent":["/**\n * Extracts the optional keys of type `T`:\n *\n * ```TypeScript\n * type Result = OptionalKeys<{ foo?: number; bar?: string; baz: boolean; }>; // `typeof Result` is `'foo' | 'bar`\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type OptionalKeys<T extends object> = Exclude<\n {\n [K in keyof T]: T extends Record<K, T[K]> ? never : K;\n }[keyof T],\n undefined\n>;\n"],"names":[],"mappings":"AAAA;;;;;;;;CAQC,GACD,WAKE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/Parameters.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- needed */\n\n/**\n * Constructs a tuple type from the types used in the parameters of a function type `T`.\n * Similarly like built-in `Parameters` utility type, but works also on nullable and other types.\n *\n * ```TypeScript\n * interface Foo {\n * get?: (id: number) => string;\n * }\n *\n * declare const foo: Foo;\n *\n * type Result = Parameters<typeof foo.get>; // `typeof Result` is `[id: number]`\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type Parameters<T extends '' | false | ((...args: any[]) => any) | null | undefined> =\n T extends (...args: infer P) => any ? P : never;\n"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/types/Parameters.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- needed */\n\n/**\n * Constructs a tuple type from the types used in the parameters of a function type `T`.\n * Similarly like built-in `Parameters` utility type, but works also on nullable and other types.\n *\n * ```TypeScript\n * interface Foo {\n * get?: (id: number) => string;\n * }\n *\n * declare const foo: Foo;\n *\n * type Result = Parameters<typeof foo.get>; // `typeof Result` is `[id: number]`\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type Parameters<T extends '' | false | ((...args: any[]) => any) | null | undefined> =\n T extends (...args: infer P) => any ? P : never;\n"],"names":[],"mappings":"AAAA,+DAA+D,GAE/D;;;;;;;;;;;;;;;CAeC,GACD,WACkD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/Primitive.ts"],"sourcesContent":["/**\n * Union of primitive types.\n */\nexport type Primitive = bigint | boolean | number | string | symbol | null | undefined;\n"],"names":[],"mappings":"AAAA;;
|
|
1
|
+
{"version":3,"sources":["../../src/types/Primitive.ts"],"sourcesContent":["/**\n * Union of primitive types.\n */\nexport type Primitive = bigint | boolean | number | string | symbol | null | undefined;\n"],"names":[],"mappings":"AAAA;;CAEC,GACD,WAAuF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/RequiredKeys.ts"],"sourcesContent":["/**\n * Extracts the non-optional keys of type `T`:\n *\n * ```TypeScript\n * type Result = RequiredKeys<{ foo: number; bar: string; baz?: boolean; }>; // `typeof Result` is `'foo' | 'bar`\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type RequiredKeys<T extends object> = Exclude<\n {\n [K in keyof T]: T extends Record<K, T[K]> ? K : never;\n }[keyof T],\n undefined\n>;\n"],"names":[],"mappings":"AAAA;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../src/types/RequiredKeys.ts"],"sourcesContent":["/**\n * Extracts the non-optional keys of type `T`:\n *\n * ```TypeScript\n * type Result = RequiredKeys<{ foo: number; bar: string; baz?: boolean; }>; // `typeof Result` is `'foo' | 'bar`\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type RequiredKeys<T extends object> = Exclude<\n {\n [K in keyof T]: T extends Record<K, T[K]> ? K : never;\n }[keyof T],\n undefined\n>;\n"],"names":[],"mappings":"AAAA;;;;;;;;CAQC,GACD,WAKE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/ReturnType.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- needed */\n\n/**\n * Constructs a type consisting of the return type of function `T`.\n * Similarly like built-in `ReturnType` utility type, but works also on nullable and other types,\n * and if you use it with async function, it doesn't return the type as a `Promise`:\n *\n * ```TypeScript\n * interface Foo {\n * get?: (id: number) => Promise<string>;\n * }\n *\n * declare const foo: Foo;\n *\n * type Result = ReturnType<typeof foo.get>; // `typeof Result` is `string`\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type ReturnType<T extends '' | false | ((...args: any[]) => any) | null | undefined> =\n T extends (...args: any[]) => infer R ? (R extends PromiseLike<infer J> ? J : R) : never;\n"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/types/ReturnType.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- needed */\n\n/**\n * Constructs a type consisting of the return type of function `T`.\n * Similarly like built-in `ReturnType` utility type, but works also on nullable and other types,\n * and if you use it with async function, it doesn't return the type as a `Promise`:\n *\n * ```TypeScript\n * interface Foo {\n * get?: (id: number) => Promise<string>;\n * }\n *\n * declare const foo: Foo;\n *\n * type Result = ReturnType<typeof foo.get>; // `typeof Result` is `string`\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type ReturnType<T extends '' | false | ((...args: any[]) => any) | null | undefined> =\n T extends (...args: any[]) => infer R ? (R extends PromiseLike<infer J> ? J : R) : never;\n"],"names":[],"mappings":"AAAA,+DAA+D,GAE/D;;;;;;;;;;;;;;;;CAgBC,GACD,WAC2F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/TupleToUnion.ts"],"sourcesContent":["/**\n * Converts tuple type to union type:\n *\n * ```TypeScript\n * type Result = TupleToUnion<['foo', 'bar']>; // `typeof Result` is `\"foo\" | \"bar\"`\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type TupleToUnion<T extends unknown[] | readonly unknown[]> = T[number];\n"],"names":[],"mappings":"AAAA;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../src/types/TupleToUnion.ts"],"sourcesContent":["/**\n * Converts tuple type to union type:\n *\n * ```TypeScript\n * type Result = TupleToUnion<['foo', 'bar']>; // `typeof Result` is `\"foo\" | \"bar\"`\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type TupleToUnion<T extends unknown[] | readonly unknown[]> = T[number];\n"],"names":[],"mappings":"AAAA;;;;;;;;CAQC,GACD,WAA+E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/UnionToIntersection.ts"],"sourcesContent":["/**\n * Converts union type to intersection type:\n *\n * ```TypeScript\n * type Result = UnionToIntersection<{ foo: string } | { bar: string }>; // `typeof Result` is `{foo: string} & {bar: string}`\n * ```\n *\n * @typeParam U Base for the new type\n */\nexport type UnionToIntersection<U> = boolean extends U\n ? UnionToIntersectionHelper<Exclude<U, boolean>> & boolean\n : UnionToIntersectionHelper<U>;\n\n/**\n * Helper type for {@linkcode UnionToIntersection}.\n */\ntype UnionToIntersectionHelper<U> = (U extends unknown ? (k: U) => void : never) extends (\n k: infer I,\n) => void\n ? I\n : never;\n"],"names":[],"mappings":"AAAA;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../src/types/UnionToIntersection.ts"],"sourcesContent":["/**\n * Converts union type to intersection type:\n *\n * ```TypeScript\n * type Result = UnionToIntersection<{ foo: string } | { bar: string }>; // `typeof Result` is `{foo: string} & {bar: string}`\n * ```\n *\n * @typeParam U Base for the new type\n */\nexport type UnionToIntersection<U> = boolean extends U\n ? UnionToIntersectionHelper<Exclude<U, boolean>> & boolean\n : UnionToIntersectionHelper<U>;\n\n/**\n * Helper type for {@linkcode UnionToIntersection}.\n */\ntype UnionToIntersectionHelper<U> = (U extends unknown ? (k: U) => void : never) extends (\n k: infer I,\n) => void\n ? I\n : never;\n"],"names":[],"mappings":"AAAA;;;;;;;;CAQC,GACD,WAWU"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["export * from './types/AtLeastOneRequired.js';\nexport * from './types/DeepPartial.js';\nexport * from './types/DeepReadonly.js';\nexport * from './types/If.js';\nexport * from './types/IsEqual.js';\nexport * from './types/LiteralUnion.js';\nexport * from './types/NonArray.js';\nexport * from './types/NonArrayLike.js';\nexport * from './types/OptionalKeys.js';\nexport * from './types/Parameters.js';\nexport * from './types/Primitive.js';\nexport * from './types/RequiredKeys.js';\nexport * from './types/ReturnType.js';\nexport * from './types/TupleToUnion.js';\nexport * from './types/UnionToIntersection.js';\n"],"names":[],"mappings":"AAAA,cAAc
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["export * from './types/AtLeastOneRequired.js';\nexport * from './types/DeepPartial.js';\nexport * from './types/DeepReadonly.js';\nexport * from './types/If.js';\nexport * from './types/IsEqual.js';\nexport * from './types/LiteralUnion.js';\nexport * from './types/NonArray.js';\nexport * from './types/NonArrayLike.js';\nexport * from './types/OptionalKeys.js';\nexport * from './types/Parameters.js';\nexport * from './types/Primitive.js';\nexport * from './types/RequiredKeys.js';\nexport * from './types/ReturnType.js';\nexport * from './types/TupleToUnion.js';\nexport * from './types/UnionToIntersection.js';\n"],"names":[],"mappings":"AAAA,cAAc,gCAAgC;AAC9C,cAAc,yBAAyB;AACvC,cAAc,0BAA0B;AACxC,cAAc,gBAAgB;AAC9B,cAAc,qBAAqB;AACnC,cAAc,0BAA0B;AACxC,cAAc,sBAAsB;AACpC,cAAc,0BAA0B;AACxC,cAAc,0BAA0B;AACxC,cAAc,wBAAwB;AACtC,cAAc,uBAAuB;AACrC,cAAc,0BAA0B;AACxC,cAAc,wBAAwB;AACtC,cAAc,0BAA0B;AACxC,cAAc,iCAAiC"}
|
package/dist/utils/assert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/assert.ts"],"sourcesContent":["/**\n * A subclass of `Error` that indicates an assertion failure.\n */\nexport class AssertionError extends Error {\n /**\n * @param message Message added to the default error message\n */\n constructor(message?: string) {\n super(`Wrong assertion encountered${message ? `: \"${message}\"` : ''}!`);\n\n this.name = 'AssertionError';\n }\n}\n\n/**\n * A function that throws {@linkcode AssertionError} (with optional message defined with `errorMessage`) if\n * `condition` is falsy.\n * You can use it to narrow types:\n *\n * ```TypeScript\n * interface Foo {\n * kind: 'Foo';\n * }\n *\n * interface Bar {\n * kind: 'Bar';\n * }\n *\n * declare const foobar: Foo | Bar;\n *\n * assert(is<Foo>(foobar, foobar.kind === 'Foo'));\n *\n * // `typeof foobar` is now `Foo`\n * ```\n *\n * @param condition Condition we're asserting isn't falsy\n * @param errorMessage Message for the `AssertionError`\n */\nexport function assert(condition: unknown, errorMessage?: string): asserts condition {\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- we don't mind here\n if (!condition) {\n throw new AssertionError(errorMessage);\n }\n}\n"],"names":["AssertionError","Error","constructor","message","name","assert","condition","errorMessage"],"mappings":"AAAA;;
|
|
1
|
+
{"version":3,"sources":["../../src/utils/assert.ts"],"sourcesContent":["/**\n * A subclass of `Error` that indicates an assertion failure.\n */\nexport class AssertionError extends Error {\n /**\n * @param message Message added to the default error message\n */\n constructor(message?: string) {\n super(`Wrong assertion encountered${message ? `: \"${message}\"` : ''}!`);\n\n this.name = 'AssertionError';\n }\n}\n\n/**\n * A function that throws {@linkcode AssertionError} (with optional message defined with `errorMessage`) if\n * `condition` is falsy.\n * You can use it to narrow types:\n *\n * ```TypeScript\n * interface Foo {\n * kind: 'Foo';\n * }\n *\n * interface Bar {\n * kind: 'Bar';\n * }\n *\n * declare const foobar: Foo | Bar;\n *\n * assert(is<Foo>(foobar, foobar.kind === 'Foo'));\n *\n * // `typeof foobar` is now `Foo`\n * ```\n *\n * @param condition Condition we're asserting isn't falsy\n * @param errorMessage Message for the `AssertionError`\n */\nexport function assert(condition: unknown, errorMessage?: string): asserts condition {\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- we don't mind here\n if (!condition) {\n throw new AssertionError(errorMessage);\n }\n}\n"],"names":["AssertionError","Error","constructor","message","name","assert","condition","errorMessage"],"mappings":"AAAA;;CAEC,GACD,OAAO,MAAMA,uBAAuBC;IAClC;;GAEC,GACDC,YAAYC,OAAgB,CAAE;QAC5B,KAAK,CAAC,CAAC,2BAA2B,EAAEA,UAAU,CAAC,GAAG,EAAEA,QAAQ,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAEtE,IAAI,CAACC,IAAI,GAAG;IACd;AACF,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GACD,OAAO,SAASC,OAAOC,SAAkB,EAAEC,YAAqB,EAAqB;IACnF,+FAA+F;IAC/F,IAAI,CAACD,WAAW;QACd,MAAM,IAAIN,eAAeO,cAAc;IACzC,CAAC;AACH,CAAC"}
|
package/dist/utils/is.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/is.ts"],"sourcesContent":["/**\n * A generic type guard. If `isMatched` is `true`, TypeScript assumes `value` is of type `T`.\n * You can use it to narrow types:\n *\n * ```TypeScript\n * interface Foo {\n * value: string;\n * }\n *\n * interface Bar {\n * value: number;\n * }\n *\n * declare let foobar: Foo | Bar;\n *\n * if (is<Foo>(foobar, typeof foobar.value === 'string')) {\n * // `typeof foobar` is now `Foo`\n * } else {\n * // `typeof foobar` is now `Bar`\n * }\n * ```\n *\n * @typeParam T Potential type of `value`\n * @param value Value being checked\n * @param isMatched Specifies if `value` is of type `T`\n * @return Value of `isMatched`\n */\nexport function is<T>(value: unknown, isMatched: boolean): value is T {\n return isMatched;\n}\n"],"names":["is","value","isMatched"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../src/utils/is.ts"],"sourcesContent":["/**\n * A generic type guard. If `isMatched` is `true`, TypeScript assumes `value` is of type `T`.\n * You can use it to narrow types:\n *\n * ```TypeScript\n * interface Foo {\n * value: string;\n * }\n *\n * interface Bar {\n * value: number;\n * }\n *\n * declare let foobar: Foo | Bar;\n *\n * if (is<Foo>(foobar, typeof foobar.value === 'string')) {\n * // `typeof foobar` is now `Foo`\n * } else {\n * // `typeof foobar` is now `Bar`\n * }\n * ```\n *\n * @typeParam T Potential type of `value`\n * @param value Value being checked\n * @param isMatched Specifies if `value` is of type `T`\n * @return Value of `isMatched`\n */\nexport function is<T>(value: unknown, isMatched: boolean): value is T {\n return isMatched;\n}\n"],"names":["is","value","isMatched"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BC,GACD,OAAO,SAASA,GAAMC,KAAc,EAAEC,SAAkB,EAAc;IACpE,OAAOA;AACT,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/isNonNullable.ts"],"sourcesContent":["/**\n * A type guard that checks whether variable is not `null` or `undefined`:\n *\n * ```TypeScript\n * declare let foobar: string | null;\n *\n * if (isNonNullable(foobar)) {\n * // `typeof foobar` is now `string`\n * } else {\n * // `typeof foobar` is now `null`\n * }\n * ```\n *\n * @typeParam T Type of `value`\n * @param value Value being checked\n * @return `true` if `value` is non-nullable\n */\nexport function isNonNullable<T>(value: T): value is NonNullable<T> {\n return value !== undefined && value !== null;\n}\n"],"names":["isNonNullable","value","undefined"],"mappings":"AAAA;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../src/utils/isNonNullable.ts"],"sourcesContent":["/**\n * A type guard that checks whether variable is not `null` or `undefined`:\n *\n * ```TypeScript\n * declare let foobar: string | null;\n *\n * if (isNonNullable(foobar)) {\n * // `typeof foobar` is now `string`\n * } else {\n * // `typeof foobar` is now `null`\n * }\n * ```\n *\n * @typeParam T Type of `value`\n * @param value Value being checked\n * @return `true` if `value` is non-nullable\n */\nexport function isNonNullable<T>(value: T): value is NonNullable<T> {\n return value !== undefined && value !== null;\n}\n"],"names":["isNonNullable","value","undefined"],"mappings":"AAAA;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,SAASA,cAAiBC,KAAQ,EAA2B;IAClE,OAAOA,UAAUC,aAAaD,UAAU,IAAI;AAC9C,CAAC"}
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["export * from './utils/assert.js';\nexport * from './utils/is.js';\nexport * from './utils/isNonNullable.js';\n"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["export * from './utils/assert.js';\nexport * from './utils/is.js';\nexport * from './utils/isNonNullable.js';\n"],"names":[],"mappings":"AAAA,cAAc,oBAAoB;AAClC,cAAc,gBAAgB;AAC9B,cAAc,2BAA2B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jakubmazanec/ts-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-39b9d1a",
|
|
4
4
|
"description": "Collection of TypeScript types and utilities.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@jest/globals": "^28.1.3"
|
|
30
30
|
},
|
|
31
|
-
"packageManager": "npm@8.
|
|
31
|
+
"packageManager": "npm@8.19.2",
|
|
32
32
|
"engines": {
|
|
33
|
-
"node": ">=16.
|
|
33
|
+
"node": ">=16.18.1"
|
|
34
34
|
}
|
|
35
35
|
}
|