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,78 @@
1
+ import type {BuiltIns, HasMultipleCallSignatures} from './internal';
2
+
3
+ type ExcludeUndefined<T> = Exclude<T, undefined>;
4
+
5
+ /**
6
+ Create a type from another type with all keys and nested keys set to required.
7
+
8
+ Use-cases:
9
+ - Creating optional configuration interfaces where the underlying implementation still requires all options to be fully specified.
10
+ - Modeling the resulting type after a deep merge with a set of defaults.
11
+
12
+ @example
13
+ ```
14
+ import type {RequiredDeep} from 'type-fest';
15
+
16
+ type Settings = {
17
+ textEditor?: {
18
+ fontSize?: number | undefined;
19
+ fontColor?: string | undefined;
20
+ fontWeight?: number | undefined;
21
+ }
22
+ autocomplete?: boolean | undefined;
23
+ autosave?: boolean | undefined;
24
+ };
25
+
26
+ type RequiredSettings = RequiredDeep<Settings>;
27
+ // type RequiredSettings = {
28
+ // textEditor: {
29
+ // fontSize: number;
30
+ // fontColor: string;
31
+ // fontWeight: number;
32
+ // }
33
+ // autocomplete: boolean;
34
+ // autosave: boolean;
35
+ // }
36
+ ```
37
+
38
+ Note that types containing overloaded functions are not made deeply required due to a [TypeScript limitation](https://github.com/microsoft/TypeScript/issues/29732).
39
+
40
+ @category Utilities
41
+ @category Object
42
+ @category Array
43
+ @category Set
44
+ @category Map
45
+ */
46
+ export type RequiredDeep<T, E extends ExcludeUndefined<T> = ExcludeUndefined<T>> = E extends BuiltIns
47
+ ? E
48
+ : E extends Map<infer KeyType, infer ValueType>
49
+ ? Map<RequiredDeep<KeyType>, RequiredDeep<ValueType>>
50
+ : E extends Set<infer ItemType>
51
+ ? Set<RequiredDeep<ItemType>>
52
+ : E extends ReadonlyMap<infer KeyType, infer ValueType>
53
+ ? ReadonlyMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>>
54
+ : E extends ReadonlySet<infer ItemType>
55
+ ? ReadonlySet<RequiredDeep<ItemType>>
56
+ : E extends WeakMap<infer KeyType, infer ValueType>
57
+ ? WeakMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>>
58
+ : E extends WeakSet<infer ItemType>
59
+ ? WeakSet<RequiredDeep<ItemType>>
60
+ : E extends Promise<infer ValueType>
61
+ ? Promise<RequiredDeep<ValueType>>
62
+ : E extends (...arguments_: any[]) => unknown
63
+ ? {} extends RequiredObjectDeep<E>
64
+ ? E
65
+ : HasMultipleCallSignatures<E> extends true
66
+ ? E
67
+ : ((...arguments_: Parameters<E>) => ReturnType<E>) & RequiredObjectDeep<E>
68
+ : E extends object
69
+ ? E extends Array<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
70
+ ? ItemType[] extends E // Test for arrays (non-tuples) specifically
71
+ ? Array<RequiredDeep<ItemType>> // Recreate relevant array type to prevent eager evaluation of circular reference
72
+ : RequiredObjectDeep<E> // Tuples behave properly
73
+ : RequiredObjectDeep<E>
74
+ : unknown;
75
+
76
+ type RequiredObjectDeep<ObjectType extends object> = {
77
+ [KeyType in keyof ObjectType]-?: RequiredDeep<ObjectType[KeyType]>
78
+ };
@@ -0,0 +1,30 @@
1
+ import type {OptionalKeysOf} from './optional-keys-of';
2
+
3
+ /**
4
+ Extract all required keys from the given type.
5
+
6
+ This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
7
+
8
+ @example
9
+ ```
10
+ import type {RequiredKeysOf} from 'type-fest';
11
+
12
+ declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
13
+
14
+ interface User {
15
+ name: string;
16
+ surname: string;
17
+
18
+ luckyNumber?: number;
19
+ }
20
+
21
+ const validator1 = createValidation<User>('name', value => value.length < 25);
22
+ const validator2 = createValidation<User>('surname', value => value.length < 25);
23
+ ```
24
+
25
+ @category Utilities
26
+ */
27
+ export type RequiredKeysOf<BaseType extends object> =
28
+ BaseType extends unknown // For distributing `BaseType`
29
+ ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>>
30
+ : never; // Should never happen
@@ -0,0 +1,114 @@
1
+ /**
2
+ Create a deep version of another object type where property values are recursively replaced into a given value type.
3
+
4
+ Use-cases:
5
+ - Form validation: Define how each field should be validated.
6
+ - Form settings: Define configuration for input fields.
7
+ - Parsing: Define types that specify special behavior for specific fields.
8
+
9
+ @example
10
+ ```
11
+ import type {Schema} from 'type-fest';
12
+
13
+ interface User {
14
+ id: string;
15
+ name: {
16
+ firstname: string;
17
+ lastname: string;
18
+ };
19
+ created: Date;
20
+ active: boolean;
21
+ passwordHash: string;
22
+ attributes: ['Foo', 'Bar']
23
+ }
24
+
25
+ type UserMask = Schema<User, 'mask' | 'hide' | 'show'>;
26
+
27
+ const userMaskSettings: UserMask = {
28
+ id: 'show',
29
+ name: {
30
+ firstname: 'show',
31
+ lastname: 'mask',
32
+ },
33
+ created: 'show',
34
+ active: 'show',
35
+ passwordHash: 'hide',
36
+ attributes: ['mask', 'show']
37
+ }
38
+ ```
39
+
40
+ @category Object
41
+ */
42
+ export type Schema<ObjectType, ValueType, Options extends SchemaOptions = {}> = ObjectType extends string
43
+ ? ValueType
44
+ : ObjectType extends Map<unknown, unknown>
45
+ ? ValueType
46
+ : ObjectType extends Set<unknown>
47
+ ? ValueType
48
+ : ObjectType extends ReadonlyMap<unknown, unknown>
49
+ ? ValueType
50
+ : ObjectType extends ReadonlySet<unknown>
51
+ ? ValueType
52
+ : ObjectType extends Array<infer U>
53
+ ? Options['recurseIntoArrays'] extends false | undefined
54
+ ? ValueType
55
+ : Array<Schema<U, ValueType>>
56
+ : ObjectType extends (...arguments_: unknown[]) => unknown
57
+ ? ValueType
58
+ : ObjectType extends Date
59
+ ? ValueType
60
+ : ObjectType extends Function
61
+ ? ValueType
62
+ : ObjectType extends RegExp
63
+ ? ValueType
64
+ : ObjectType extends object
65
+ ? SchemaObject<ObjectType, ValueType, Options>
66
+ : ValueType;
67
+
68
+ /**
69
+ Same as `Schema`, but accepts only `object`s as inputs. Internal helper for `Schema`.
70
+ */
71
+ type SchemaObject<
72
+ ObjectType extends object,
73
+ K,
74
+ Options extends SchemaOptions,
75
+ > = {
76
+ [KeyType in keyof ObjectType]: ObjectType[KeyType] extends
77
+ | readonly unknown[]
78
+ | unknown[]
79
+ ? Options['recurseIntoArrays'] extends false | undefined
80
+ ? K
81
+ : Schema<ObjectType[KeyType], K, Options>
82
+ : Schema<ObjectType[KeyType], K, Options> | K;
83
+ };
84
+
85
+ /**
86
+ @see Schema
87
+ */
88
+ export type SchemaOptions = {
89
+ /**
90
+ By default, this affects elements in array and tuple types. You can change this by passing `{recurseIntoArrays: false}` as the third type argument:
91
+ - If `recurseIntoArrays` is set to `true` (default), array elements will be recursively processed as well.
92
+ - If `recurseIntoArrays` is set to `false`, arrays will not be recursively processed, and the entire array will be replaced with the given value type.
93
+
94
+ @example
95
+ ```
96
+ type UserMask = Schema<User, 'mask' | 'hide' | 'show', {recurseIntoArrays: false}>;
97
+
98
+ const userMaskSettings: UserMask = {
99
+ id: 'show',
100
+ name: {
101
+ firstname: 'show',
102
+ lastname: 'mask',
103
+ },
104
+ created: 'show',
105
+ active: 'show',
106
+ passwordHash: 'hide',
107
+ attributes: 'hide'
108
+ }
109
+ ```
110
+
111
+ @default true
112
+ */
113
+ readonly recurseIntoArrays?: boolean | undefined;
114
+ };
@@ -0,0 +1,28 @@
1
+ import type {DefaultDelimiterCaseOptions} from './delimiter-case';
2
+ import type {ApplyDefaultOptions} from './internal';
3
+ import type {SnakeCase} from './snake-case';
4
+ import type {WordsOptions} from './words';
5
+
6
+ /**
7
+ Convert a string literal to screaming-snake-case.
8
+
9
+ This can be useful when, for example, converting a camel-cased object property to a screaming-snake-cased SQL column name.
10
+
11
+ @example
12
+ ```
13
+ import type {ScreamingSnakeCase} from 'type-fest';
14
+
15
+ const someVariable: ScreamingSnakeCase<'fooBar'> = 'FOO_BAR';
16
+ const someVariableNoSplitOnNumbers: ScreamingSnakeCase<'p2pNetwork', {splitOnNumbers: false}> = 'P2P_NETWORK';
17
+
18
+ ```
19
+
20
+ @category Change case
21
+ @category Template literal
22
+ */
23
+ export type ScreamingSnakeCase<
24
+ Value,
25
+ Options extends WordsOptions = {},
26
+ > = Value extends string
27
+ ? Uppercase<SnakeCase<Value, ApplyDefaultOptions<WordsOptions, DefaultDelimiterCaseOptions, Options>>>
28
+ : Value;
@@ -0,0 +1,65 @@
1
+ import type {ApplyDefaultOptions} from './internal';
2
+ import type {Simplify} from './simplify';
3
+
4
+ type SetFieldTypeOptions = {
5
+ /**
6
+ Preserve optional and readonly modifiers for properties being updated.
7
+
8
+ NOTE: Property modifiers will always be preserved for properties that are not being updated.
9
+
10
+ @default true
11
+ */
12
+ preservePropertyModifiers?: boolean;
13
+ };
14
+
15
+ type DefaultSetFieldTypeOptions = {
16
+ preservePropertyModifiers: true;
17
+ };
18
+
19
+ /**
20
+ Create a type that changes the type of the given keys.
21
+
22
+ Use-cases:
23
+ - Creating variations of a base model.
24
+ - Fixing incorrect external types.
25
+
26
+ @see `Merge` if you need to change multiple properties to different types.
27
+
28
+ @example
29
+ ```
30
+ import type {SetFieldType} from 'type-fest';
31
+
32
+ type MyModel = {
33
+ readonly id: number;
34
+ readonly createdAt: Date;
35
+ updatedAt?: Date;
36
+ };
37
+
38
+ type MyModelApi = SetFieldType<MyModel, 'createdAt' | 'updatedAt', string>;
39
+ // {
40
+ // readonly id: number;
41
+ // readonly createdAt: string;
42
+ // updatedAt?: string;
43
+ // }
44
+
45
+ // `preservePropertyModifiers` option can be set to `false` if you want to remove property modifiers for properties being updated
46
+ type MyModelApi = SetFieldType<MyModel, 'createdAt' | 'updatedAt', string, {preservePropertyModifiers: false}>;
47
+ // {
48
+ // readonly id: number;
49
+ // createdAt: string; // no longer readonly
50
+ // updatedAt: string; // no longer optional
51
+ // }
52
+ ```
53
+
54
+ @category Object
55
+ */
56
+ export type SetFieldType<BaseType, Keys extends keyof BaseType, NewType, Options extends SetFieldTypeOptions = {}> =
57
+ _SetFieldType<BaseType, Keys, NewType, ApplyDefaultOptions<SetFieldTypeOptions, DefaultSetFieldTypeOptions, Options>>;
58
+
59
+ type _SetFieldType<BaseType, Keys extends keyof BaseType, NewType, Options extends Required<SetFieldTypeOptions>> =
60
+ Simplify<{
61
+ [P in keyof BaseType]: P extends Keys ? NewType : BaseType[P];
62
+ } & (
63
+ // `Record` is used to remove property modifiers
64
+ Options['preservePropertyModifiers'] extends false ? Record<Keys, NewType> : unknown
65
+ )>;
@@ -0,0 +1,83 @@
1
+ import type {NonRecursiveType, StringToNumber} from './internal';
2
+ import type {Paths} from './paths';
3
+ import type {SetNonNullable} from './set-non-nullable';
4
+ import type {Simplify} from './simplify';
5
+ import type {UnionToTuple} from './union-to-tuple';
6
+ import type {UnknownArray} from './unknown-array';
7
+
8
+ /**
9
+ Create a type that makes the specified keys non-nullable (removes `null` and `undefined`), supports deeply nested key paths, and leaves all other keys unchanged.
10
+
11
+ NOTE: Optional modifiers (`?`) are not removed from properties. For example, `SetNonNullableDeep<{foo?: string | null | undefined}, 'foo'>` will result in `{foo?: string}`.
12
+
13
+ @example
14
+ ```
15
+ import type {SetNonNullableDeep} from 'type-fest';
16
+
17
+ type User = {
18
+ name: string;
19
+ address: {
20
+ city: string | undefined;
21
+ street?: string | null;
22
+ };
23
+ contact: {
24
+ email?: string | null | undefined;
25
+ phone: string | undefined;
26
+ };
27
+ };
28
+
29
+ type UpdatedUser = SetNonNullableDeep<User, 'address.street' | 'contact.email' | 'contact.phone'>;
30
+ //=> {
31
+ // name: string;
32
+ // address: {
33
+ // city: string | undefined;
34
+ // street?: string;
35
+ // };
36
+ // contact: {
37
+ // email?: string;
38
+ // phone: string;
39
+ // };
40
+ // };
41
+ ```
42
+
43
+ @example
44
+ ```
45
+ import type {SetNonNullableDeep} from 'type-fest';
46
+
47
+ // Set specific indices in an array to be non-nullable.
48
+ type ArrayExample1 = SetNonNullableDeep<{a: [number | null, number | null, number | undefined]}, 'a.1' | 'a.2'>;
49
+ //=> {a: [number | null, number, number]}
50
+
51
+ // Optional modifier (`?`) is not removed.
52
+ type ArrayExample2 = SetNonNullableDeep<{a: [(number | null)?, (number | null)?]}, 'a.1'>;
53
+ //=> {a: [(number | null)?, number?]}
54
+ ```
55
+
56
+ @category Object
57
+ */
58
+ export type SetNonNullableDeep<BaseType, KeyPaths extends Paths<BaseType>> =
59
+ SetNonNullableDeepHelper<BaseType, UnionToTuple<KeyPaths>>;
60
+
61
+ /**
62
+ Internal helper for {@link SetNonNullableDeep}.
63
+
64
+ Recursively transforms the `BaseType` by applying {@link SetNonNullableDeepSinglePath} for each path in `KeyPathsTuple`.
65
+ */
66
+ type SetNonNullableDeepHelper<BaseType, KeyPathsTuple extends UnknownArray> =
67
+ KeyPathsTuple extends [infer KeyPath, ...infer RestPaths]
68
+ ? SetNonNullableDeepHelper<SetNonNullableDeepSinglePath<BaseType, KeyPath>, RestPaths>
69
+ : BaseType;
70
+
71
+ /**
72
+ Makes a single path non-nullable in `BaseType`.
73
+ */
74
+ type SetNonNullableDeepSinglePath<BaseType, KeyPath> =
75
+ BaseType extends NonRecursiveType | ReadonlySet<unknown> | ReadonlyMap<unknown, unknown> // Also distributes `BaseType`
76
+ ? BaseType
77
+ : KeyPath extends `${infer Property}.${infer RestPath}`
78
+ ? {
79
+ [Key in keyof BaseType]: Property extends `${Key & (string | number)}`
80
+ ? SetNonNullableDeepSinglePath<BaseType[Key], RestPath>
81
+ : BaseType[Key];
82
+ }
83
+ : Simplify<SetNonNullable<BaseType, (KeyPath | StringToNumber<KeyPath & string>) & keyof BaseType>>;
@@ -0,0 +1,39 @@
1
+ /**
2
+ Create a type that makes the given keys non-nullable, where the remaining keys are kept as is.
3
+
4
+ If no keys are given, all keys will be made non-nullable.
5
+
6
+ Use-case: You want to define a single model where the only thing that changes is whether or not some or all of the keys are non-nullable.
7
+
8
+ @example
9
+ ```
10
+ import type {SetNonNullable} from 'type-fest';
11
+
12
+ type Foo = {
13
+ a: number | null;
14
+ b: string | undefined;
15
+ c?: boolean | null;
16
+ }
17
+
18
+ type SomeNonNullable = SetNonNullable<Foo, 'b' | 'c'>;
19
+ // type SomeNonNullable = {
20
+ // a: number | null;
21
+ // b: string; // Can no longer be undefined.
22
+ // c?: boolean; // Can no longer be null, but is still optional.
23
+ // }
24
+
25
+ type AllNonNullable = SetNonNullable<Foo>;
26
+ // type AllNonNullable = {
27
+ // a: number; // Can no longer be null.
28
+ // b: string; // Can no longer be undefined.
29
+ // c?: boolean; // Can no longer be null, but is still optional.
30
+ // }
31
+ ```
32
+
33
+ @category Object
34
+ */
35
+ export type SetNonNullable<BaseType, Keys extends keyof BaseType = keyof BaseType> = {
36
+ [Key in keyof BaseType]: Key extends Keys
37
+ ? NonNullable<BaseType[Key]>
38
+ : BaseType[Key];
39
+ };
@@ -0,0 +1,38 @@
1
+ import type {Except} from './except';
2
+ import type {HomomorphicPick} from './internal';
3
+ import type {Simplify} from './simplify';
4
+
5
+ /**
6
+ Create a type that makes the given keys optional. The remaining keys are kept as is. The sister of the `SetRequired` type.
7
+
8
+ Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are optional.
9
+
10
+ @example
11
+ ```
12
+ import type {SetOptional} from 'type-fest';
13
+
14
+ type Foo = {
15
+ a: number;
16
+ b?: string;
17
+ c: boolean;
18
+ }
19
+
20
+ type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
21
+ // type SomeOptional = {
22
+ // a: number;
23
+ // b?: string; // Was already optional and still is.
24
+ // c?: boolean; // Is now optional.
25
+ // }
26
+ ```
27
+
28
+ @category Object
29
+ */
30
+ export type SetOptional<BaseType, Keys extends keyof BaseType> =
31
+ BaseType extends unknown // To distribute `BaseType` when it's a union type.
32
+ ? Simplify<
33
+ // Pick just the keys that are readonly from the base type.
34
+ Except<BaseType, Keys> &
35
+ // Pick the keys that should be mutable from the base type and make them mutable.
36
+ Partial<HomomorphicPick<BaseType, Keys>>
37
+ >
38
+ : never;
@@ -0,0 +1,117 @@
1
+ import type {IsUnknown} from './is-unknown';
2
+ import type {StaticPartOfArray, VariablePartOfArray} from './internal';
3
+ import type {UnknownArray} from './unknown-array';
4
+
5
+ /**
6
+ Create an array that replaces the given `TArray`'s elements with the given `TObject`'s values at the given indices.
7
+
8
+ `TArray` and `TObject` supports tailing spread array like `[string, ...boolean[]]`, but does not support `[string, ...boolean[], number]`.
9
+
10
+ @example:
11
+ ```ts
12
+ // object
13
+ type A = MergeObjectToArray<[string, number], {0: boolean}>;
14
+ //=> [boolean, number]
15
+
16
+ // array
17
+ type B = MergeObjectToArray<[string, number], [boolean]>;
18
+ //=> [boolean, number]
19
+
20
+ // tailing spread array
21
+ type C = MergeObjectToArray<[string, ...boolean[]], {1: number}>;
22
+ //=> [string, ...number[]]
23
+
24
+ type D = MergeObjectToArray<[string, ...boolean[]], [number, ...string[]]>;
25
+ //=> [number, ...string[]]
26
+ ```
27
+ */
28
+ type MergeObjectToArray<TArray extends UnknownArray, TObject, TArrayCopy extends UnknownArray = TArray> =
29
+ // If `TObject` is an array like `[0, 1, 2]`
30
+ TObject extends UnknownArray
31
+ // If `TObject` is a variable length array, we should use `TObject`'s type as the result type.
32
+ ? number extends TObject['length']
33
+ ? TObject
34
+ : {
35
+ [K in keyof TArray]:
36
+ number extends K
37
+ ? VariablePartOfArray<TArray>[number]
38
+ : K extends keyof TObject ? TObject[K] : TArray[K]
39
+ }
40
+ : TObject extends object
41
+ // If `TObject` is a object witch key is number like `{0: string, 1: number}`
42
+ ? {
43
+ [K in keyof TArray]:
44
+ K extends `${infer NumberK extends number}`
45
+ ? NumberK extends keyof TObject ? TObject[NumberK] : TArray[K]
46
+ : number extends K
47
+ // If array key `K` is `number`, means it's a rest parameter, we should set the rest parameter type to corresponding type in `TObject`.
48
+ // example: `MergeObjectToParamterArray<[string, ...boolean[]], {1: number}>` => `[string, ...number[]]`
49
+ ? StaticPartOfArray<TArrayCopy>['length'] extends keyof TObject
50
+ ? TObject[StaticPartOfArray<TArrayCopy>['length']]
51
+ : TArray[K]
52
+ : never
53
+ } : never;
54
+
55
+ /**
56
+ Create a function that replaces some parameters with the given parameters.
57
+
58
+ The parameters that are not specified will be kept as-is.
59
+
60
+ Note:
61
+ - This type will ignore the given function's generic type.
62
+ - If you change the parameter type that return type depends on, the return type will not change:
63
+ ```
64
+ const fn = (a: number) => a;
65
+ //=> fn: (a: number) => number;
66
+
67
+ // We change type of `a` to `string`, but return type is still `number`.
68
+ type Fn = SetParameterType<typeof fn, {0: string}>;
69
+ //=> (a: string) => number;
70
+ ```
71
+
72
+ Use-case:
73
+ - Define a wrapped function that receives something different while returning the same type.
74
+ - Mocking and testing.
75
+ - Overload function type. (See example)
76
+
77
+ @example
78
+ ```
79
+ import type {SetParameterType} from 'type-fest';
80
+
81
+ type HandleMessage = (data: Data, message: string, ...arguments: any[]) => void;
82
+
83
+ type HandleOk = SetParameterType<HandleMessage, {0: SuccessData, 1: 'ok'}>;
84
+ //=> type HandleOk = (data: SuccessData, message: 'ok') => void;
85
+
86
+ // Another way to define the parameters to replace.
87
+ type HandleError = SetParameterType<HandleMessage, [data: ErrorData, message: 'error']>;
88
+ //=> type HandleError = (data: ErrorData, message: 'error') => void;
89
+
90
+ // Change single parameter type.
91
+ type HandleWarn = SetParameterType<HandleMessage, {1: 'warn'}>;
92
+ //=> type HandleWarn = (data: Data, message: 'warn') => void;
93
+
94
+ // Change rest parameter type.
95
+
96
+ // Way 1: Input full parameter type.
97
+ type HandleLog = SetParameterType<HandleMessage, [data: Data, message: 'log', ...arguments: string[]]>;
98
+ //=> type HandleLog = (data: Data, message: 'log', ...arguments: string[]) => void;
99
+
100
+ // Way 2: Input rest parameter type by Object index.
101
+ type HandleLog2 = SetParameterType<HandleMessage, {2: string}>;
102
+ //=> type HandleLog2 = (data: Data, message: string, ...arguments: string[]) => void;
103
+ ```
104
+
105
+ @category Function
106
+ */
107
+ export type SetParameterType<Function_ extends (...arguments_: any[]) => unknown, P extends Record<number, unknown>> =
108
+ // Just using `Parameters<Fn>` isn't ideal because it doesn't handle the `this` fake parameter.
109
+ Function_ extends (this: infer ThisArgument, ...arguments_: infer Arguments) => unknown
110
+ ? (
111
+ // If a function did not specify the `this` fake parameter, it will be inferred to `unknown`.
112
+ // We want to detect this situation just to display a friendlier type upon hovering on an IntelliSense-powered IDE.
113
+ IsUnknown<ThisArgument> extends true
114
+ ? (...arguments_: MergeObjectToArray<Arguments, P>) => ReturnType<Function_>
115
+ : (this: ThisArgument, ...arguments_: MergeObjectToArray<Arguments, P>) => ReturnType<Function_>
116
+ )
117
+ : Function_; // This part should be unreachable
@@ -0,0 +1,39 @@
1
+ import type {Except} from './except';
2
+ import type {HomomorphicPick} from './internal';
3
+ import type {Simplify} from './simplify';
4
+
5
+ /**
6
+ Create a type that makes the given keys readonly. The remaining keys are kept as is.
7
+
8
+ Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are readonly.
9
+
10
+ @example
11
+ ```
12
+ import type {SetReadonly} from 'type-fest';
13
+
14
+ type Foo = {
15
+ a: number;
16
+ readonly b: string;
17
+ c: boolean;
18
+ }
19
+
20
+ type SomeReadonly = SetReadonly<Foo, 'b' | 'c'>;
21
+ // type SomeReadonly = {
22
+ // a: number;
23
+ // readonly b: string; // Was already readonly and still is.
24
+ // readonly c: boolean; // Is now readonly.
25
+ // }
26
+ ```
27
+
28
+ @category Object
29
+ */
30
+ export type SetReadonly<BaseType, Keys extends keyof BaseType> =
31
+ // `extends unknown` is always going to be the case and is used to convert any
32
+ // union into a [distributive conditional
33
+ // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
34
+ BaseType extends unknown
35
+ ? Simplify<
36
+ Except<BaseType, Keys> &
37
+ Readonly<HomomorphicPick<BaseType, Keys>>
38
+ >
39
+ : never;