@jakubmazanec/ts-utils 2.0.0 → 2.1.0-a500263
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/README.md +1 -1
- package/dist/types/IsEqual.d.ts +3 -14
- package/dist/types/IsEqual.js +2 -2
- package/dist/types/IsEqual.js.map +1 -1
- package/dist/types/Simplify.d.ts +8 -0
- package/dist/types/Simplify.js +7 -0
- package/dist/types/Simplify.js.map +1 -0
- package/dist/types/TupleToUnion.d.ts +1 -1
- package/dist/types/TupleToUnion.js +1 -1
- package/dist/types/TupleToUnion.js.map +1 -1
- package/dist/types/Writable.d.ts +6 -0
- package/dist/types/Writable.js +5 -0
- package/dist/types/Writable.js.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +2 -0
- 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/tuple.d.ts +2 -0
- package/dist/utils/tuple.js +6 -0
- package/dist/utils/tuple.js.map +1 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +1 -0
- package/dist/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/types/IsEqual.ts +3 -15
- package/src/types/Simplify.ts +6 -0
- package/src/types/TupleToUnion.ts +1 -1
- package/src/types/Writable.ts +6 -0
- package/src/types.ts +2 -0
- package/src/utils/tuple.ts +6 -0
- package/src/utils.ts +1 -0
package/README.md
CHANGED
package/dist/types/IsEqual.d.ts
CHANGED
|
@@ -9,18 +9,7 @@
|
|
|
9
9
|
* type Result = IsEqual<{foo: string}, {foo: string}> // `typeof Result` is `true`
|
|
10
10
|
* ```
|
|
11
11
|
*
|
|
12
|
-
* @typeParam
|
|
13
|
-
* @typeParam
|
|
12
|
+
* @typeParam T First type to compare
|
|
13
|
+
* @typeParam U Second type to compare
|
|
14
14
|
*/
|
|
15
|
-
export type IsEqual<
|
|
16
|
-
/**
|
|
17
|
-
* Helper type for {@linkcode IsEqual}.
|
|
18
|
-
*/
|
|
19
|
-
type IsStrictlyEqual<A1, A2> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1 ? true : false ? true : false;
|
|
20
|
-
/**
|
|
21
|
-
* Helper type for {@linkcode IsEqual}.
|
|
22
|
-
*/
|
|
23
|
-
type Unite<T> = T extends Record<string, unknown> ? {
|
|
24
|
-
[K in keyof T]: T[K];
|
|
25
|
-
} : T;
|
|
26
|
-
export {};
|
|
15
|
+
export type IsEqual<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? true : false;
|
package/dist/types/IsEqual.js
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
* type Result = IsEqual<{foo: string}, {foo: string}> // `typeof Result` is `true`
|
|
10
10
|
* ```
|
|
11
11
|
*
|
|
12
|
-
* @typeParam
|
|
13
|
-
* @typeParam
|
|
12
|
+
* @typeParam T First type to compare
|
|
13
|
+
* @typeParam U Second type to compare
|
|
14
14
|
*/ export { };
|
|
15
15
|
|
|
16
16
|
//# sourceMappingURL=IsEqual.js.map
|
|
@@ -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
|
|
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 T First type to compare\n * @typeParam U Second type to compare\n */\nexport type IsEqual<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2\n ? true\n : false;\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;CAaC,GACD,WAEU"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps all keys of type `T` to a new object type. Useful for converting interfaces to types or showing better hints from the language server.
|
|
3
|
+
*
|
|
4
|
+
* @typeParam T Base for the new type.
|
|
5
|
+
*/
|
|
6
|
+
export type Simplify<T> = {
|
|
7
|
+
[KeyType in keyof T]: T[KeyType];
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/types/Simplify.ts"],"sourcesContent":["/**\n * Maps all keys of type `T` to a new object type. Useful for converting interfaces to types or showing better hints from the language server.\n *\n * @typeParam T Base for the new type.\n */\nexport type Simplify<T> = {[KeyType in keyof T]: T[KeyType]};\n"],"names":[],"mappings":"AAAA;;;;CAIC,GACD,WAA6D"}
|
|
@@ -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
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/types/Writable.ts"],"sourcesContent":["/**\n * Create a new type that removes `readonly` from object types's keys. Inverse of {@linkcode Readonly<T>}.\n */\nexport type Writable<T> = {\n -readonly [K in keyof T]: T[K];\n};\n"],"names":[],"mappings":"AAAA;;CAEC,GACD,WAEE"}
|
package/dist/types.d.ts
CHANGED
|
@@ -11,5 +11,7 @@ export * from './types/Parameters.js';
|
|
|
11
11
|
export * from './types/Primitive.js';
|
|
12
12
|
export * from './types/RequiredKeys.js';
|
|
13
13
|
export * from './types/ReturnType.js';
|
|
14
|
+
export * from './types/Simplify.js';
|
|
14
15
|
export * from './types/TupleToUnion.js';
|
|
15
16
|
export * from './types/UnionToIntersection.js';
|
|
17
|
+
export * from './types/Writable.js';
|
package/dist/types.js
CHANGED
|
@@ -11,7 +11,9 @@ export * from './types/Parameters.js';
|
|
|
11
11
|
export * from './types/Primitive.js';
|
|
12
12
|
export * from './types/RequiredKeys.js';
|
|
13
13
|
export * from './types/ReturnType.js';
|
|
14
|
+
export * from './types/Simplify.js';
|
|
14
15
|
export * from './types/TupleToUnion.js';
|
|
15
16
|
export * from './types/UnionToIntersection.js';
|
|
17
|
+
export * from './types/Writable.js';
|
|
16
18
|
|
|
17
19
|
//# sourceMappingURL=types.js.map
|
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,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"}
|
|
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/Simplify.js';\nexport * from './types/TupleToUnion.js';\nexport * from './types/UnionToIntersection.js';\nexport * from './types/Writable.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,sBAAsB;AACpC,cAAc,0BAA0B;AACxC,cAAc,iCAAiC;AAC/C,cAAc,sBAAsB"}
|
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;;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,
|
|
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,GAAG,CAAC,CAAC;QAEtE,IAAI,CAACC,OAAO;IACd;AACF;AAEA;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GACD,OAAO,SAASC,OAAOC,SAAkB,EAAEC,YAAqB;IAC9D,+FAA+F;IAC/F,IAAI,CAACD,WAAW;QACd,MAAM,IAAIN,eAAeO;IAC3B;AACF"}
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BC,GACD,OAAO,SAASA,GAAMC,KAAc,EAAEC,SAAkB
|
|
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;IACtD,OAAOA;AACT"}
|
|
@@ -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;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,SAASA,cAAiBC,KAAQ
|
|
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;IACvC,OAAOA,UAAUC,aAAaD,UAAU;AAC1C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/tuple.ts"],"sourcesContent":["import {type Primitive} from '../types.js';\n\n// eslint-disable-next-line @typescript-eslint/ban-types -- this is intended\nexport function tuple<T extends Array<Primitive | {}>>(...values: T) {\n return values;\n}\n"],"names":["tuple","values"],"mappings":"AAEA,4EAA4E;AAC5E,OAAO,SAASA,MAAuC,GAAGC,MAAS;IACjE,OAAOA;AACT"}
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
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,oBAAoB;AAClC,cAAc,gBAAgB;AAC9B,cAAc,2BAA2B"}
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["export * from './utils/assert.js';\nexport * from './utils/is.js';\nexport * from './utils/isNonNullable.js';\nexport * from './utils/tuple.js';\n"],"names":[],"mappings":"AAAA,cAAc,oBAAoB;AAClC,cAAc,gBAAgB;AAC9B,cAAc,2BAA2B;AACzC,cAAc,mBAAmB"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jakubmazanec/ts-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0-a500263",
|
|
4
4
|
"description": "Collection of TypeScript types and utilities.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "
|
|
7
|
+
"url": "https://github.com/jakubmazanec/js-tools",
|
|
8
8
|
"directory": "packages/ts-utils"
|
|
9
9
|
},
|
|
10
10
|
"license": "LGPL-3.0-only",
|
package/src/types/IsEqual.ts
CHANGED
|
@@ -9,21 +9,9 @@
|
|
|
9
9
|
* type Result = IsEqual<{foo: string}, {foo: string}> // `typeof Result` is `true`
|
|
10
10
|
* ```
|
|
11
11
|
*
|
|
12
|
-
* @typeParam
|
|
13
|
-
* @typeParam
|
|
12
|
+
* @typeParam T First type to compare
|
|
13
|
+
* @typeParam U Second type to compare
|
|
14
14
|
*/
|
|
15
|
-
export type IsEqual<
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Helper type for {@linkcode IsEqual}.
|
|
19
|
-
*/
|
|
20
|
-
type IsStrictlyEqual<A1, A2> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1
|
|
21
|
-
? true
|
|
22
|
-
: false
|
|
15
|
+
export type IsEqual<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2
|
|
23
16
|
? true
|
|
24
17
|
: false;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Helper type for {@linkcode IsEqual}.
|
|
28
|
-
*/
|
|
29
|
-
type Unite<T> = T extends Record<string, unknown> ? {[K in keyof T]: T[K]} : T;
|
package/src/types.ts
CHANGED
|
@@ -11,5 +11,7 @@ export * from './types/Parameters.js';
|
|
|
11
11
|
export * from './types/Primitive.js';
|
|
12
12
|
export * from './types/RequiredKeys.js';
|
|
13
13
|
export * from './types/ReturnType.js';
|
|
14
|
+
export * from './types/Simplify.js';
|
|
14
15
|
export * from './types/TupleToUnion.js';
|
|
15
16
|
export * from './types/UnionToIntersection.js';
|
|
17
|
+
export * from './types/Writable.js';
|
package/src/utils.ts
CHANGED