pull-request-split-advisor 3.1.2

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 (375) hide show
  1. package/LICENSE +52 -0
  2. package/README.md +168 -0
  3. package/dist/ai/config-wizard.js +282 -0
  4. package/dist/ai/enricher.js +290 -0
  5. package/dist/ai/prompts.js +231 -0
  6. package/dist/ai/provider.js +265 -0
  7. package/dist/cli.js +442 -0
  8. package/dist/config/config.js +315 -0
  9. package/dist/config/default-config.js +223 -0
  10. package/dist/core/blocks.js +145 -0
  11. package/dist/core/commit-planner.js +273 -0
  12. package/dist/core/dependency.js +284 -0
  13. package/dist/core/file-stats.js +341 -0
  14. package/dist/core/history.js +72 -0
  15. package/dist/core/planner.js +25 -0
  16. package/dist/core/scoring.js +166 -0
  17. package/dist/core/strategy.js +486 -0
  18. package/dist/git/branch-naming.js +120 -0
  19. package/dist/git/executor.js +378 -0
  20. package/dist/git/git.js +239 -0
  21. package/dist/output/report-styles.generated.js +10 -0
  22. package/dist/output/report.js +726 -0
  23. package/dist/output/ui.js +417 -0
  24. package/dist/shared/constants.js +59 -0
  25. package/dist/shared/types.js +7 -0
  26. package/dist/shared/utils.js +73 -0
  27. package/node_modules/@colors/colors/LICENSE +26 -0
  28. package/node_modules/@colors/colors/README.md +219 -0
  29. package/node_modules/@colors/colors/examples/normal-usage.js +83 -0
  30. package/node_modules/@colors/colors/examples/safe-string.js +80 -0
  31. package/node_modules/@colors/colors/index.d.ts +136 -0
  32. package/node_modules/@colors/colors/lib/colors.js +211 -0
  33. package/node_modules/@colors/colors/lib/custom/trap.js +46 -0
  34. package/node_modules/@colors/colors/lib/custom/zalgo.js +110 -0
  35. package/node_modules/@colors/colors/lib/extendStringPrototype.js +110 -0
  36. package/node_modules/@colors/colors/lib/index.js +13 -0
  37. package/node_modules/@colors/colors/lib/maps/america.js +10 -0
  38. package/node_modules/@colors/colors/lib/maps/rainbow.js +12 -0
  39. package/node_modules/@colors/colors/lib/maps/random.js +11 -0
  40. package/node_modules/@colors/colors/lib/maps/zebra.js +5 -0
  41. package/node_modules/@colors/colors/lib/styles.js +95 -0
  42. package/node_modules/@colors/colors/lib/system/has-flag.js +35 -0
  43. package/node_modules/@colors/colors/lib/system/supports-colors.js +151 -0
  44. package/node_modules/@colors/colors/package.json +45 -0
  45. package/node_modules/@colors/colors/safe.d.ts +48 -0
  46. package/node_modules/@colors/colors/safe.js +10 -0
  47. package/node_modules/@colors/colors/themes/generic-logging.js +12 -0
  48. package/node_modules/ansi-align/LICENSE +13 -0
  49. package/node_modules/ansi-align/README.md +80 -0
  50. package/node_modules/ansi-align/index.js +61 -0
  51. package/node_modules/ansi-align/node_modules/ansi-regex/index.d.ts +37 -0
  52. package/node_modules/ansi-align/node_modules/ansi-regex/index.js +10 -0
  53. package/node_modules/ansi-align/node_modules/ansi-regex/license +9 -0
  54. package/node_modules/ansi-align/node_modules/ansi-regex/package.json +55 -0
  55. package/node_modules/ansi-align/node_modules/ansi-regex/readme.md +78 -0
  56. package/node_modules/ansi-align/node_modules/emoji-regex/LICENSE-MIT.txt +20 -0
  57. package/node_modules/ansi-align/node_modules/emoji-regex/README.md +73 -0
  58. package/node_modules/ansi-align/node_modules/emoji-regex/es2015/index.js +6 -0
  59. package/node_modules/ansi-align/node_modules/emoji-regex/es2015/text.js +6 -0
  60. package/node_modules/ansi-align/node_modules/emoji-regex/index.d.ts +23 -0
  61. package/node_modules/ansi-align/node_modules/emoji-regex/index.js +6 -0
  62. package/node_modules/ansi-align/node_modules/emoji-regex/package.json +50 -0
  63. package/node_modules/ansi-align/node_modules/emoji-regex/text.js +6 -0
  64. package/node_modules/ansi-align/node_modules/string-width/index.d.ts +29 -0
  65. package/node_modules/ansi-align/node_modules/string-width/index.js +47 -0
  66. package/node_modules/ansi-align/node_modules/string-width/license +9 -0
  67. package/node_modules/ansi-align/node_modules/string-width/package.json +56 -0
  68. package/node_modules/ansi-align/node_modules/string-width/readme.md +50 -0
  69. package/node_modules/ansi-align/node_modules/strip-ansi/index.d.ts +17 -0
  70. package/node_modules/ansi-align/node_modules/strip-ansi/index.js +4 -0
  71. package/node_modules/ansi-align/node_modules/strip-ansi/license +9 -0
  72. package/node_modules/ansi-align/node_modules/strip-ansi/package.json +54 -0
  73. package/node_modules/ansi-align/node_modules/strip-ansi/readme.md +46 -0
  74. package/node_modules/ansi-align/package.json +43 -0
  75. package/node_modules/ansi-regex/index.d.ts +33 -0
  76. package/node_modules/ansi-regex/index.js +14 -0
  77. package/node_modules/ansi-regex/license +9 -0
  78. package/node_modules/ansi-regex/package.json +61 -0
  79. package/node_modules/ansi-regex/readme.md +66 -0
  80. package/node_modules/ansi-styles/index.d.ts +236 -0
  81. package/node_modules/ansi-styles/index.js +223 -0
  82. package/node_modules/ansi-styles/license +9 -0
  83. package/node_modules/ansi-styles/package.json +54 -0
  84. package/node_modules/ansi-styles/readme.md +173 -0
  85. package/node_modules/boxen/index.d.ts +267 -0
  86. package/node_modules/boxen/index.js +376 -0
  87. package/node_modules/boxen/license +9 -0
  88. package/node_modules/boxen/package.json +69 -0
  89. package/node_modules/boxen/readme.md +300 -0
  90. package/node_modules/camelcase/index.d.ts +102 -0
  91. package/node_modules/camelcase/index.js +110 -0
  92. package/node_modules/camelcase/license +9 -0
  93. package/node_modules/camelcase/package.json +47 -0
  94. package/node_modules/camelcase/readme.md +135 -0
  95. package/node_modules/chalk/license +9 -0
  96. package/node_modules/chalk/package.json +83 -0
  97. package/node_modules/chalk/readme.md +297 -0
  98. package/node_modules/chalk/source/index.d.ts +325 -0
  99. package/node_modules/chalk/source/index.js +225 -0
  100. package/node_modules/chalk/source/utilities.js +33 -0
  101. package/node_modules/chalk/source/vendor/ansi-styles/index.d.ts +236 -0
  102. package/node_modules/chalk/source/vendor/ansi-styles/index.js +223 -0
  103. package/node_modules/chalk/source/vendor/supports-color/browser.d.ts +1 -0
  104. package/node_modules/chalk/source/vendor/supports-color/browser.js +34 -0
  105. package/node_modules/chalk/source/vendor/supports-color/index.d.ts +55 -0
  106. package/node_modules/chalk/source/vendor/supports-color/index.js +190 -0
  107. package/node_modules/cli-boxes/boxes.json +82 -0
  108. package/node_modules/cli-boxes/index.d.ts +127 -0
  109. package/node_modules/cli-boxes/index.js +6 -0
  110. package/node_modules/cli-boxes/license +9 -0
  111. package/node_modules/cli-boxes/package.json +42 -0
  112. package/node_modules/cli-boxes/readme.md +115 -0
  113. package/node_modules/cli-table3/LICENSE +21 -0
  114. package/node_modules/cli-table3/README.md +236 -0
  115. package/node_modules/cli-table3/index.d.ts +96 -0
  116. package/node_modules/cli-table3/index.js +1 -0
  117. package/node_modules/cli-table3/node_modules/ansi-regex/index.d.ts +37 -0
  118. package/node_modules/cli-table3/node_modules/ansi-regex/index.js +10 -0
  119. package/node_modules/cli-table3/node_modules/ansi-regex/license +9 -0
  120. package/node_modules/cli-table3/node_modules/ansi-regex/package.json +55 -0
  121. package/node_modules/cli-table3/node_modules/ansi-regex/readme.md +78 -0
  122. package/node_modules/cli-table3/node_modules/emoji-regex/LICENSE-MIT.txt +20 -0
  123. package/node_modules/cli-table3/node_modules/emoji-regex/README.md +73 -0
  124. package/node_modules/cli-table3/node_modules/emoji-regex/es2015/index.js +6 -0
  125. package/node_modules/cli-table3/node_modules/emoji-regex/es2015/text.js +6 -0
  126. package/node_modules/cli-table3/node_modules/emoji-regex/index.d.ts +23 -0
  127. package/node_modules/cli-table3/node_modules/emoji-regex/index.js +6 -0
  128. package/node_modules/cli-table3/node_modules/emoji-regex/package.json +50 -0
  129. package/node_modules/cli-table3/node_modules/emoji-regex/text.js +6 -0
  130. package/node_modules/cli-table3/node_modules/string-width/index.d.ts +29 -0
  131. package/node_modules/cli-table3/node_modules/string-width/index.js +47 -0
  132. package/node_modules/cli-table3/node_modules/string-width/license +9 -0
  133. package/node_modules/cli-table3/node_modules/string-width/package.json +56 -0
  134. package/node_modules/cli-table3/node_modules/string-width/readme.md +50 -0
  135. package/node_modules/cli-table3/node_modules/strip-ansi/index.d.ts +17 -0
  136. package/node_modules/cli-table3/node_modules/strip-ansi/index.js +4 -0
  137. package/node_modules/cli-table3/node_modules/strip-ansi/license +9 -0
  138. package/node_modules/cli-table3/node_modules/strip-ansi/package.json +54 -0
  139. package/node_modules/cli-table3/node_modules/strip-ansi/readme.md +46 -0
  140. package/node_modules/cli-table3/package.json +100 -0
  141. package/node_modules/cli-table3/src/cell.js +409 -0
  142. package/node_modules/cli-table3/src/debug.js +28 -0
  143. package/node_modules/cli-table3/src/layout-manager.js +254 -0
  144. package/node_modules/cli-table3/src/table.js +106 -0
  145. package/node_modules/cli-table3/src/utils.js +344 -0
  146. package/node_modules/commander/LICENSE +22 -0
  147. package/node_modules/commander/Readme.md +1157 -0
  148. package/node_modules/commander/esm.mjs +16 -0
  149. package/node_modules/commander/index.js +24 -0
  150. package/node_modules/commander/lib/argument.js +149 -0
  151. package/node_modules/commander/lib/command.js +2509 -0
  152. package/node_modules/commander/lib/error.js +39 -0
  153. package/node_modules/commander/lib/help.js +520 -0
  154. package/node_modules/commander/lib/option.js +330 -0
  155. package/node_modules/commander/lib/suggestSimilar.js +101 -0
  156. package/node_modules/commander/package-support.json +16 -0
  157. package/node_modules/commander/package.json +84 -0
  158. package/node_modules/commander/typings/esm.d.mts +3 -0
  159. package/node_modules/commander/typings/index.d.ts +969 -0
  160. package/node_modules/emoji-regex/LICENSE-MIT.txt +20 -0
  161. package/node_modules/emoji-regex/README.md +107 -0
  162. package/node_modules/emoji-regex/index.d.ts +3 -0
  163. package/node_modules/emoji-regex/index.js +4 -0
  164. package/node_modules/emoji-regex/index.mjs +4 -0
  165. package/node_modules/emoji-regex/package.json +45 -0
  166. package/node_modules/get-east-asian-width/index.d.ts +60 -0
  167. package/node_modules/get-east-asian-width/index.js +30 -0
  168. package/node_modules/get-east-asian-width/license +9 -0
  169. package/node_modules/get-east-asian-width/lookup-data.js +18 -0
  170. package/node_modules/get-east-asian-width/lookup.js +135 -0
  171. package/node_modules/get-east-asian-width/package.json +71 -0
  172. package/node_modules/get-east-asian-width/readme.md +65 -0
  173. package/node_modules/get-east-asian-width/utilities.js +24 -0
  174. package/node_modules/is-fullwidth-code-point/index.d.ts +17 -0
  175. package/node_modules/is-fullwidth-code-point/index.js +50 -0
  176. package/node_modules/is-fullwidth-code-point/license +9 -0
  177. package/node_modules/is-fullwidth-code-point/package.json +42 -0
  178. package/node_modules/is-fullwidth-code-point/readme.md +39 -0
  179. package/node_modules/isbinaryfile/LICENSE.txt +22 -0
  180. package/node_modules/isbinaryfile/README.md +70 -0
  181. package/node_modules/isbinaryfile/lib/index.d.ts +3 -0
  182. package/node_modules/isbinaryfile/lib/index.js +256 -0
  183. package/node_modules/isbinaryfile/package.json +64 -0
  184. package/node_modules/string-width/index.d.ts +39 -0
  185. package/node_modules/string-width/index.js +82 -0
  186. package/node_modules/string-width/license +9 -0
  187. package/node_modules/string-width/package.json +64 -0
  188. package/node_modules/string-width/readme.md +66 -0
  189. package/node_modules/strip-ansi/index.d.ts +15 -0
  190. package/node_modules/strip-ansi/index.js +19 -0
  191. package/node_modules/strip-ansi/license +9 -0
  192. package/node_modules/strip-ansi/package.json +59 -0
  193. package/node_modules/strip-ansi/readme.md +37 -0
  194. package/node_modules/type-fest/index.d.ts +178 -0
  195. package/node_modules/type-fest/license-cc0 +121 -0
  196. package/node_modules/type-fest/license-mit +9 -0
  197. package/node_modules/type-fest/package.json +91 -0
  198. package/node_modules/type-fest/readme.md +1060 -0
  199. package/node_modules/type-fest/source/all-union-fields.d.ts +88 -0
  200. package/node_modules/type-fest/source/and.d.ts +25 -0
  201. package/node_modules/type-fest/source/array-indices.d.ts +23 -0
  202. package/node_modules/type-fest/source/array-slice.d.ts +109 -0
  203. package/node_modules/type-fest/source/array-splice.d.ts +99 -0
  204. package/node_modules/type-fest/source/array-tail.d.ts +76 -0
  205. package/node_modules/type-fest/source/array-values.d.ts +22 -0
  206. package/node_modules/type-fest/source/arrayable.d.ts +29 -0
  207. package/node_modules/type-fest/source/async-return-type.d.ts +23 -0
  208. package/node_modules/type-fest/source/asyncify.d.ts +32 -0
  209. package/node_modules/type-fest/source/basic.d.ts +68 -0
  210. package/node_modules/type-fest/source/camel-case.d.ts +89 -0
  211. package/node_modules/type-fest/source/camel-cased-properties-deep.d.ts +97 -0
  212. package/node_modules/type-fest/source/camel-cased-properties.d.ts +43 -0
  213. package/node_modules/type-fest/source/conditional-except.d.ts +45 -0
  214. package/node_modules/type-fest/source/conditional-keys.d.ts +47 -0
  215. package/node_modules/type-fest/source/conditional-pick-deep.d.ts +118 -0
  216. package/node_modules/type-fest/source/conditional-pick.d.ts +44 -0
  217. package/node_modules/type-fest/source/conditional-simplify.d.ts +32 -0
  218. package/node_modules/type-fest/source/delimiter-case.d.ts +78 -0
  219. package/node_modules/type-fest/source/delimiter-cased-properties-deep.d.ts +106 -0
  220. package/node_modules/type-fest/source/delimiter-cased-properties.d.ts +46 -0
  221. package/node_modules/type-fest/source/distributed-omit.d.ts +89 -0
  222. package/node_modules/type-fest/source/distributed-pick.d.ts +85 -0
  223. package/node_modules/type-fest/source/empty-object.d.ts +46 -0
  224. package/node_modules/type-fest/source/enforce-optional.d.ts +47 -0
  225. package/node_modules/type-fest/source/entries.d.ts +62 -0
  226. package/node_modules/type-fest/source/entry.d.ts +65 -0
  227. package/node_modules/type-fest/source/exact.d.ts +68 -0
  228. package/node_modules/type-fest/source/except.d.ts +108 -0
  229. package/node_modules/type-fest/source/find-global-type.d.ts +64 -0
  230. package/node_modules/type-fest/source/fixed-length-array.d.ts +43 -0
  231. package/node_modules/type-fest/source/get.d.ts +219 -0
  232. package/node_modules/type-fest/source/global-this.d.ts +21 -0
  233. package/node_modules/type-fest/source/greater-than-or-equal.d.ts +22 -0
  234. package/node_modules/type-fest/source/greater-than.d.ts +56 -0
  235. package/node_modules/type-fest/source/has-optional-keys.d.ts +21 -0
  236. package/node_modules/type-fest/source/has-readonly-keys.d.ts +21 -0
  237. package/node_modules/type-fest/source/has-required-keys.d.ts +59 -0
  238. package/node_modules/type-fest/source/has-writable-keys.d.ts +21 -0
  239. package/node_modules/type-fest/source/if-any.d.ts +24 -0
  240. package/node_modules/type-fest/source/if-empty-object.d.ts +26 -0
  241. package/node_modules/type-fest/source/if-never.d.ts +24 -0
  242. package/node_modules/type-fest/source/if-null.d.ts +24 -0
  243. package/node_modules/type-fest/source/if-unknown.d.ts +24 -0
  244. package/node_modules/type-fest/source/includes.d.ts +22 -0
  245. package/node_modules/type-fest/source/int-closed-range.d.ts +35 -0
  246. package/node_modules/type-fest/source/int-range.d.ts +55 -0
  247. package/node_modules/type-fest/source/internal/array.d.ts +126 -0
  248. package/node_modules/type-fest/source/internal/characters.d.ts +67 -0
  249. package/node_modules/type-fest/source/internal/index.d.ts +8 -0
  250. package/node_modules/type-fest/source/internal/keys.d.ts +97 -0
  251. package/node_modules/type-fest/source/internal/numeric.d.ts +118 -0
  252. package/node_modules/type-fest/source/internal/object.d.ts +236 -0
  253. package/node_modules/type-fest/source/internal/string.d.ts +210 -0
  254. package/node_modules/type-fest/source/internal/tuple.d.ts +90 -0
  255. package/node_modules/type-fest/source/internal/type.d.ts +139 -0
  256. package/node_modules/type-fest/source/invariant-of.d.ts +76 -0
  257. package/node_modules/type-fest/source/is-any.d.ts +33 -0
  258. package/node_modules/type-fest/source/is-equal.d.ts +31 -0
  259. package/node_modules/type-fest/source/is-float.d.ts +41 -0
  260. package/node_modules/type-fest/source/is-integer.d.ts +58 -0
  261. package/node_modules/type-fest/source/is-literal.d.ts +296 -0
  262. package/node_modules/type-fest/source/is-never.d.ts +42 -0
  263. package/node_modules/type-fest/source/is-null.d.ts +20 -0
  264. package/node_modules/type-fest/source/is-tuple.d.ts +89 -0
  265. package/node_modules/type-fest/source/is-unknown.d.ts +52 -0
  266. package/node_modules/type-fest/source/iterable-element.d.ts +64 -0
  267. package/node_modules/type-fest/source/join.d.ts +68 -0
  268. package/node_modules/type-fest/source/jsonifiable.d.ts +37 -0
  269. package/node_modules/type-fest/source/jsonify.d.ts +122 -0
  270. package/node_modules/type-fest/source/kebab-case.d.ts +44 -0
  271. package/node_modules/type-fest/source/kebab-cased-properties-deep.d.ts +63 -0
  272. package/node_modules/type-fest/source/kebab-cased-properties.d.ts +40 -0
  273. package/node_modules/type-fest/source/keys-of-union.d.ts +42 -0
  274. package/node_modules/type-fest/source/last-array-element.d.ts +38 -0
  275. package/node_modules/type-fest/source/less-than-or-equal.d.ts +22 -0
  276. package/node_modules/type-fest/source/less-than.d.ts +26 -0
  277. package/node_modules/type-fest/source/literal-to-primitive-deep.d.ts +36 -0
  278. package/node_modules/type-fest/source/literal-to-primitive.d.ts +36 -0
  279. package/node_modules/type-fest/source/literal-union.d.ts +37 -0
  280. package/node_modules/type-fest/source/merge-deep.d.ts +486 -0
  281. package/node_modules/type-fest/source/merge-exclusive.d.ts +41 -0
  282. package/node_modules/type-fest/source/merge.d.ts +48 -0
  283. package/node_modules/type-fest/source/multidimensional-array.d.ts +44 -0
  284. package/node_modules/type-fest/source/multidimensional-readonly-array.d.ts +48 -0
  285. package/node_modules/type-fest/source/non-empty-object.d.ts +35 -0
  286. package/node_modules/type-fest/source/non-empty-string.d.ts +28 -0
  287. package/node_modules/type-fest/source/non-empty-tuple.d.ts +21 -0
  288. package/node_modules/type-fest/source/numeric.d.ts +222 -0
  289. package/node_modules/type-fest/source/observable-like.d.ts +63 -0
  290. package/node_modules/type-fest/source/omit-deep.d.ts +167 -0
  291. package/node_modules/type-fest/source/omit-index-signature.d.ts +95 -0
  292. package/node_modules/type-fest/source/opaque.d.ts +1 -0
  293. package/node_modules/type-fest/source/optional-keys-of.d.ts +39 -0
  294. package/node_modules/type-fest/source/or.d.ts +25 -0
  295. package/node_modules/type-fest/source/override-properties.d.ts +36 -0
  296. package/node_modules/type-fest/source/package-json.d.ts +676 -0
  297. package/node_modules/type-fest/source/partial-deep.d.ts +151 -0
  298. package/node_modules/type-fest/source/partial-on-undefined-deep.d.ts +78 -0
  299. package/node_modules/type-fest/source/pascal-case.d.ts +42 -0
  300. package/node_modules/type-fest/source/pascal-cased-properties-deep.d.ts +62 -0
  301. package/node_modules/type-fest/source/pascal-cased-properties.d.ts +36 -0
  302. package/node_modules/type-fest/source/paths.d.ts +262 -0
  303. package/node_modules/type-fest/source/pick-deep.d.ts +149 -0
  304. package/node_modules/type-fest/source/pick-index-signature.d.ts +50 -0
  305. package/node_modules/type-fest/source/primitive.d.ts +13 -0
  306. package/node_modules/type-fest/source/promisable.d.ts +25 -0
  307. package/node_modules/type-fest/source/readonly-deep.d.ts +81 -0
  308. package/node_modules/type-fest/source/readonly-keys-of.d.ts +30 -0
  309. package/node_modules/type-fest/source/readonly-tuple.d.ts +41 -0
  310. package/node_modules/type-fest/source/replace.d.ts +85 -0
  311. package/node_modules/type-fest/source/require-all-or-none.d.ts +51 -0
  312. package/node_modules/type-fest/source/require-at-least-one.d.ts +47 -0
  313. package/node_modules/type-fest/source/require-exactly-one.d.ts +45 -0
  314. package/node_modules/type-fest/source/require-one-or-none.d.ts +46 -0
  315. package/node_modules/type-fest/source/required-deep.d.ts +78 -0
  316. package/node_modules/type-fest/source/required-keys-of.d.ts +30 -0
  317. package/node_modules/type-fest/source/schema.d.ts +114 -0
  318. package/node_modules/type-fest/source/screaming-snake-case.d.ts +28 -0
  319. package/node_modules/type-fest/source/set-field-type.d.ts +65 -0
  320. package/node_modules/type-fest/source/set-non-nullable-deep.d.ts +83 -0
  321. package/node_modules/type-fest/source/set-non-nullable.d.ts +39 -0
  322. package/node_modules/type-fest/source/set-optional.d.ts +38 -0
  323. package/node_modules/type-fest/source/set-parameter-type.d.ts +117 -0
  324. package/node_modules/type-fest/source/set-readonly.d.ts +39 -0
  325. package/node_modules/type-fest/source/set-required-deep.d.ts +68 -0
  326. package/node_modules/type-fest/source/set-required.d.ts +70 -0
  327. package/node_modules/type-fest/source/set-return-type.d.ts +29 -0
  328. package/node_modules/type-fest/source/shared-union-fields-deep.d.ts +178 -0
  329. package/node_modules/type-fest/source/shared-union-fields.d.ts +76 -0
  330. package/node_modules/type-fest/source/simplify-deep.d.ts +115 -0
  331. package/node_modules/type-fest/source/simplify.d.ts +58 -0
  332. package/node_modules/type-fest/source/single-key-object.d.ts +29 -0
  333. package/node_modules/type-fest/source/snake-case.d.ts +45 -0
  334. package/node_modules/type-fest/source/snake-cased-properties-deep.d.ts +63 -0
  335. package/node_modules/type-fest/source/snake-cased-properties.d.ts +40 -0
  336. package/node_modules/type-fest/source/split.d.ts +88 -0
  337. package/node_modules/type-fest/source/spread.d.ts +84 -0
  338. package/node_modules/type-fest/source/string-key-of.d.ts +25 -0
  339. package/node_modules/type-fest/source/string-repeat.d.ts +47 -0
  340. package/node_modules/type-fest/source/string-slice.d.ts +37 -0
  341. package/node_modules/type-fest/source/stringified.d.ts +23 -0
  342. package/node_modules/type-fest/source/structured-cloneable.d.ts +92 -0
  343. package/node_modules/type-fest/source/subtract.d.ts +83 -0
  344. package/node_modules/type-fest/source/sum.d.ts +78 -0
  345. package/node_modules/type-fest/source/tagged-union.d.ts +51 -0
  346. package/node_modules/type-fest/source/tagged.d.ts +256 -0
  347. package/node_modules/type-fest/source/trim.d.ts +27 -0
  348. package/node_modules/type-fest/source/tsconfig-json.d.ts +1294 -0
  349. package/node_modules/type-fest/source/tuple-to-object.d.ts +42 -0
  350. package/node_modules/type-fest/source/tuple-to-union.d.ts +51 -0
  351. package/node_modules/type-fest/source/typed-array.d.ts +17 -0
  352. package/node_modules/type-fest/source/undefined-on-partial-deep.d.ts +80 -0
  353. package/node_modules/type-fest/source/union-to-intersection.d.ts +61 -0
  354. package/node_modules/type-fest/source/union-to-tuple.d.ts +56 -0
  355. package/node_modules/type-fest/source/unknown-array.d.ts +25 -0
  356. package/node_modules/type-fest/source/unknown-map.d.ts +24 -0
  357. package/node_modules/type-fest/source/unknown-record.d.ts +31 -0
  358. package/node_modules/type-fest/source/unknown-set.d.ts +24 -0
  359. package/node_modules/type-fest/source/value-of.d.ts +42 -0
  360. package/node_modules/type-fest/source/words.d.ts +118 -0
  361. package/node_modules/type-fest/source/writable-deep.d.ts +83 -0
  362. package/node_modules/type-fest/source/writable-keys-of.d.ts +33 -0
  363. package/node_modules/type-fest/source/writable.d.ts +68 -0
  364. package/node_modules/widest-line/index.d.ts +12 -0
  365. package/node_modules/widest-line/index.js +11 -0
  366. package/node_modules/widest-line/license +9 -0
  367. package/node_modules/widest-line/package.json +60 -0
  368. package/node_modules/widest-line/readme.md +26 -0
  369. package/node_modules/wrap-ansi/index.d.ts +41 -0
  370. package/node_modules/wrap-ansi/index.js +222 -0
  371. package/node_modules/wrap-ansi/license +9 -0
  372. package/node_modules/wrap-ansi/package.json +69 -0
  373. package/node_modules/wrap-ansi/readme.md +75 -0
  374. package/package.json +78 -0
  375. package/scripts/postinstall.cjs +122 -0
@@ -0,0 +1,76 @@
1
+ declare const invariantBrand: unique symbol;
2
+
3
+ /**
4
+ Create an [invariant type](https://basarat.gitbook.io/typescript/type-system/type-compatibility#footnote-invariance), which is a type that does not accept supertypes and subtypes.
5
+
6
+ Use-case:
7
+ - Prevent runtime errors that may occur due to assigning subtypes to supertypes.
8
+ - Improve type signature of object methods like [`Object.keys()` or `Object.entries()`](https://github.com/microsoft/TypeScript/pull/12253#issuecomment-263132208) by sealing the object type.
9
+
10
+ @example
11
+ ```
12
+ import type {InvariantOf} from 'type-fest';
13
+
14
+ class Animal {
15
+ constructor(public name: string){}
16
+ }
17
+
18
+ class Cat extends Animal {
19
+ meow() {}
20
+ }
21
+
22
+ let animalArray: Animal[] = [animal];
23
+ let catArray: Cat[] = [cat];
24
+
25
+ animalArray = catArray; // Okay if covariant
26
+ animalArray.push(new Animal('another animal')); // Pushed an animal into catArray
27
+ catArray.forEach(c => c.meow()); // Allowed but, error at runtime
28
+
29
+ let invariantAnimalArray: InvariantOf<Animal>[] = [animal] as InvariantOf<Animal>[];
30
+ let invariantCatArray: InvariantOf<Cat>[] = [cat] as InvariantOf<Cat>[];
31
+
32
+ invariantAnimalArray = invariantCatArray; // Error: Type 'InvariantOf<Cat>[]' is not assignable to type 'InvariantOf<Animal>[]'.
33
+ ```
34
+
35
+ @example
36
+ ```
37
+ import type {InvariantOf} from 'type-fest';
38
+
39
+ // In covariance (default)
40
+
41
+ interface FooBar {
42
+ foo: number;
43
+ bar: string
44
+ }
45
+
46
+ interface FooBarBaz extends FooBar {
47
+ baz: boolean
48
+ }
49
+
50
+ declare const fooBar: FooBar
51
+ declare const fooBarBaz: FooBarBaz
52
+
53
+ function keyOfFooBar(fooBar: FooBar) {
54
+ return Object.keys(fooBar) as (keyof FooBar)[]
55
+ }
56
+
57
+ keyOfFooBar(fooBar) //=> (keyof FooBar)[]
58
+ keyOfFooBar(fooBarBaz) //=> (keyof FooBar)[] but, (keyof FooBarBaz)[] at runtime
59
+
60
+ // In invariance
61
+
62
+ export function invariantOf<Type>(value: Type): InvariantOf<Type> {
63
+ return value as InvariantOf<Type>;
64
+ }
65
+
66
+ function keyOfInvariantFooBar(fooBar: InvariantOf<FooBar>) {
67
+ return Object.keys(fooBar) as (keyof FooBar)[]
68
+ }
69
+
70
+ keyOfInvariantFooBar(invariantOf(fooBar)); // (keyof FooBar)[]
71
+ keyOfInvariantFooBar(invariantOf(fooBarBaz)); // Error: Argument of type 'InvariantOf<FooBarBaz>' is not assignable to parameter of type 'InvariantOf<FooBar>'.
72
+ ```
73
+
74
+ @category Type
75
+ */
76
+ export type InvariantOf<Type> = Type & {[invariantBrand]: (_: Type) => Type};
@@ -0,0 +1,33 @@
1
+ // Can eventually be replaced with the built-in once this library supports
2
+ // TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
3
+ type NoInfer<T> = T extends infer U ? U : never;
4
+
5
+ /**
6
+ Returns a boolean for whether the given type is `any`.
7
+
8
+ @link https://stackoverflow.com/a/49928360/1490091
9
+
10
+ Useful in type utilities, such as disallowing `any`s to be passed to a function.
11
+
12
+ @example
13
+ ```
14
+ import type {IsAny} from 'type-fest';
15
+
16
+ const typedObject = {a: 1, b: 2} as const;
17
+ const anyObject: any = {a: 1, b: 2};
18
+
19
+ function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
20
+ return obj[key];
21
+ }
22
+
23
+ const typedA = get(typedObject, 'a');
24
+ //=> 1
25
+
26
+ const anyA = get(anyObject, 'a');
27
+ //=> any
28
+ ```
29
+
30
+ @category Type Guard
31
+ @category Utilities
32
+ */
33
+ export type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
@@ -0,0 +1,31 @@
1
+ /**
2
+ Returns a boolean for whether the two given types are equal.
3
+
4
+ @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
5
+ @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
6
+
7
+ Use-cases:
8
+ - If you want to make a conditional branch based on the result of a comparison of two types.
9
+
10
+ @example
11
+ ```
12
+ import type {IsEqual} from 'type-fest';
13
+
14
+ // This type returns a boolean for whether the given array includes the given item.
15
+ // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
16
+ type Includes<Value extends readonly any[], Item> =
17
+ Value extends readonly [Value[0], ...infer rest]
18
+ ? IsEqual<Value[0], Item> extends true
19
+ ? true
20
+ : Includes<rest, Item>
21
+ : false;
22
+ ```
23
+
24
+ @category Type Guard
25
+ @category Utilities
26
+ */
27
+ export type IsEqual<A, B> =
28
+ (<G>() => G extends A & G | G ? 1 : 2) extends
29
+ (<G>() => G extends B & G | G ? 1 : 2)
30
+ ? true
31
+ : false;
@@ -0,0 +1,41 @@
1
+ /**
2
+ Returns a boolean for whether the given number is a float, like `1.5` or `-1.5`.
3
+
4
+ Use-case:
5
+ - If you want to make a conditional branch based on the result of whether a number is a float or not.
6
+
7
+ @example
8
+ ```
9
+ import type {IsFloat, PositiveInfinity} from "type-fest";
10
+
11
+ type A = IsFloat<1.5>;
12
+ //=> true
13
+
14
+ type B = IsFloat<-1.5>;
15
+ //=> true
16
+
17
+ type C = IsFloat<1e-7>;
18
+ //=> true
19
+
20
+ type D = IsFloat<1.0>;
21
+ //=> false
22
+
23
+ type E = IsFloat<PositiveInfinity>;
24
+ //=> false
25
+
26
+ type F = IsFloat<1.23e+21>;
27
+ //=> false
28
+ ```
29
+
30
+ @category Type Guard
31
+ @category Numeric
32
+ */
33
+ export type IsFloat<T> = T extends number
34
+ ? `${T}` extends `${number}e${infer E extends '-' | '+'}${number}`
35
+ ? E extends '-'
36
+ ? true
37
+ : false
38
+ : `${T}` extends `${number}.${number}`
39
+ ? true
40
+ : false
41
+ : false;
@@ -0,0 +1,58 @@
1
+ import type {Not} from './internal';
2
+ import type {IsFloat} from './is-float';
3
+ import type {PositiveInfinity, NegativeInfinity} from './numeric';
4
+
5
+ /**
6
+ Returns a boolean for whether the given number is an integer, like `-5`, `1.0`, or `100`.
7
+
8
+ Use-case:
9
+ - If you want to make a conditional branch based on the result of whether a number is an integer or not.
10
+
11
+ @example
12
+ ```
13
+ import type {IsInteger, PositiveInfinity} from "type-fest";
14
+
15
+ type A = IsInteger<1>;
16
+ //=> true
17
+
18
+ type B = IsInteger<1.0>;
19
+ //=> true
20
+
21
+ type C = IsInteger<-1>;
22
+ //=> true
23
+
24
+ type D = IsInteger<0b10>;
25
+ //=> true
26
+
27
+ type E = IsInteger<0o10>;
28
+ //=> true
29
+
30
+ type F = IsInteger<0x10>;
31
+ //=> true
32
+
33
+ type G = IsInteger<1.23+21>;
34
+ //=> true
35
+
36
+ type H = IsInteger<1.5>;
37
+ //=> false
38
+
39
+ type I = IsInteger<PositiveInfinity>;
40
+ //=> false
41
+
42
+ type J = IsInteger<1e-7>;
43
+ //=> false
44
+ ```
45
+
46
+ @category Type Guard
47
+ @category Numeric
48
+ */
49
+ export type IsInteger<T> =
50
+ T extends bigint
51
+ ? true
52
+ : T extends number
53
+ ? number extends T
54
+ ? false
55
+ : T extends PositiveInfinity | NegativeInfinity
56
+ ? false
57
+ : Not<IsFloat<T>>
58
+ : false;
@@ -0,0 +1,296 @@
1
+ import type {Primitive} from './primitive';
2
+ import type {Numeric} from './numeric';
3
+ import type {IsNotFalse, IsPrimitive} from './internal';
4
+ import type {IsNever} from './is-never';
5
+ import type {IfNever} from './if-never';
6
+
7
+ /**
8
+ Returns a boolean for whether the given type `T` is the specified `LiteralType`.
9
+
10
+ @link https://stackoverflow.com/a/52806744/10292952
11
+
12
+ @example
13
+ ```
14
+ LiteralCheck<1, number>
15
+ //=> true
16
+
17
+ LiteralCheck<number, number>
18
+ //=> false
19
+
20
+ LiteralCheck<1, string>
21
+ //=> false
22
+ ```
23
+ */
24
+ type LiteralCheck<T, LiteralType extends Primitive> = (
25
+ IsNever<T> extends false // Must be wider than `never`
26
+ ? [T] extends [LiteralType & infer U] // Remove any branding
27
+ ? [U] extends [LiteralType] // Must be narrower than `LiteralType`
28
+ ? [LiteralType] extends [U] // Cannot be wider than `LiteralType`
29
+ ? false
30
+ : true
31
+ : false
32
+ : false
33
+ : false
34
+ );
35
+
36
+ /**
37
+ Returns a boolean for whether the given type `T` is one of the specified literal types in `LiteralUnionType`.
38
+
39
+ @example
40
+ ```
41
+ LiteralChecks<1, Numeric>
42
+ //=> true
43
+
44
+ LiteralChecks<1n, Numeric>
45
+ //=> true
46
+
47
+ LiteralChecks<bigint, Numeric>
48
+ //=> false
49
+ ```
50
+ */
51
+ type LiteralChecks<T, LiteralUnionType> = (
52
+ // Conditional type to force union distribution.
53
+ // If `T` is none of the literal types in the union `LiteralUnionType`, then `LiteralCheck<T, LiteralType>` will evaluate to `false` for the whole union.
54
+ // If `T` is one of the literal types in the union, it will evaluate to `boolean` (i.e. `true | false`)
55
+ IsNotFalse<LiteralUnionType extends Primitive
56
+ ? LiteralCheck<T, LiteralUnionType>
57
+ : never
58
+ >
59
+ );
60
+
61
+ /**
62
+ Returns a boolean for whether the given type is a `string` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
63
+
64
+ Useful for:
65
+ - providing strongly-typed string manipulation functions
66
+ - constraining strings to be a string literal
67
+ - type utilities, such as when constructing parsers and ASTs
68
+
69
+ The implementation of this type is inspired by the trick mentioned in this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
70
+
71
+ @example
72
+ ```
73
+ import type {IsStringLiteral} from 'type-fest';
74
+
75
+ type CapitalizedString<T extends string> = IsStringLiteral<T> extends true ? Capitalize<T> : string;
76
+
77
+ // https://github.com/yankeeinlondon/native-dash/blob/master/src/capitalize.ts
78
+ function capitalize<T extends Readonly<string>>(input: T): CapitalizedString<T> {
79
+ return (input.slice(0, 1).toUpperCase() + input.slice(1)) as CapitalizedString<T>;
80
+ }
81
+
82
+ const output = capitalize('hello, world!');
83
+ //=> 'Hello, world!'
84
+ ```
85
+
86
+ @example
87
+ ```
88
+ // String types with infinite set of possible values return `false`.
89
+
90
+ import type {IsStringLiteral} from 'type-fest';
91
+
92
+ type AllUppercaseStrings = IsStringLiteral<Uppercase<string>>;
93
+ //=> false
94
+
95
+ type StringsStartingWithOn = IsStringLiteral<`on${string}`>;
96
+ //=> false
97
+
98
+ // This behaviour is particularly useful in string manipulation utilities, as infinite string types often require separate handling.
99
+
100
+ type Length<S extends string, Counter extends never[] = []> =
101
+ IsStringLiteral<S> extends false
102
+ ? number // return `number` for infinite string types
103
+ : S extends `${string}${infer Tail}`
104
+ ? Length<Tail, [...Counter, never]>
105
+ : Counter['length'];
106
+
107
+ type L1 = Length<Lowercase<string>>;
108
+ //=> number
109
+
110
+ type L2 = Length<`${number}`>;
111
+ //=> number
112
+ ```
113
+
114
+ @category Type Guard
115
+ @category Utilities
116
+ */
117
+ export type IsStringLiteral<T> = IfNever<T, false,
118
+ // If `T` is an infinite string type (e.g., `on${string}`), `Record<T, never>` produces an index signature,
119
+ // and since `{}` extends index signatures, the result becomes `false`.
120
+ T extends string
121
+ ? {} extends Record<T, never>
122
+ ? false
123
+ : true
124
+ : false>;
125
+
126
+ /**
127
+ Returns a boolean for whether the given type is a `number` or `bigint` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
128
+
129
+ Useful for:
130
+ - providing strongly-typed functions when given literal arguments
131
+ - type utilities, such as when constructing parsers and ASTs
132
+
133
+ @example
134
+ ```
135
+ import type {IsNumericLiteral} from 'type-fest';
136
+
137
+ // https://github.com/inocan-group/inferred-types/blob/master/src/types/boolean-logic/EndsWith.ts
138
+ type EndsWith<TValue, TEndsWith extends string> =
139
+ TValue extends string
140
+ ? IsStringLiteral<TEndsWith> extends true
141
+ ? IsStringLiteral<TValue> extends true
142
+ ? TValue extends `${string}${TEndsWith}`
143
+ ? true
144
+ : false
145
+ : boolean
146
+ : boolean
147
+ : TValue extends number
148
+ ? IsNumericLiteral<TValue> extends true
149
+ ? EndsWith<`${TValue}`, TEndsWith>
150
+ : false
151
+ : false;
152
+
153
+ function endsWith<Input extends string | number, End extends string>(input: Input, end: End) {
154
+ return `${input}`.endsWith(end) as EndsWith<Input, End>;
155
+ }
156
+
157
+ endsWith('abc', 'c');
158
+ //=> true
159
+
160
+ endsWith(123456, '456');
161
+ //=> true
162
+
163
+ const end = '123' as string;
164
+
165
+ endsWith('abc123', end);
166
+ //=> boolean
167
+ ```
168
+
169
+ @category Type Guard
170
+ @category Utilities
171
+ */
172
+ export type IsNumericLiteral<T> = LiteralChecks<T, Numeric>;
173
+
174
+ /**
175
+ Returns a boolean for whether the given type is a `true` or `false` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
176
+
177
+ Useful for:
178
+ - providing strongly-typed functions when given literal arguments
179
+ - type utilities, such as when constructing parsers and ASTs
180
+
181
+ @example
182
+ ```
183
+ import type {IsBooleanLiteral} from 'type-fest';
184
+
185
+ const id = 123;
186
+
187
+ type GetId<AsString extends boolean> =
188
+ IsBooleanLiteral<AsString> extends true
189
+ ? AsString extends true
190
+ ? `${typeof id}`
191
+ : typeof id
192
+ : number | string;
193
+
194
+ function getId<AsString extends boolean = false>(options?: {asString: AsString}) {
195
+ return (options?.asString ? `${id}` : id) as GetId<AsString>;
196
+ }
197
+
198
+ const numberId = getId();
199
+ //=> 123
200
+
201
+ const stringId = getId({asString: true});
202
+ //=> '123'
203
+
204
+ declare const runtimeBoolean: boolean;
205
+ const eitherId = getId({asString: runtimeBoolean});
206
+ //=> number | string
207
+ ```
208
+
209
+ @category Type Guard
210
+ @category Utilities
211
+ */
212
+ export type IsBooleanLiteral<T> = LiteralCheck<T, boolean>;
213
+
214
+ /**
215
+ Returns a boolean for whether the given type is a `symbol` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
216
+
217
+ Useful for:
218
+ - providing strongly-typed functions when given literal arguments
219
+ - type utilities, such as when constructing parsers and ASTs
220
+
221
+ @example
222
+ ```
223
+ import type {IsSymbolLiteral} from 'type-fest';
224
+
225
+ type Get<Obj extends Record<symbol, number>, Key extends keyof Obj> =
226
+ IsSymbolLiteral<Key> extends true
227
+ ? Obj[Key]
228
+ : number;
229
+
230
+ function get<Obj extends Record<symbol, number>, Key extends keyof Obj>(o: Obj, key: Key) {
231
+ return o[key] as Get<Obj, Key>;
232
+ }
233
+
234
+ const symbolLiteral = Symbol('literal');
235
+ const symbolValue: symbol = Symbol('value');
236
+
237
+ get({[symbolLiteral]: 1} as const, symbolLiteral);
238
+ //=> 1
239
+
240
+ get({[symbolValue]: 1} as const, symbolValue);
241
+ //=> number
242
+ ```
243
+
244
+ @category Type Guard
245
+ @category Utilities
246
+ */
247
+ export type IsSymbolLiteral<T> = LiteralCheck<T, symbol>;
248
+
249
+ /** Helper type for `IsLiteral`. */
250
+ type IsLiteralUnion<T> =
251
+ | IsStringLiteral<T>
252
+ | IsNumericLiteral<T>
253
+ | IsBooleanLiteral<T>
254
+ | IsSymbolLiteral<T>;
255
+
256
+ /**
257
+ Returns a boolean for whether the given type is a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
258
+
259
+ Useful for:
260
+ - providing strongly-typed functions when given literal arguments
261
+ - type utilities, such as when constructing parsers and ASTs
262
+
263
+ @example
264
+ ```
265
+ import type {IsLiteral} from 'type-fest';
266
+
267
+ // https://github.com/inocan-group/inferred-types/blob/master/src/types/string-literals/StripLeading.ts
268
+ export type StripLeading<A, B> =
269
+ A extends string
270
+ ? B extends string
271
+ ? IsLiteral<A> extends true
272
+ ? string extends B ? never : A extends `${B & string}${infer After}` ? After : A
273
+ : string
274
+ : A
275
+ : A;
276
+
277
+ function stripLeading<Input extends string, Strip extends string>(input: Input, strip: Strip) {
278
+ return input.replace(`^${strip}`, '') as StripLeading<Input, Strip>;
279
+ }
280
+
281
+ stripLeading('abc123', 'abc');
282
+ //=> '123'
283
+
284
+ const str = 'abc123' as string;
285
+
286
+ stripLeading(str, 'abc');
287
+ //=> string
288
+ ```
289
+
290
+ @category Type Guard
291
+ @category Utilities
292
+ */
293
+ export type IsLiteral<T> =
294
+ IsPrimitive<T> extends true
295
+ ? IsNotFalse<IsLiteralUnion<T>>
296
+ : false;
@@ -0,0 +1,42 @@
1
+ /**
2
+ Returns a boolean for whether the given type is `never`.
3
+
4
+ @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
5
+ @link https://stackoverflow.com/a/53984913/10292952
6
+ @link https://www.zhenghao.io/posts/ts-never
7
+
8
+ Useful in type utilities, such as checking if something does not occur.
9
+
10
+ @example
11
+ ```
12
+ import type {IsNever, And} from 'type-fest';
13
+
14
+ // https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
15
+ type AreStringsEqual<A extends string, B extends string> =
16
+ And<
17
+ IsNever<Exclude<A, B>> extends true ? true : false,
18
+ IsNever<Exclude<B, A>> extends true ? true : false
19
+ >;
20
+
21
+ type EndIfEqual<I extends string, O extends string> =
22
+ AreStringsEqual<I, O> extends true
23
+ ? never
24
+ : void;
25
+
26
+ function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
27
+ if (input === output) {
28
+ process.exit(0);
29
+ }
30
+ }
31
+
32
+ endIfEqual('abc', 'abc');
33
+ //=> never
34
+
35
+ endIfEqual('abc', '123');
36
+ //=> void
37
+ ```
38
+
39
+ @category Type Guard
40
+ @category Utilities
41
+ */
42
+ export type IsNever<T> = [T] extends [never] ? true : false;
@@ -0,0 +1,20 @@
1
+ /**
2
+ Returns a boolean for whether the given type is `null`.
3
+
4
+ @example
5
+ ```
6
+ import type {IsNull} from 'type-fest';
7
+
8
+ type NonNullFallback<T, Fallback> = IsNull<T> extends true ? Fallback : T;
9
+
10
+ type Example1 = NonNullFallback<null, string>;
11
+ //=> string
12
+
13
+ type Example2 = NonNullFallback<number, string>;
14
+ //=? number
15
+ ```
16
+
17
+ @category Type Guard
18
+ @category Utilities
19
+ */
20
+ export type IsNull<T> = [T] extends [null] ? true : false;
@@ -0,0 +1,89 @@
1
+ import type {IfAny} from './if-any';
2
+ import type {IfNever} from './if-never';
3
+ import type {ApplyDefaultOptions} from './internal';
4
+ import type {UnknownArray} from './unknown-array';
5
+
6
+ /**
7
+ @see {@link IsTuple}
8
+ */
9
+ export type IsTupleOptions = {
10
+ /**
11
+ Consider only fixed length arrays as tuples.
12
+
13
+ - When set to `true` (default), arrays with rest elements (e.g., `[1, ...number[]]`) are _not_ considered as tuples.
14
+ - When set to `false`, arrays with at least one non-rest element (e.g., `[1, ...number[]]`) are considered as tuples.
15
+
16
+ @default true
17
+
18
+ @example
19
+ ```ts
20
+ import type {IsTuple} from 'type-fest';
21
+
22
+ type Example1 = IsTuple<[number, ...number[]], {fixedLengthOnly: true}>;
23
+ //=> false
24
+
25
+ type Example2 = IsTuple<[number, ...number[]], {fixedLengthOnly: false}>;
26
+ //=> true
27
+ ```
28
+ */
29
+ fixedLengthOnly?: boolean;
30
+ };
31
+
32
+ type DefaultIsTupleOptions = {
33
+ fixedLengthOnly: true;
34
+ };
35
+
36
+ /**
37
+ Returns a boolean for whether the given array is a tuple.
38
+
39
+ Use-case:
40
+ - If you want to make a conditional branch based on the result of whether an array is a tuple or not.
41
+
42
+ Note: `IsTuple` returns `boolean` when instantiated with a union of tuple and non-tuple (e.g., `IsTuple<[1, 2] | number[]>`).
43
+
44
+ @example
45
+ ```ts
46
+ import type {IsTuple} from 'type-fest';
47
+
48
+ type Tuple = IsTuple<[1, 2, 3]>;
49
+ //=> true
50
+
51
+ type NotTuple = IsTuple<number[]>;
52
+ //=> false
53
+
54
+ type TupleWithOptionalItems = IsTuple<[1?, 2?]>;
55
+ //=> true
56
+
57
+ type RestItemsNotAllowed = IsTuple<[1, 2, ...number[]]>;
58
+ //=> false
59
+
60
+ type RestItemsAllowed = IsTuple<[1, 2, ...number[]], {fixedLengthOnly: false}>;
61
+ //=> true
62
+ ```
63
+
64
+ @see {@link IsTupleOptions}
65
+
66
+ @category Type Guard
67
+ @category Utilities
68
+ */
69
+ export type IsTuple<
70
+ TArray extends UnknownArray,
71
+ Options extends IsTupleOptions = {},
72
+ > =
73
+ _IsTuple<TArray, ApplyDefaultOptions<IsTupleOptions, DefaultIsTupleOptions, Options>>;
74
+
75
+ type _IsTuple<
76
+ TArray extends UnknownArray,
77
+ Options extends Required<IsTupleOptions>,
78
+ > =
79
+ IfAny<TArray, boolean, IfNever<TArray, false,
80
+ TArray extends unknown // For distributing `TArray`
81
+ ? number extends TArray['length']
82
+ ? Options['fixedLengthOnly'] extends false
83
+ ? IfNever<keyof TArray & `${number}`,
84
+ TArray extends readonly [...any, any] ? true : false, // To handle cases where a non-rest element follows a rest element, e.g., `[...number[], number]`
85
+ true>
86
+ : false
87
+ : true
88
+ : false
89
+ >>;