@stryke/types 0.0.1

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 (225) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +295 -0
  3. package/dist/convert/buffer-to-string.cjs +8 -0
  4. package/dist/convert/buffer-to-string.d.ts +1 -0
  5. package/dist/convert/buffer-to-string.mjs +1 -0
  6. package/dist/convert/index.cjs +71 -0
  7. package/dist/convert/index.d.ts +6 -0
  8. package/dist/convert/index.mjs +1 -0
  9. package/dist/convert/string-to-uint8-array.cjs +8 -0
  10. package/dist/convert/string-to-uint8-array.d.ts +7 -0
  11. package/dist/convert/string-to-uint8-array.mjs +1 -0
  12. package/dist/convert/to-array.cjs +9 -0
  13. package/dist/convert/to-array.d.ts +8 -0
  14. package/dist/convert/to-array.mjs +1 -0
  15. package/dist/convert/to-string-key.cjs +9 -0
  16. package/dist/convert/to-string-key.d.ts +7 -0
  17. package/dist/convert/to-string-key.mjs +1 -0
  18. package/dist/convert/uint8-array-to-string.cjs +8 -0
  19. package/dist/convert/uint8-array-to-string.d.ts +13 -0
  20. package/dist/convert/uint8-array-to-string.mjs +1 -0
  21. package/dist/convert/utf8-array-to-string.cjs +8 -0
  22. package/dist/convert/utf8-array-to-string.d.ts +13 -0
  23. package/dist/convert/utf8-array-to-string.mjs +1 -0
  24. package/dist/helpers/index.cjs +16 -0
  25. package/dist/helpers/index.d.ts +1 -0
  26. package/dist/helpers/index.mjs +1 -0
  27. package/dist/helpers/parse-type-definition.cjs +33 -0
  28. package/dist/helpers/parse-type-definition.d.ts +8 -0
  29. package/dist/helpers/parse-type-definition.mjs +1 -0
  30. package/dist/index.cjs +49 -0
  31. package/dist/index.d.ts +12 -0
  32. package/dist/index.mjs +1 -0
  33. package/dist/type-checks/get-object-tag.cjs +8 -0
  34. package/dist/type-checks/get-object-tag.d.ts +7 -0
  35. package/dist/type-checks/get-object-tag.mjs +1 -0
  36. package/dist/type-checks/index.cjs +456 -0
  37. package/dist/type-checks/index.d.ts +41 -0
  38. package/dist/type-checks/index.mjs +1 -0
  39. package/dist/type-checks/is-array-like.cjs +11 -0
  40. package/dist/type-checks/is-array-like.d.ts +7 -0
  41. package/dist/type-checks/is-array-like.mjs +1 -0
  42. package/dist/type-checks/is-async-iterable.cjs +10 -0
  43. package/dist/type-checks/is-async-iterable.d.ts +7 -0
  44. package/dist/type-checks/is-async-iterable.mjs +1 -0
  45. package/dist/type-checks/is-bigint.cjs +9 -0
  46. package/dist/type-checks/is-bigint.d.ts +16 -0
  47. package/dist/type-checks/is-bigint.mjs +1 -0
  48. package/dist/type-checks/is-boolean.cjs +14 -0
  49. package/dist/type-checks/is-boolean.d.ts +7 -0
  50. package/dist/type-checks/is-boolean.mjs +1 -0
  51. package/dist/type-checks/is-buffer.cjs +10 -0
  52. package/dist/type-checks/is-buffer.d.ts +5 -0
  53. package/dist/type-checks/is-buffer.mjs +1 -0
  54. package/dist/type-checks/is-collection.cjs +11 -0
  55. package/dist/type-checks/is-collection.d.ts +8 -0
  56. package/dist/type-checks/is-collection.mjs +1 -0
  57. package/dist/type-checks/is-date.cjs +10 -0
  58. package/dist/type-checks/is-date.d.ts +16 -0
  59. package/dist/type-checks/is-date.mjs +1 -0
  60. package/dist/type-checks/is-deep-key.cjs +26 -0
  61. package/dist/type-checks/is-deep-key.d.ts +35 -0
  62. package/dist/type-checks/is-deep-key.mjs +1 -0
  63. package/dist/type-checks/is-empty-object.cjs +23 -0
  64. package/dist/type-checks/is-empty-object.d.ts +14 -0
  65. package/dist/type-checks/is-empty-object.mjs +1 -0
  66. package/dist/type-checks/is-empty-string.cjs +16 -0
  67. package/dist/type-checks/is-empty-string.d.ts +7 -0
  68. package/dist/type-checks/is-empty-string.mjs +1 -0
  69. package/dist/type-checks/is-empty.cjs +35 -0
  70. package/dist/type-checks/is-empty.d.ts +8 -0
  71. package/dist/type-checks/is-empty.mjs +1 -0
  72. package/dist/type-checks/is-equal.cjs +18 -0
  73. package/dist/type-checks/is-equal.d.ts +1 -0
  74. package/dist/type-checks/is-equal.mjs +1 -0
  75. package/dist/type-checks/is-error.cjs +15 -0
  76. package/dist/type-checks/is-error.d.ts +17 -0
  77. package/dist/type-checks/is-error.mjs +1 -0
  78. package/dist/type-checks/is-file-result.cjs +11 -0
  79. package/dist/type-checks/is-file-result.d.ts +8 -0
  80. package/dist/type-checks/is-file-result.mjs +1 -0
  81. package/dist/type-checks/is-float.cjs +9 -0
  82. package/dist/type-checks/is-float.d.ts +8 -0
  83. package/dist/type-checks/is-float.mjs +1 -0
  84. package/dist/type-checks/is-function.cjs +23 -0
  85. package/dist/type-checks/is-function.d.ts +10 -0
  86. package/dist/type-checks/is-function.mjs +1 -0
  87. package/dist/type-checks/is-integer.cjs +10 -0
  88. package/dist/type-checks/is-integer.d.ts +8 -0
  89. package/dist/type-checks/is-integer.mjs +1 -0
  90. package/dist/type-checks/is-mergeable-object.cjs +14 -0
  91. package/dist/type-checks/is-mergeable-object.d.ts +1 -0
  92. package/dist/type-checks/is-mergeable-object.mjs +1 -0
  93. package/dist/type-checks/is-non-null-object.cjs +10 -0
  94. package/dist/type-checks/is-non-null-object.d.ts +7 -0
  95. package/dist/type-checks/is-non-null-object.mjs +1 -0
  96. package/dist/type-checks/is-not-empty.cjs +17 -0
  97. package/dist/type-checks/is-not-empty.d.ts +7 -0
  98. package/dist/type-checks/is-not-empty.mjs +1 -0
  99. package/dist/type-checks/is-null.cjs +14 -0
  100. package/dist/type-checks/is-null.d.ts +1 -0
  101. package/dist/type-checks/is-null.mjs +1 -0
  102. package/dist/type-checks/is-number.cjs +19 -0
  103. package/dist/type-checks/is-number.d.ts +15 -0
  104. package/dist/type-checks/is-number.mjs +1 -0
  105. package/dist/type-checks/is-object-index.cjs +17 -0
  106. package/dist/type-checks/is-object-index.d.ts +7 -0
  107. package/dist/type-checks/is-object-index.mjs +1 -0
  108. package/dist/type-checks/is-object.cjs +30 -0
  109. package/dist/type-checks/is-object.d.ts +30 -0
  110. package/dist/type-checks/is-object.mjs +1 -0
  111. package/dist/type-checks/is-plain-object.cjs +17 -0
  112. package/dist/type-checks/is-plain-object.d.ts +50 -0
  113. package/dist/type-checks/is-plain-object.mjs +1 -0
  114. package/dist/type-checks/is-primitive.cjs +14 -0
  115. package/dist/type-checks/is-primitive.d.ts +1 -0
  116. package/dist/type-checks/is-primitive.mjs +1 -0
  117. package/dist/type-checks/is-promise.cjs +12 -0
  118. package/dist/type-checks/is-promise.d.ts +17 -0
  119. package/dist/type-checks/is-promise.mjs +1 -0
  120. package/dist/type-checks/is-react-element.cjs +8 -0
  121. package/dist/type-checks/is-react-element.d.ts +1 -0
  122. package/dist/type-checks/is-react-element.mjs +1 -0
  123. package/dist/type-checks/is-ref.cjs +14 -0
  124. package/dist/type-checks/is-ref.d.ts +8 -0
  125. package/dist/type-checks/is-ref.mjs +1 -0
  126. package/dist/type-checks/is-regexp.cjs +10 -0
  127. package/dist/type-checks/is-regexp.d.ts +16 -0
  128. package/dist/type-checks/is-regexp.mjs +1 -0
  129. package/dist/type-checks/is-select-option.cjs +15 -0
  130. package/dist/type-checks/is-select-option.d.ts +8 -0
  131. package/dist/type-checks/is-select-option.mjs +1 -0
  132. package/dist/type-checks/is-set-object.cjs +15 -0
  133. package/dist/type-checks/is-set-object.d.ts +7 -0
  134. package/dist/type-checks/is-set-object.mjs +1 -0
  135. package/dist/type-checks/is-set-string.cjs +16 -0
  136. package/dist/type-checks/is-set-string.d.ts +7 -0
  137. package/dist/type-checks/is-set-string.mjs +1 -0
  138. package/dist/type-checks/is-set.cjs +15 -0
  139. package/dist/type-checks/is-set.d.ts +7 -0
  140. package/dist/type-checks/is-set.mjs +1 -0
  141. package/dist/type-checks/is-string.cjs +14 -0
  142. package/dist/type-checks/is-string.d.ts +1 -0
  143. package/dist/type-checks/is-string.mjs +1 -0
  144. package/dist/type-checks/is-symbol.cjs +14 -0
  145. package/dist/type-checks/is-symbol.d.ts +1 -0
  146. package/dist/type-checks/is-symbol.mjs +1 -0
  147. package/dist/type-checks/is-typed-array.cjs +9 -0
  148. package/dist/type-checks/is-typed-array.d.ts +1 -0
  149. package/dist/type-checks/is-typed-array.mjs +1 -0
  150. package/dist/type-checks/is-typed.cjs +16 -0
  151. package/dist/type-checks/is-typed.d.ts +8 -0
  152. package/dist/type-checks/is-typed.mjs +1 -0
  153. package/dist/type-checks/is-undefined.cjs +8 -0
  154. package/dist/type-checks/is-undefined.d.ts +1 -0
  155. package/dist/type-checks/is-undefined.mjs +1 -0
  156. package/dist/type-checks/property-exists.cjs +17 -0
  157. package/dist/type-checks/property-exists.d.ts +16 -0
  158. package/dist/type-checks/property-exists.mjs +1 -0
  159. package/dist/type-checks/type-detect.cjs +38 -0
  160. package/dist/type-checks/type-detect.d.ts +1 -0
  161. package/dist/type-checks/type-detect.mjs +1 -0
  162. package/dist/utility-types/array.cjs +9 -0
  163. package/dist/utility-types/array.d.ts +130 -0
  164. package/dist/utility-types/array.mjs +1 -0
  165. package/dist/utility-types/async.cjs +1 -0
  166. package/dist/utility-types/async.d.ts +103 -0
  167. package/dist/utility-types/async.mjs +0 -0
  168. package/dist/utility-types/base.cjs +16 -0
  169. package/dist/utility-types/base.d.ts +325 -0
  170. package/dist/utility-types/base.mjs +2 -0
  171. package/dist/utility-types/configuration.cjs +1 -0
  172. package/dist/utility-types/configuration.d.ts +59 -0
  173. package/dist/utility-types/configuration.mjs +0 -0
  174. package/dist/utility-types/file.cjs +12 -0
  175. package/dist/utility-types/file.d.ts +29 -0
  176. package/dist/utility-types/file.mjs +1 -0
  177. package/dist/utility-types/form.cjs +1 -0
  178. package/dist/utility-types/form.d.ts +35 -0
  179. package/dist/utility-types/form.mjs +0 -0
  180. package/dist/utility-types/index.cjs +214 -0
  181. package/dist/utility-types/index.d.ts +19 -0
  182. package/dist/utility-types/index.mjs +1 -0
  183. package/dist/utility-types/json.cjs +1 -0
  184. package/dist/utility-types/json.d.ts +82 -0
  185. package/dist/utility-types/json.mjs +0 -0
  186. package/dist/utility-types/logic.cjs +1 -0
  187. package/dist/utility-types/logic.d.ts +152 -0
  188. package/dist/utility-types/logic.mjs +0 -0
  189. package/dist/utility-types/messages.cjs +13 -0
  190. package/dist/utility-types/messages.d.ts +24 -0
  191. package/dist/utility-types/messages.mjs +1 -0
  192. package/dist/utility-types/navigator.cjs +1 -0
  193. package/dist/utility-types/navigator.d.ts +40 -0
  194. package/dist/utility-types/navigator.mjs +0 -0
  195. package/dist/utility-types/number.cjs +1 -0
  196. package/dist/utility-types/number.d.ts +198 -0
  197. package/dist/utility-types/number.mjs +0 -0
  198. package/dist/utility-types/object.cjs +1 -0
  199. package/dist/utility-types/object.d.ts +434 -0
  200. package/dist/utility-types/object.mjs +0 -0
  201. package/dist/utility-types/package-json.cjs +1 -0
  202. package/dist/utility-types/package-json.d.ts +504 -0
  203. package/dist/utility-types/package-json.mjs +0 -0
  204. package/dist/utility-types/package-manager.cjs +18 -0
  205. package/dist/utility-types/package-manager.d.ts +14 -0
  206. package/dist/utility-types/package-manager.mjs +1 -0
  207. package/dist/utility-types/string.cjs +1 -0
  208. package/dist/utility-types/string.d.ts +87 -0
  209. package/dist/utility-types/string.mjs +0 -0
  210. package/dist/utility-types/system.cjs +1 -0
  211. package/dist/utility-types/system.d.ts +1 -0
  212. package/dist/utility-types/system.mjs +0 -0
  213. package/dist/utility-types/tsconfig.cjs +1 -0
  214. package/dist/utility-types/tsconfig.d.ts +800 -0
  215. package/dist/utility-types/tsconfig.mjs +0 -0
  216. package/dist/utility-types/user.cjs +11 -0
  217. package/dist/utility-types/user.d.ts +30 -0
  218. package/dist/utility-types/user.mjs +1 -0
  219. package/dist/utility-types/utilities.cjs +1 -0
  220. package/dist/utility-types/utilities.d.ts +53 -0
  221. package/dist/utility-types/utilities.mjs +0 -0
  222. package/dist/utility-types/validations.cjs +1 -0
  223. package/dist/utility-types/validations.d.ts +16 -0
  224. package/dist/utility-types/validations.mjs +0 -0
  225. package/package.json +1157 -0
@@ -0,0 +1,198 @@
1
+ import type { Not } from "./logic";
2
+ export type Numeric = number | bigint;
3
+ export type Zero = 0 | 0n;
4
+ /**
5
+ * Matches the hidden `Infinity` type.
6
+ *
7
+ * Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
8
+ *
9
+ * @see NegativeInfinity
10
+ *
11
+ * @category Numeric
12
+ */
13
+ export type PositiveInfinity = 1e999;
14
+ /**
15
+ * Matches the hidden `-Infinity` type.
16
+ *
17
+ * Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
18
+ *
19
+ * @see PositiveInfinity
20
+ *
21
+ * @category Numeric
22
+ */
23
+ export type NegativeInfinity = -1e999;
24
+ /**
25
+ * A finite `number`.
26
+ * You can't pass a `bigint` as they are already guaranteed to be finite.
27
+ *
28
+ * Use-case: Validating and documenting parameters.
29
+ *
30
+ * Note: This can't detect `NaN`, please upvote [this issue](https://github.com/microsoft/TypeScript/issues/28682) if you want to have this type as a built-in in TypeScript.
31
+ *
32
+ * @example
33
+ * ```
34
+ * import type {Finite} from 'type-fest';
35
+ *
36
+ * declare function setScore<T extends number>(length: Finite<T>): void;
37
+ * ```
38
+ *
39
+ * @category Numeric
40
+ */
41
+ export type Finite<T extends number> = T extends PositiveInfinity | NegativeInfinity ? never : T;
42
+ /**
43
+ * A `number` that is an integer.
44
+ *
45
+ * Use-case: Validating and documenting parameters.
46
+ *
47
+ * @example
48
+ * ```
49
+ * type Integer = Integer<1>;
50
+ * //=> 1
51
+ *
52
+ * type IntegerWithDecimal = Integer<1.0>;
53
+ * //=> 1
54
+ *
55
+ * type NegativeInteger = Integer<-1>;
56
+ * //=> -1
57
+ *
58
+ * type Float = Integer<1.5>;
59
+ * //=> never
60
+ *
61
+ * // Supports non-decimal numbers
62
+ *
63
+ * type OctalInteger: Integer<0o10>;
64
+ * //=> 0o10
65
+ *
66
+ * type BinaryInteger: Integer<0b10>;
67
+ * //=> 0b10
68
+ *
69
+ * type HexadecimalInteger: Integer<0x10>;
70
+ * //=> 0x10
71
+ * ```
72
+ *
73
+ * @example
74
+ * ```
75
+ * import type {Integer} from 'type-fest';
76
+ *
77
+ * declare function setYear<T extends number>(length: Integer<T>): void;
78
+ * ```
79
+ *
80
+ * @see NegativeInteger
81
+ * @see NonNegativeInteger
82
+ *
83
+ * @category Numeric
84
+ */
85
+ export type Integer<T> = T extends unknown ? IsInteger<T> extends true ? T : never : never;
86
+ export type IsInteger<T> = T extends bigint ? true : T extends number ? number extends T ? false : T extends PositiveInfinity | NegativeInfinity ? false : Not<IsFloat<T>> : false;
87
+ export type IsFloat<T> = T extends number ? `${T}` extends `${string | number | bigint | boolean | null | undefined}${number}.${infer Decimal extends number}` ? Decimal extends Zero ? false : true : false : false;
88
+ /**
89
+ * A `number` that is not an integer.
90
+ *
91
+ * Use-case: Validating and documenting parameters.
92
+ *
93
+ * It does not accept `Infinity`.
94
+ *
95
+ * @example
96
+ * ```
97
+ * import type {Float} from 'type-fest';
98
+ *
99
+ * declare function setPercentage<T extends number>(length: Float<T>): void;
100
+ * ```
101
+ *
102
+ * @see Integer
103
+ *
104
+ * @category Numeric
105
+ */
106
+ export type Float<T> = T extends unknown ? IsFloat<T> extends true ? T : never : never;
107
+ /**
108
+ * A negative (`-∞ < x < 0`) `number` that is not an integer.
109
+ * Equivalent to `Negative<Float<T>>`.
110
+ *
111
+ * Use-case: Validating and documenting parameters.
112
+ *
113
+ * @see Negative
114
+ * @see Float
115
+ *
116
+ * @category Numeric
117
+ */
118
+ export type NegativeFloat<T extends number> = Negative<Float<T>>;
119
+ /**
120
+ * A negative `number`/`bigint` (`-∞ < x < 0`)
121
+ *
122
+ * Use-case: Validating and documenting parameters.
123
+ *
124
+ * @see NegativeInteger
125
+ * @see NonNegative
126
+ *
127
+ * @category Numeric
128
+ */
129
+ export type Negative<T extends Numeric> = T extends Zero ? never : `${T}` extends `-${string}` ? T : never;
130
+ /**
131
+ * A negative (`-∞ < x < 0`) `number` that is an integer.
132
+ * Equivalent to `Negative<Integer<T>>`.
133
+ *
134
+ * You can't pass a `bigint` as they are already guaranteed to be integers, instead use `Negative<T>`.
135
+ *
136
+ * Use-case: Validating and documenting parameters.
137
+ *
138
+ * @see Negative
139
+ * @see Integer
140
+ *
141
+ * @category Numeric
142
+ */
143
+ export type NegativeInteger<T extends number> = Negative<Integer<T>>;
144
+ /**
145
+ * A non-negative `number`/`bigint` (`0 <= x < ∞`).
146
+ *
147
+ * Use-case: Validating and documenting parameters.
148
+ *
149
+ * @see NonNegativeInteger
150
+ * @see Negative
151
+ *
152
+ * @example
153
+ * ```
154
+ * import type {NonNegative} from 'type-fest';
155
+ *
156
+ * declare function setLength<T extends number>(length: NonNegative<T>): void;
157
+ * ```
158
+ *
159
+ * @category Numeric
160
+ */
161
+ export type NonNegative<T extends Numeric> = T extends Zero ? T : Negative<T> extends never ? T : never;
162
+ /**
163
+ * A non-negative (`0 <= x < ∞`) `number` that is an integer.
164
+ * Equivalent to `NonNegative<Integer<T>>`.
165
+ *
166
+ * You can't pass a `bigint` as they are already guaranteed to be integers, instead use `NonNegative<T>`.
167
+ *
168
+ * Use-case: Validating and documenting parameters.
169
+ *
170
+ * @see NonNegative
171
+ * @see Integer
172
+ *
173
+ * @example
174
+ * ```
175
+ * import type {NonNegativeInteger} from 'type-fest';
176
+ *
177
+ * declare function setLength<T extends number>(length: NonNegativeInteger<T>): void;
178
+ * ```
179
+ *
180
+ * @category Numeric
181
+ */
182
+ export type NonNegativeInteger<T extends number> = NonNegative<Integer<T>>;
183
+ /**
184
+ * Returns a boolean for whether the given number is a negative number.
185
+ *
186
+ * @see Negative
187
+ *
188
+ * @example
189
+ * ```
190
+ * import type {IsNegative} from 'type-fest';
191
+ *
192
+ * type ShouldBeFalse = IsNegative<1>;
193
+ * type ShouldBeTrue = IsNegative<-1>;
194
+ * ```
195
+ *
196
+ * @category Numeric
197
+ */
198
+ export type IsNegative<T extends Numeric> = T extends Negative<T> ? true : false;
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,434 @@
1
+ import type { StaticPartOfArray, UnknownArray, VariablePartOfArray } from "./array";
2
+ import type { BuildTuple, EmptyObject, IsAny, IsNever, IsPrimitive, NonRecursiveType, Nullish, Primitive, Simplify } from "./base";
3
+ import type { StringKeyOf } from "./json";
4
+ import type { IsNotFalse, LessThan, Sum } from "./logic";
5
+ import type { Numeric } from "./number";
6
+ import type { StringDigit } from "./string";
7
+ import type { Index40, Nullable } from "./utilities";
8
+ /**
9
+ * Returns a boolean for whether the given type is an empty object.
10
+ */
11
+ export type IsEmptyObject<T> = T extends EmptyObject ? true : false;
12
+ /**
13
+ * Returns a boolean for whether the given type is a plain key-value object.
14
+ */
15
+ export type IsPlainObject<T> = T extends NonRecursiveType | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown> | UnknownArray ? false : T extends object ? true : false;
16
+ type LiteralCheck<T, LiteralType extends Primitive> = IsNever<T> extends false ? [T] extends [LiteralType & infer U] ? [U] extends [LiteralType] ? [LiteralType] extends [U] ? false : true : false : false : false;
17
+ type LiteralChecks<T, LiteralUnionType> = IsNotFalse<LiteralUnionType extends Primitive ? LiteralCheck<T, LiteralUnionType> : never>;
18
+ /**
19
+ * Returns a boolean for whether the given type is a string literal.
20
+ */
21
+ export type IsStringLiteral<T> = LiteralCheck<T, string>;
22
+ /**
23
+ * Returns a boolean for whether the given type is a numeric literal.
24
+ */
25
+ export type IsNumericLiteral<T> = LiteralChecks<T, Numeric>;
26
+ /**
27
+ * Returns a boolean for whether the given type is a boolean literal.
28
+ */
29
+ export type IsBooleanLiteral<T> = LiteralCheck<T, boolean>;
30
+ /**
31
+ * Returns a boolean for whether the given type is a symbol literal.
32
+ */
33
+ export type IsSymbolLiteral<T> = LiteralCheck<T, symbol>;
34
+ type IsLiteralUnion<T> = IsBooleanLiteral<T> | IsNumericLiteral<T> | IsStringLiteral<T> | IsSymbolLiteral<T>;
35
+ /**
36
+ * Returns a boolean for whether the given type is a literal type.
37
+ */
38
+ export type IsLiteral<T> = IsPrimitive<T> extends true ? IsNotFalse<IsLiteralUnion<T>> : false;
39
+ /**
40
+ * Returns a boolean for whether the given type is an object.
41
+ */
42
+ export type LiteralKeyOf<T> = keyof {
43
+ [K in keyof T as IsLiteral<K> extends true ? K : never]-?: never;
44
+ };
45
+ /**
46
+ * Allows creating a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
47
+ *
48
+ * Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals.
49
+ *
50
+ * This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as it's not needed anymore.
51
+ *
52
+ * @example
53
+ * ```
54
+ * import type {LiteralUnion} from 'type-fest';
55
+ *
56
+ * // Before
57
+ *
58
+ * type Pet = 'dog' | 'cat' | string;
59
+ *
60
+ * const pet: Pet = '';
61
+ * // Start typing in your TypeScript-enabled IDE.
62
+ * // You **will not** get auto-completion for `dog` and `cat` literals.
63
+ *
64
+ * // After
65
+ *
66
+ * type Pet2 = LiteralUnion<'dog' | 'cat', string>;
67
+ *
68
+ * const pet: Pet2 = '';
69
+ * // You **will** get auto-completion for `dog` and `cat` literals.
70
+ * ```
71
+ *
72
+ * @category Type
73
+ */
74
+ export type LiteralUnion<LiteralType, BaseType extends Primitive> = (BaseType & Record<never, never>) | LiteralType;
75
+ /**
76
+ * Create an object type with the given key `<Key>` and value `<Value>`.
77
+ *
78
+ * It will copy the prefix and optional status of the same key from the given object `CopiedFrom` into the result.
79
+ *
80
+ * @example
81
+ * ```
82
+ * type A = BuildObject<'a', string>;
83
+ * //=> {a: string}
84
+ *
85
+ * // Copy `readonly` and `?` from the key `a` of `{readonly a?: any}`
86
+ * type B = BuildObject<'a', string, {readonly a?: any}>;
87
+ * //=> {readonly a?: string}
88
+ * ```
89
+ */
90
+ export type BuildObject<Key extends PropertyKey, Value, CopiedFrom extends object = {}> = Key extends keyof CopiedFrom ? Pick<{
91
+ [_ in keyof CopiedFrom]: Value;
92
+ }, Key> : Key extends `${infer NumberKey extends number}` ? NumberKey extends keyof CopiedFrom ? Pick<{
93
+ [_ in keyof CopiedFrom]: Value;
94
+ }, NumberKey> : {
95
+ [_ in Key]: Value;
96
+ } : {
97
+ [_ in Key]: Value;
98
+ };
99
+ /**
100
+ * Return a string representation of the given string or number.
101
+ *
102
+ * Note: This type is not the return type of the `.toString()` function.
103
+ */
104
+ export type ToString<T> = T extends number | string ? `${T}` : never;
105
+ /**
106
+ * Extract the object field type if T is an object and K is a key of T, return `never` otherwise.
107
+ *
108
+ * It creates a type-safe way to access the member type of `unknown` type.
109
+ */
110
+ export type ObjectValue<T, K> = K extends keyof T ? T[K] : ToString<K> extends keyof T ? T[ToString<K>] : K extends `${infer NumberK extends number}` ? NumberK extends keyof T ? T[NumberK] : never : never;
111
+ export type Paths<T> = Paths_<T>;
112
+ type Paths_<T, Depth extends number = 0> = T extends NonRecursiveType | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown> ? never : IsAny<T> extends true ? never : T extends UnknownArray ? number extends T["length"] ? InternalPaths<VariablePartOfArray<T>[number][], Depth> | InternalPaths<StaticPartOfArray<T>, Depth> : InternalPaths<T, Depth> : T extends object ? InternalPaths<T, Depth> : never;
113
+ export type InternalPaths<_T, Depth extends number = 0, T = Required<_T>> = T extends EmptyObject | readonly [] ? never : {
114
+ [Key in keyof T]: Key extends number | string ? Key | (LessThan<Depth, 15> extends true ? IsNever<Paths_<T[Key], Sum<Depth, 1>>> extends false ? `${Key}.${Paths_<T[Key], Sum<Depth, 1>>}` : never : never) | ToString<Key> : never;
115
+ }[(T extends UnknownArray ? number : unknown) & keyof T];
116
+ interface GetOptions {
117
+ /**
118
+ * Include `undefined` in the return type when accessing properties.
119
+ *
120
+ * Setting this to `false` is not recommended.
121
+ *
122
+ * @defaultValue `true`
123
+ */
124
+ strict?: boolean;
125
+ }
126
+ /**
127
+ * Like the `Get` type but receives an array of strings as a path parameter.
128
+ */
129
+ export type GetWithPath<BaseType, Keys extends readonly string[], Options extends GetOptions = {}> = Keys extends readonly [] ? BaseType : Keys extends readonly [infer Head, ...infer Tail] ? GetWithPath<PropertyOf<BaseType, Extract<Head, string>, Options>, Extract<Tail, string[]>, Options> : never;
130
+ /**
131
+ * Adds `undefined` to `Type` if `strict` is enabled.
132
+ */
133
+ type Strictify<Type, Options extends GetOptions> = Options["strict"] extends false ? Type : Type | undefined;
134
+ /**
135
+ * If `Options['strict']` is `true`, includes `undefined` in the returned type when accessing properties on `Record<string, any>`.
136
+ *
137
+ * Known limitations:
138
+ * - Does not include `undefined` in the type on object types with an index signature (for example, `{a: string; [key: string]: string}`).
139
+ */
140
+ type StrictPropertyOf<BaseType, Key extends keyof BaseType, Options extends GetOptions> = Record<string, any> extends BaseType ? string extends keyof BaseType ? Strictify<BaseType[Key], Options> : BaseType[Key] : BaseType[Key];
141
+ /**
142
+ * Represents an array of strings split using a given character or character set.
143
+ *
144
+ * Use-case: Defining the return type of a method like `String.prototype.split`.
145
+ *
146
+ * @example
147
+ * ```
148
+ * import type {Split} from 'type-fest';
149
+ *
150
+ * declare function split<S extends string, D extends string>(string: S, separator: D): Split<S, D>;
151
+ *
152
+ * type Item = 'foo' | 'bar' | 'baz' | 'waldo';
153
+ * const items = 'foo,bar,baz,waldo';
154
+ * let array: Item[];
155
+ *
156
+ * array = split(items, ',');
157
+ * ```
158
+ *
159
+ * @category String
160
+ * @category Template literal
161
+ */
162
+ export type Split<S extends string, Delimiter extends string> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [Head, ...Split<Tail, Delimiter>] : S extends Delimiter ? [] : [S];
163
+ /**
164
+ * Splits a dot-prop style path into a tuple comprised of the properties in the path. Handles square-bracket notation.
165
+ *
166
+ * @example
167
+ * ```
168
+ * ToPath<'foo.bar.baz'>
169
+ * //=> ['foo', 'bar', 'baz']
170
+ *
171
+ * ToPath<'foo[0].bar.baz'>
172
+ * //=> ['foo', '0', 'bar', 'baz']
173
+ * ```
174
+ */
175
+ export type ToPath<S extends string> = Split<FixPathSquareBrackets<S>, ".">;
176
+ /**
177
+ * Replaces square-bracketed dot notation with dots, for example, `foo[0].bar` -> `foo.0.bar`.
178
+ */
179
+ type FixPathSquareBrackets<Path extends string> = Path extends `[${infer Head}]${infer Tail}` ? Tail extends `[${string}` ? `${Head}.${FixPathSquareBrackets<Tail>}` : `${Head}${FixPathSquareBrackets<Tail>}` : Path extends `${infer Head}[${infer Middle}]${infer Tail}` ? `${Head}.${FixPathSquareBrackets<`[${Middle}]${Tail}`>}` : Path;
180
+ /**
181
+ * Returns true if `LongString` is made up out of `Substring` repeated 0 or more times.
182
+ *
183
+ * @example
184
+ * ```ts
185
+ * ConsistsOnlyOf<'aaa', 'a'> //=> true
186
+ * ConsistsOnlyOf<'ababab', 'ab'> //=> true
187
+ * ConsistsOnlyOf<'aBa', 'a'> //=> false
188
+ * ConsistsOnlyOf<'', 'a'> //=> true
189
+ * ```
190
+ *
191
+ */
192
+ type ConsistsOnlyOf<LongString extends string, Substring extends string> = LongString extends "" ? true : LongString extends `${Substring}${infer Tail}` ? ConsistsOnlyOf<Tail, Substring> : false;
193
+ /**
194
+ * Convert a type which may have number keys to one with string keys, making it possible to index using strings retrieved from template types.
195
+ *
196
+ * @example
197
+ *
198
+ * ```ts
199
+ * type WithNumbers = {foo: string; 0: boolean};
200
+ * type WithStrings = WithStringKeys<WithNumbers>;
201
+ *
202
+ * type WithNumbersKeys = keyof WithNumbers;
203
+ * //=> 'foo' | 0
204
+ * type WithStringsKeys = keyof WithStrings;
205
+ * //=> 'foo' | '0'
206
+ * ```
207
+ *
208
+ */
209
+ type WithStringKeys<BaseType> = {
210
+ [Key in StringKeyOf<BaseType>]: UncheckedIndex<BaseType, Key>;
211
+ };
212
+ /**
213
+ Perform a `T[U]` operation if `T` supports indexing.
214
+ */
215
+ type UncheckedIndex<T, U extends number | string> = [T] extends [
216
+ Record<number | string, any>
217
+ ] ? T[U] : never;
218
+ /**
219
+ * Get a property of an object or array. Works when indexing arrays using number-literal-strings, for example, `PropertyOf<number[], '0'> = number`, and when indexing objects with number keys.
220
+ *
221
+ * Note:
222
+ * - Returns `unknown` if `Key` is not a property of `BaseType`, since TypeScript uses structural typing, and it cannot be guaranteed that extra properties unknown to the type system will exist at runtime.
223
+ * - Returns `undefined` from nullish values, to match the behavior of most deep-key libraries like `lodash`, `dot-prop`, etc.
224
+ */
225
+ type PropertyOf<BaseType, Key extends string, Options extends GetOptions = {}> = BaseType extends Nullish ? undefined : Key extends keyof BaseType ? StrictPropertyOf<BaseType, Key, Options> : BaseType extends readonly [] | readonly [unknown, ...unknown[]] ? unknown : BaseType extends {
226
+ [n: number]: infer Item;
227
+ length: number;
228
+ } ? ConsistsOnlyOf<Key, StringDigit> extends true ? Strictify<Item, Options> : unknown : Key extends keyof WithStringKeys<BaseType> ? StrictPropertyOf<WithStringKeys<BaseType>, Key, Options> : unknown;
229
+ /**
230
+ * Get a deeply-nested property from an object using a key path, like Lodash's `.get()` function.
231
+ *
232
+ * Use-case: Retrieve a property from deep inside an API response or some other complex object.
233
+ *
234
+ * @example
235
+ * ```
236
+ * import type {Get} from 'type-fest';
237
+ * import * as lodash from 'lodash';
238
+ *
239
+ * const get = <BaseType, Path extends string | readonly string[]>(object: BaseType, path: Path): Get<BaseType, Path> =>
240
+ * lodash.get(object, path);
241
+ *
242
+ * interface ApiResponse {
243
+ * hits: {
244
+ * hits: Array<{
245
+ * _id: string
246
+ * _source: {
247
+ * name: Array<{
248
+ * given: string[]
249
+ * family: string
250
+ * }>
251
+ * birthDate: string
252
+ * }
253
+ * }>
254
+ * }
255
+ * }
256
+ *
257
+ * const getName = (apiResponse: ApiResponse) =>
258
+ * get(apiResponse, 'hits.hits[0]._source.name');
259
+ * //=> Array<{given: string[]; family: string}> | undefined
260
+ *
261
+ * // Path also supports a readonly array of strings
262
+ * const getNameWithPathArray = (apiResponse: ApiResponse) =>
263
+ * get(apiResponse, ['hits','hits', '0', '_source', 'name'] as const);
264
+ * //=> Array<{given: string[]; family: string}> | undefined
265
+ *
266
+ * // Non-strict mode:
267
+ * Get<string[], '3', {strict: false}> //=> string
268
+ * Get<Record<string, string>, 'foo', {strict: true}> // => string
269
+ * ```
270
+ *
271
+ * @category Object
272
+ * @category Array
273
+ * @category Template literal
274
+ */
275
+ export type Get<BaseType, Path extends readonly string[] | string, Options extends GetOptions = NonNullable<unknown>> = GetWithPath<BaseType, Path extends string ? ToPath<Path> : Path, Options>;
276
+ /**
277
+ * Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
278
+ *
279
+ * Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
280
+ *
281
+ * @example
282
+ * ```
283
+ * import type {UnionToIntersection} from 'type-fest';
284
+ *
285
+ * type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
286
+ *
287
+ * type Intersection = UnionToIntersection<Union>;
288
+ * //=> {the(): void; great(arg: string): void; escape: boolean};
289
+ * ```
290
+ *
291
+ * A more applicable example which could make its way into your library code follows.
292
+ *
293
+ * @example
294
+ * ```
295
+ * import type {UnionToIntersection} from 'type-fest';
296
+ *
297
+ * class CommandOne {
298
+ * commands: {
299
+ * a1: () => undefined,
300
+ * b1: () => undefined,
301
+ * }
302
+ * }
303
+ *
304
+ * class CommandTwo {
305
+ * commands: {
306
+ * a2: (argA: string) => undefined,
307
+ * b2: (argB: string) => undefined,
308
+ * }
309
+ * }
310
+ *
311
+ * const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
312
+ * type Union = typeof union;
313
+ * //=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
314
+ *
315
+ * type Intersection = UnionToIntersection<Union>;
316
+ * //=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
317
+ * ```
318
+ *
319
+ * @category Type
320
+ */
321
+ export type UnionToIntersection<Union> = (Union extends unknown ? (_distributedUnion: Union) => void : never) extends (_mergedIntersection: infer Intersection) => void ? // The `& Union` is to allow indexing by the resulting type
322
+ Intersection & Union : never;
323
+ /**
324
+ * Pick properties from a deeply-nested object.
325
+ *
326
+ * It supports recursing into arrays.
327
+ *
328
+ * Use-case: Distill complex objects down to the components you need to target.
329
+ *
330
+ * @example
331
+ * ```
332
+ * import type {PickDeep, PartialDeep} from 'type-fest';
333
+ *
334
+ * type Configuration = {
335
+ * userConfig: {
336
+ * name: string;
337
+ * age: number;
338
+ * address: [
339
+ * {
340
+ * city1: string;
341
+ * street1: string;
342
+ * },
343
+ * {
344
+ * city2: string;
345
+ * street2: string;
346
+ * }
347
+ * ]
348
+ * };
349
+ * otherConfig: any;
350
+ * };
351
+ *
352
+ * type NameConfig = PickDeep<Configuration, 'userConfig.name'>;
353
+ * // type NameConfig = {
354
+ * // userConfig: {
355
+ * // name: string;
356
+ * // }
357
+ * // };
358
+ *
359
+ * // Supports optional properties
360
+ * type User = PickDeep<PartialDeep<Configuration>, 'userConfig.name' | 'userConfig.age'>;
361
+ * // type User = {
362
+ * // userConfig?: {
363
+ * // name?: string;
364
+ * // age?: number;
365
+ * // };
366
+ * // };
367
+ *
368
+ * // Supports array
369
+ * type AddressConfig = PickDeep<Configuration, 'userConfig.address.0'>;
370
+ * // type AddressConfig = {
371
+ * // userConfig: {
372
+ * // address: [{
373
+ * // city1: string;
374
+ * // street1: string;
375
+ * // }];
376
+ * // };
377
+ * // }
378
+ *
379
+ * // Supports recurse into array
380
+ * type Street = PickDeep<Configuration, 'userConfig.address.1.street2'>;
381
+ * // type Street = {
382
+ * // userConfig: {
383
+ * // address: [
384
+ * // unknown,
385
+ * // {street2: string}
386
+ * // ];
387
+ * // };
388
+ * // }
389
+ * ```
390
+ *
391
+ * @category Object
392
+ * @category Array
393
+ */
394
+ export type PickDeep<T, PathUnion extends Paths<T>> = T extends NonRecursiveType ? never : T extends UnknownArray ? UnionToIntersection<{
395
+ [P in PathUnion]: InternalPickDeep<T, P>;
396
+ }[PathUnion]> : T extends object ? Simplify<UnionToIntersection<{
397
+ [P in PathUnion]: InternalPickDeep<T, P>;
398
+ }[PathUnion]>> : never;
399
+ /**
400
+ * Pick an object/array from the given object/array by one path.
401
+ */
402
+ type InternalPickDeep<T, Path extends number | string> = T extends NonRecursiveType ? never : T extends UnknownArray ? PickDeepArray<T, Path> : T extends object ? Simplify<PickDeepObject<T, Path>> : never;
403
+ /**
404
+ * Pick an object from the given object by one path.
405
+ */
406
+ type PickDeepObject<RecordType extends object, P extends number | string> = P extends `${infer RecordKeyInPath}.${infer SubPath}` ? ObjectValue<RecordType, RecordKeyInPath> extends infer ObjectV ? IsNever<ObjectV> extends false ? BuildObject<RecordKeyInPath, InternalPickDeep<NonNullable<ObjectV>, SubPath>, RecordType> : never : never : ObjectValue<RecordType, P> extends infer ObjectV ? IsNever<ObjectV> extends false ? BuildObject<P, ObjectV, RecordType> : never : never;
407
+ /**
408
+ * Pick an array from the given array by one path.
409
+ */
410
+ type PickDeepArray<ArrayType extends UnknownArray, P extends number | string> = P extends `${infer ArrayIndex extends number}.${infer SubPath}` ? number extends ArrayIndex ? ArrayType extends unknown[] ? InternalPickDeep<NonNullable<ArrayType[number]>, SubPath>[] : ArrayType extends readonly unknown[] ? readonly InternalPickDeep<NonNullable<ArrayType[number]>, SubPath>[] : never : ArrayType extends unknown[] ? [
411
+ ...BuildTuple<ArrayIndex>,
412
+ InternalPickDeep<NonNullable<ArrayType[ArrayIndex]>, SubPath>
413
+ ] : ArrayType extends readonly unknown[] ? readonly [
414
+ ...BuildTuple<ArrayIndex>,
415
+ InternalPickDeep<NonNullable<ArrayType[ArrayIndex]>, SubPath>
416
+ ] : never : P extends `${infer ArrayIndex extends number}` ? number extends ArrayIndex ? ArrayType : ArrayType extends unknown[] ? [...BuildTuple<ArrayIndex>, ArrayType[ArrayIndex]] : ArrayType extends readonly unknown[] ? readonly [...BuildTuple<ArrayIndex>, ArrayType[ArrayIndex]] : never : never;
417
+ type IsTuple<T> = T extends {
418
+ length: infer Length;
419
+ } & readonly any[] ? Length extends Index40 ? T : never : never;
420
+ type AllowedIndexes<Tuple extends readonly any[], Keys extends number = never> = Tuple extends readonly [] ? Keys : Tuple extends readonly [infer _First, ...infer Tail] ? AllowedIndexes<Tail, Keys | Tail["length"]> : Keys;
421
+ type PrefixArrayAccessor<T extends any[], TDepth extends any[]> = {
422
+ [K in keyof T]: `[${number}]${DeepKey<T[K], TDepth>}`;
423
+ }[number];
424
+ type PrefixTupleAccessor<T extends any[], TIndex extends number, TDepth extends any[]> = {
425
+ [K in TIndex]: `[${K}]${DeepKey<T[K], TDepth>}` | `[${K}]`;
426
+ }[TIndex];
427
+ type PrefixObjectAccessor<T extends object, TDepth extends any[]> = {
428
+ [K in keyof T]-?: K extends number | string ? `${PrefixFromDepth<K, TDepth>}${DeepKey<T[K], [TDepth]>}` | PrefixFromDepth<K, TDepth> : never;
429
+ }[keyof T];
430
+ type PrefixFromDepth<T extends number | string, TDepth extends any[]> = TDepth["length"] extends 0 ? T : `.${T}`;
431
+ export type DeepKey<T, TDepth extends any[] = []> = TDepth["length"] extends 5 ? never : unknown extends T ? PrefixFromDepth<string, TDepth> : T extends IsTuple<T> & any[] ? PrefixTupleAccessor<T, AllowedIndexes<T>, TDepth> : T extends any[] ? PrefixArrayAccessor<T, [...TDepth, any]> : T extends Date ? never : T extends object ? PrefixObjectAccessor<T, TDepth> : T extends bigint | boolean | number | string ? "" : never;
432
+ export type DeepValue<TObject extends Record<string, unknown>, TPath extends DeepKey<TObject>> = GetWithPath<TObject, ToPath<TPath>>;
433
+ export type NullableDeepValue<TObject extends Record<string, unknown>, TPath extends DeepKey<TObject>> = Nullable<GetWithPath<TObject, ToPath<TPath>>>;
434
+ export {};
File without changes
@@ -0,0 +1 @@
1
+ "use strict";