@jakubmazanec/ts-utils 3.0.0-unstable.d4f095a → 3.0.0-unstable.d770f2b

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.
Files changed (145) hide show
  1. package/build/main.js +4 -0
  2. package/build/main.js.map +7 -0
  3. package/build/types/AtLeastOneRequired.js +2 -0
  4. package/build/types/AtLeastOneRequired.js.map +7 -0
  5. package/{dist → build}/types/DeepPartial.d.ts +2 -2
  6. package/build/types/DeepPartial.js +2 -0
  7. package/build/types/DeepPartial.js.map +7 -0
  8. package/{dist → build}/types/DeepReadonly.d.ts +1 -1
  9. package/build/types/DeepReadonly.js +2 -0
  10. package/build/types/DeepReadonly.js.map +7 -0
  11. package/build/types/If.js +2 -0
  12. package/build/types/If.js.map +7 -0
  13. package/build/types/IsEqual.js +2 -0
  14. package/build/types/IsEqual.js.map +7 -0
  15. package/{dist → build}/types/LiteralUnion.d.ts +1 -1
  16. package/build/types/LiteralUnion.js +2 -0
  17. package/build/types/LiteralUnion.js.map +7 -0
  18. package/build/types/NonArray.js +2 -0
  19. package/build/types/NonArray.js.map +7 -0
  20. package/build/types/NonArrayLike.js +2 -0
  21. package/build/types/NonArrayLike.js.map +7 -0
  22. package/build/types/OptionalKeys.js +2 -0
  23. package/build/types/OptionalKeys.js.map +7 -0
  24. package/build/types/Parameters.js +2 -0
  25. package/build/types/Parameters.js.map +7 -0
  26. package/build/types/Primitive.js +2 -0
  27. package/build/types/Primitive.js.map +7 -0
  28. package/build/types/RequiredKeys.js +2 -0
  29. package/build/types/RequiredKeys.js.map +7 -0
  30. package/{dist → build}/types/ReturnType.d.ts +1 -1
  31. package/build/types/ReturnType.js +2 -0
  32. package/build/types/ReturnType.js.map +7 -0
  33. package/build/types/Simplify.js +2 -0
  34. package/build/types/Simplify.js.map +7 -0
  35. package/build/types/TupleToUnion.js +2 -0
  36. package/build/types/TupleToUnion.js.map +7 -0
  37. package/build/types/UnionToIntersection.js +2 -0
  38. package/build/types/UnionToIntersection.js.map +7 -0
  39. package/build/types/Writable.js +2 -0
  40. package/build/types/Writable.js.map +7 -0
  41. package/build/types.js +19 -0
  42. package/build/types.js.map +7 -0
  43. package/build/utils/assert.js +16 -0
  44. package/build/utils/assert.js.map +7 -0
  45. package/build/utils/is.js +5 -0
  46. package/build/utils/is.js.map +7 -0
  47. package/build/utils/isNonNullable.js +5 -0
  48. package/build/utils/isNonNullable.js.map +7 -0
  49. package/build/utils/tuple.js +5 -0
  50. package/build/utils/tuple.js.map +7 -0
  51. package/build/utils.js +6 -0
  52. package/build/utils.js.map +7 -0
  53. package/package.json +22 -11
  54. package/{src → source}/types/DeepPartial.ts +17 -17
  55. package/{src → source}/types/DeepReadonly.ts +6 -9
  56. package/{src → source}/types/IsEqual.ts +2 -3
  57. package/{src → source}/types/LiteralUnion.ts +1 -1
  58. package/{src → source}/types/ReturnType.ts +5 -1
  59. package/{src → source}/types/UnionToIntersection.ts +4 -7
  60. package/dist/main.js +0 -4
  61. package/dist/main.js.map +0 -1
  62. package/dist/types/AtLeastOneRequired.js +0 -35
  63. package/dist/types/AtLeastOneRequired.js.map +0 -1
  64. package/dist/types/DeepPartial.js +0 -33
  65. package/dist/types/DeepPartial.js.map +0 -1
  66. package/dist/types/DeepReadonly.js +0 -19
  67. package/dist/types/DeepReadonly.js.map +0 -1
  68. package/dist/types/If.js +0 -16
  69. package/dist/types/If.js.map +0 -1
  70. package/dist/types/IsEqual.js +0 -16
  71. package/dist/types/IsEqual.js.map +0 -1
  72. package/dist/types/LiteralUnion.js +0 -21
  73. package/dist/types/LiteralUnion.js.map +0 -1
  74. package/dist/types/NonArray.js +0 -3
  75. package/dist/types/NonArray.js.map +0 -1
  76. package/dist/types/NonArrayLike.js +0 -3
  77. package/dist/types/NonArrayLike.js.map +0 -1
  78. package/dist/types/OptionalKeys.js +0 -11
  79. package/dist/types/OptionalKeys.js.map +0 -1
  80. package/dist/types/Parameters.js +0 -18
  81. package/dist/types/Parameters.js.map +0 -1
  82. package/dist/types/Primitive.js +0 -5
  83. package/dist/types/Primitive.js.map +0 -1
  84. package/dist/types/RequiredKeys.js +0 -11
  85. package/dist/types/RequiredKeys.js.map +0 -1
  86. package/dist/types/ReturnType.js +0 -19
  87. package/dist/types/ReturnType.js.map +0 -1
  88. package/dist/types/Simplify.js +0 -7
  89. package/dist/types/Simplify.js.map +0 -1
  90. package/dist/types/TupleToUnion.js +0 -11
  91. package/dist/types/TupleToUnion.js.map +0 -1
  92. package/dist/types/UnionToIntersection.js +0 -11
  93. package/dist/types/UnionToIntersection.js.map +0 -1
  94. package/dist/types/Writable.js +0 -5
  95. package/dist/types/Writable.js.map +0 -1
  96. package/dist/types.js +0 -19
  97. package/dist/types.js.map +0 -1
  98. package/dist/utils/assert.js +0 -41
  99. package/dist/utils/assert.js.map +0 -1
  100. package/dist/utils/is.js +0 -31
  101. package/dist/utils/is.js.map +0 -1
  102. package/dist/utils/isNonNullable.js +0 -21
  103. package/dist/utils/isNonNullable.js.map +0 -1
  104. package/dist/utils/tuple.js +0 -6
  105. package/dist/utils/tuple.js.map +0 -1
  106. package/dist/utils.js +0 -6
  107. package/dist/utils.js.map +0 -1
  108. /package/{dist → build}/main.d.ts +0 -0
  109. /package/{dist → build}/types/AtLeastOneRequired.d.ts +0 -0
  110. /package/{dist → build}/types/If.d.ts +0 -0
  111. /package/{dist → build}/types/IsEqual.d.ts +0 -0
  112. /package/{dist → build}/types/NonArray.d.ts +0 -0
  113. /package/{dist → build}/types/NonArrayLike.d.ts +0 -0
  114. /package/{dist → build}/types/OptionalKeys.d.ts +0 -0
  115. /package/{dist → build}/types/Parameters.d.ts +0 -0
  116. /package/{dist → build}/types/Primitive.d.ts +0 -0
  117. /package/{dist → build}/types/RequiredKeys.d.ts +0 -0
  118. /package/{dist → build}/types/Simplify.d.ts +0 -0
  119. /package/{dist → build}/types/TupleToUnion.d.ts +0 -0
  120. /package/{dist → build}/types/UnionToIntersection.d.ts +0 -0
  121. /package/{dist → build}/types/Writable.d.ts +0 -0
  122. /package/{dist → build}/types.d.ts +0 -0
  123. /package/{dist → build}/utils/assert.d.ts +0 -0
  124. /package/{dist → build}/utils/is.d.ts +0 -0
  125. /package/{dist → build}/utils/isNonNullable.d.ts +0 -0
  126. /package/{dist → build}/utils/tuple.d.ts +0 -0
  127. /package/{dist → build}/utils.d.ts +0 -0
  128. /package/{src → source}/main.ts +0 -0
  129. /package/{src → source}/types/AtLeastOneRequired.ts +0 -0
  130. /package/{src → source}/types/If.ts +0 -0
  131. /package/{src → source}/types/NonArray.ts +0 -0
  132. /package/{src → source}/types/NonArrayLike.ts +0 -0
  133. /package/{src → source}/types/OptionalKeys.ts +0 -0
  134. /package/{src → source}/types/Parameters.ts +0 -0
  135. /package/{src → source}/types/Primitive.ts +0 -0
  136. /package/{src → source}/types/RequiredKeys.ts +0 -0
  137. /package/{src → source}/types/Simplify.ts +0 -0
  138. /package/{src → source}/types/TupleToUnion.ts +0 -0
  139. /package/{src → source}/types/Writable.ts +0 -0
  140. /package/{src → source}/types.ts +0 -0
  141. /package/{src → source}/utils/assert.ts +0 -0
  142. /package/{src → source}/utils/is.ts +0 -0
  143. /package/{src → source}/utils/isNonNullable.ts +0 -0
  144. /package/{src → source}/utils/tuple.ts +0 -0
  145. /package/{src → source}/utils.ts +0 -0
package/build/main.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ export * from "./types.js";
3
+ export * from "./utils.js";
4
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../source/main.ts"],
4
+ "sourcesContent": ["export * from './types.js';\nexport * from './utils.js';\n"],
5
+ "mappings": ";AAAA,cAAc;AACd,cAAc;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=AtLeastOneRequired.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -1,4 +1,4 @@
1
- import type { Primitive } from './Primitive.js';
1
+ import { type Primitive } from './Primitive.js';
2
2
  /**
3
3
  * 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.
4
4
  *
@@ -30,7 +30,7 @@ import type { Primitive } from './Primitive.js';
30
30
  *
31
31
  * @typeParam T Base for the new type
32
32
  */
33
- export type DeepPartial<T> = T extends Date | Primitive | RegExp ? T : T extends Map<infer KeyType, infer ValueType> ? DeepPartialMap<KeyType, ValueType> : T extends Set<infer ItemType> ? DeepPartialSet<ItemType> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? DeepPartialReadonlyMap<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? DeepPartialReadonlySet<ItemType> : T extends (...args: any[]) => unknown ? T | undefined : T extends object ? T extends Array<infer I> ? I[] extends T ? Array<DeepPartial<I | undefined>> : DeepPartialObject<T> : DeepPartialObject<T> : unknown;
33
+ export type DeepPartial<T> = T extends Date | Primitive | RegExp ? T : T extends Map<infer KeyType, infer ValueType> ? DeepPartialMap<KeyType, ValueType> : T extends Set<infer ItemType> ? DeepPartialSet<ItemType> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? DeepPartialReadonlyMap<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? DeepPartialReadonlySet<ItemType> : T extends (...args: any[]) => unknown ? T | undefined : T extends object ? T extends (Array<infer I>) ? I[] extends (T) ? Array<DeepPartial<I | undefined>> : DeepPartialObject<T> : DeepPartialObject<T> : unknown;
34
34
  /**
35
35
  * Helper type for {@link DeepPartial}.
36
36
  */
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=DeepPartial.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -1,4 +1,4 @@
1
- import type { Primitive } from './Primitive.js';
1
+ import { type Primitive } from './Primitive.js';
2
2
  /**
3
3
  * Same as built-in `Readonly`, but works recursively:
4
4
  *
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=DeepReadonly.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=If.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=IsEqual.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -1,4 +1,4 @@
1
- import type { Primitive } from './Primitive.js';
1
+ import { type Primitive } from './Primitive.js';
2
2
  /**
3
3
  * Creates union type by combining primitve types and literal types while allowing auto-completion in IDEs.
4
4
  * This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729).
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=LiteralUnion.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=NonArray.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=NonArrayLike.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=OptionalKeys.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=Parameters.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=Primitive.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=RequiredKeys.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -15,4 +15,4 @@
15
15
  *
16
16
  * @typeParam T Base for the new type
17
17
  */
18
- export type ReturnType<T extends '' | false | ((...args: any[]) => any) | null | undefined> = T extends (...args: any[]) => infer R ? (R extends PromiseLike<infer J> ? J : R) : never;
18
+ export type ReturnType<T extends '' | false | ((...args: any[]) => any) | null | undefined> = T extends (...args: any[]) => infer R ? R extends PromiseLike<infer J> ? J : R : never;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=ReturnType.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=Simplify.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=TupleToUnion.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=UnionToIntersection.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=Writable.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
package/build/types.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ export * from "./types/AtLeastOneRequired.js";
3
+ export * from "./types/DeepPartial.js";
4
+ export * from "./types/DeepReadonly.js";
5
+ export * from "./types/If.js";
6
+ export * from "./types/IsEqual.js";
7
+ export * from "./types/LiteralUnion.js";
8
+ export * from "./types/NonArray.js";
9
+ export * from "./types/NonArrayLike.js";
10
+ export * from "./types/OptionalKeys.js";
11
+ export * from "./types/Parameters.js";
12
+ export * from "./types/Primitive.js";
13
+ export * from "./types/RequiredKeys.js";
14
+ export * from "./types/ReturnType.js";
15
+ export * from "./types/Simplify.js";
16
+ export * from "./types/TupleToUnion.js";
17
+ export * from "./types/UnionToIntersection.js";
18
+ export * from "./types/Writable.js";
19
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../source/types.ts"],
4
+ "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"],
5
+ "mappings": ";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
6
+ "names": []
7
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ export class AssertionError extends Error {
3
+ /**
4
+ * @param message Message added to the default error message
5
+ */
6
+ constructor(message) {
7
+ super(`Wrong assertion encountered${message ? `: "${message}"` : ""}!`);
8
+ this.name = "AssertionError";
9
+ }
10
+ }
11
+ export function assert(condition, errorMessage) {
12
+ if (!condition) {
13
+ throw new AssertionError(errorMessage);
14
+ }
15
+ }
16
+ //# sourceMappingURL=assert.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../source/utils/assert.ts"],
4
+ "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 {@link 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"],
5
+ "mappings": ";AAGO,aAAM,uBAAuB,MAAM;AAAA;AAAA;AAAA;AAAA,EAIxC,YAAY,SAAkB;AAC5B,UAAM,8BAA8B,UAAU,MAAM,OAAO,MAAM,EAAE,GAAG;AAEtE,SAAK,OAAO;AAAA,EACd;AACF;AA0BO,gBAAS,OAAO,WAAoB,cAA0C;AAEnF,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,eAAe,YAAY;AAAA,EACvC;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ export function is(value, isMatched) {
3
+ return isMatched;
4
+ }
5
+ //# sourceMappingURL=is.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../source/utils/is.ts"],
4
+ "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"],
5
+ "mappings": ";AA2BO,gBAAS,GAAM,OAAgB,WAAgC;AACpE,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ export function isNonNullable(value) {
3
+ return value !== void 0 && value !== null;
4
+ }
5
+ //# sourceMappingURL=isNonNullable.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../source/utils/isNonNullable.ts"],
4
+ "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"],
5
+ "mappings": ";AAiBO,gBAAS,cAAiB,OAAmC;AAClE,SAAO,UAAU,UAAa,UAAU;AAC1C;",
6
+ "names": []
7
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ export function tuple(...values) {
3
+ return values;
4
+ }
5
+ //# sourceMappingURL=tuple.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../source/utils/tuple.ts"],
4
+ "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"],
5
+ "mappings": ";AAGO,gBAAS,SAA0C,QAAW;AACnE,SAAO;AACT;",
6
+ "names": []
7
+ }
package/build/utils.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ export * from "./utils/assert.js";
3
+ export * from "./utils/is.js";
4
+ export * from "./utils/isNonNullable.js";
5
+ export * from "./utils/tuple.js";
6
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../source/utils.ts"],
4
+ "sourcesContent": ["export * from './utils/assert.js';\nexport * from './utils/is.js';\nexport * from './utils/isNonNullable.js';\nexport * from './utils/tuple.js';\n"],
5
+ "mappings": ";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jakubmazanec/ts-utils",
3
- "version": "3.0.0-unstable.d4f095a",
3
+ "version": "3.0.0-unstable.d770f2b",
4
4
  "description": "Collection of TypeScript types and utilities.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,23 +11,34 @@
11
11
  "author": "Jakub Mazanec <jakub@mazanec.dev>",
12
12
  "sideEffects": false,
13
13
  "type": "module",
14
- "exports": "./dist/main.js",
14
+ "exports": "./build/main.js",
15
15
  "files": [
16
- "dist",
17
- "src"
16
+ "build",
17
+ "source"
18
18
  ],
19
19
  "scripts": {
20
- "build": "swc src -d dist && tsc",
21
- "clean": "del-cli coverage dist *.tsbuildinfo",
22
- "document": "typedoc --options typedoc.config.cjs",
23
- "format": "prettier . --write --ignore-unknown --ignore-path ../../.prettierignore",
20
+ "build": "del-cli build tsconfig.tsbuildinfo && esbuild \"source/**/*\" --platform=node --target=node20.8 --outdir=build --sourcemap && tsc",
21
+ "clean": "del-cli coverage build *.tsbuildinfo",
22
+ "develop": "concurrently \"esbuild \"source/**/*\" --platform=node --target=node20.8 --outdir=build --sourcemap --watch\" \"tsc --watch\"",
23
+ "document": "del-cli docs && typedoc --options typedoc.config.cjs",
24
+ "format": "prettier . --write --ignore-unknown",
24
25
  "lint": "eslint .",
25
- "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests",
26
+ "test": "del-cli coverage && vitest run --coverage --passWithNoTests",
26
27
  "typecheck": "tsc --project tsconfig.typecheck.json"
27
28
  },
28
29
  "devDependencies": {
29
- "@jest/globals": "^29.5.0",
30
- "@types/node": "^20.8.5"
30
+ "@types/node": "^20.8.5",
31
+ "@vitest/coverage-v8": "^1.2.0",
32
+ "concurrently": "^8.0.0",
33
+ "del-cli": "^5.0.0",
34
+ "esbuild": "^0.19.11",
35
+ "eslint": "^8.56.0",
36
+ "prettier": "^3.0.0",
37
+ "prettier-plugin-packagejson": "^2.4.3",
38
+ "typedoc": "^0.25.2",
39
+ "typedoc-plugin-markdown": "^3.15.1",
40
+ "typescript": "^5.3.3",
41
+ "vitest": "^1.2.0"
31
42
  },
32
43
  "packageManager": "npm@10.1.0",
33
44
  "engines": {
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-interface -- needed */
2
2
 
3
- import type {Primitive} from './Primitive.js';
3
+ import {type Primitive} from './Primitive.js';
4
4
 
5
5
  /**
6
6
  * 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.
@@ -33,22 +33,22 @@ import type {Primitive} from './Primitive.js';
33
33
  *
34
34
  * @typeParam T Base for the new type
35
35
  */
36
- export type DeepPartial<T> = T extends Date | Primitive | RegExp
37
- ? T
38
- : T extends Map<infer KeyType, infer ValueType>
39
- ? DeepPartialMap<KeyType, ValueType>
40
- : T extends Set<infer ItemType>
41
- ? DeepPartialSet<ItemType>
42
- : T extends ReadonlyMap<infer KeyType, infer ValueType>
43
- ? DeepPartialReadonlyMap<KeyType, ValueType>
44
- : T extends ReadonlySet<infer ItemType>
45
- ? DeepPartialReadonlySet<ItemType>
46
- : T extends (...args: any[]) => unknown
47
- ? T | undefined
48
- : T extends object
49
- ? T extends Array<infer I> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
50
- ? I[] extends T // Test for arrays (non-tuples) specifically
51
- ? Array<DeepPartial<I | undefined>> // Recreate relevant array type to prevent eager evaluation of circular reference
36
+ export type DeepPartial<T> =
37
+ T extends Date | Primitive | RegExp ? T
38
+ : T extends Map<infer KeyType, infer ValueType> ? DeepPartialMap<KeyType, ValueType>
39
+ : T extends Set<infer ItemType> ? DeepPartialSet<ItemType>
40
+ : T extends ReadonlyMap<infer KeyType, infer ValueType> ?
41
+ DeepPartialReadonlyMap<KeyType, ValueType>
42
+ : T extends ReadonlySet<infer ItemType> ? DeepPartialReadonlySet<ItemType>
43
+ : T extends (...args: any[]) => unknown ? T | undefined
44
+ : T extends object ?
45
+ T extends (
46
+ Array<infer I> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
47
+ ) ?
48
+ I[] extends (
49
+ T // Test for arrays (non-tuples) specifically
50
+ ) ?
51
+ Array<DeepPartial<I | undefined>> // Recreate relevant array type to prevent eager evaluation of circular reference
52
52
  : DeepPartialObject<T> // Tuples behave properly
53
53
  : DeepPartialObject<T>
54
54
  : unknown;
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any -- needed */
2
2
 
3
- import type {Primitive} from './Primitive.js';
3
+ import {type Primitive} from './Primitive.js';
4
4
 
5
5
  /**
6
6
  * Same as built-in `Readonly`, but works recursively:
@@ -19,14 +19,11 @@ import type {Primitive} from './Primitive.js';
19
19
  *
20
20
  * @typeParam T Base for the new type
21
21
  */
22
- export type DeepReadonly<T> = T extends Primitive | ((...args: any[]) => unknown)
23
- ? T
24
- : T extends ReadonlyMap<infer K, infer V>
25
- ? DeepReadonlyMap<K, V>
26
- : T extends ReadonlySet<infer I>
27
- ? DeepReadonlySet<I>
28
- : T extends object
29
- ? DeepReadonlyObject<T>
22
+ export type DeepReadonly<T> =
23
+ T extends Primitive | ((...args: any[]) => unknown) ? T
24
+ : T extends ReadonlyMap<infer K, infer V> ? DeepReadonlyMap<K, V>
25
+ : T extends ReadonlySet<infer I> ? DeepReadonlySet<I>
26
+ : T extends object ? DeepReadonlyObject<T>
30
27
  : unknown;
31
28
 
32
29
  /**
@@ -12,6 +12,5 @@
12
12
  * @typeParam T First type to compare
13
13
  * @typeParam U Second type to compare
14
14
  */
15
- export type IsEqual<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2
16
- ? true
17
- : false;
15
+ export type IsEqual<T, U> =
16
+ (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? true : false;
@@ -1,4 +1,4 @@
1
- import type {Primitive} from './Primitive.js';
1
+ import {type Primitive} from './Primitive.js';
2
2
 
3
3
  /**
4
4
  * Creates union type by combining primitve types and literal types while allowing auto-completion in IDEs.
@@ -18,4 +18,8 @@
18
18
  * @typeParam T Base for the new type
19
19
  */
20
20
  export type ReturnType<T extends '' | false | ((...args: any[]) => any) | null | undefined> =
21
- T extends (...args: any[]) => infer R ? (R extends PromiseLike<infer J> ? J : R) : never;
21
+ T extends (...args: any[]) => infer R ?
22
+ R extends PromiseLike<infer J> ?
23
+ J
24
+ : R
25
+ : never;
@@ -7,15 +7,12 @@
7
7
  *
8
8
  * @typeParam U Base for the new type
9
9
  */
10
- export type UnionToIntersection<U> = boolean extends U
11
- ? UnionToIntersectionHelper<Exclude<U, boolean>> & boolean
10
+ export type UnionToIntersection<U> =
11
+ boolean extends U ? UnionToIntersectionHelper<Exclude<U, boolean>> & boolean
12
12
  : UnionToIntersectionHelper<U>;
13
13
 
14
14
  /**
15
15
  * Helper type for {@link UnionToIntersection}.
16
16
  */
17
- type UnionToIntersectionHelper<U> = (U extends unknown ? (k: U) => void : never) extends (
18
- k: infer I,
19
- ) => void
20
- ? I
21
- : never;
17
+ type UnionToIntersectionHelper<U> =
18
+ (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
package/dist/main.js DELETED
@@ -1,4 +0,0 @@
1
- export * from './types.js';
2
- export * from './utils.js';
3
-
4
- //# sourceMappingURL=main.js.map
package/dist/main.js.map DELETED
@@ -1 +0,0 @@
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"}