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,68 @@
1
+ import type {IsAny} from './is-any';
2
+ import type {NonRecursiveType, StringToNumber} from './internal';
3
+ import type {Paths} from './paths';
4
+ import type {SetRequired} from './set-required';
5
+ import type {SimplifyDeep} from './simplify-deep';
6
+ import type {UnionToTuple} from './union-to-tuple';
7
+ import type {RequiredDeep} from './required-deep';
8
+ import type {UnknownArray} from './unknown-array';
9
+
10
+ /**
11
+ Create a type that makes the given keys required. You can specify deeply nested key paths. The remaining keys are kept as is.
12
+
13
+ Use-case: Selectively make nested properties required in complex types like models.
14
+
15
+ @example
16
+ ```
17
+ import type {SetRequiredDeep} from 'type-fest';
18
+
19
+ type Foo = {
20
+ a?: number;
21
+ b?: string;
22
+ c?: {
23
+ d?: number
24
+ }[]
25
+ }
26
+
27
+ type SomeRequiredDeep = SetRequiredDeep<Foo, 'a' | `c.${number}.d`>;
28
+ // type SomeRequiredDeep = {
29
+ // a: number; // Is now required
30
+ // b?: string;
31
+ // c: {
32
+ // d: number // Is now required
33
+ // }[]
34
+ // }
35
+
36
+ // Set specific indices in an array to be required.
37
+ type ArrayExample = SetRequiredDeep<{a: [number?, number?, number?]}, 'a.0' | 'a.1'>;
38
+ //=> {a: [number, number, number?]}
39
+ ```
40
+
41
+ @category Object
42
+ */
43
+ export type SetRequiredDeep<BaseType, KeyPaths extends Paths<BaseType>> = IsAny<KeyPaths> extends true
44
+ ? SimplifyDeep<RequiredDeep<BaseType>>
45
+ : SetRequiredDeepHelper<BaseType, UnionToTuple<KeyPaths>>;
46
+
47
+ /**
48
+ Internal helper for {@link SetRequiredDeep}.
49
+
50
+ Recursively transforms the `BaseType` by applying {@link SetRequiredDeepSinglePath} for each path in `KeyPathsTuple`.
51
+ */
52
+ type SetRequiredDeepHelper<BaseType, KeyPathsTuple extends UnknownArray> =
53
+ KeyPathsTuple extends [infer KeyPath, ...infer RestPaths]
54
+ ? SetRequiredDeepHelper<SetRequiredDeepSinglePath<BaseType, KeyPath>, RestPaths>
55
+ : BaseType;
56
+
57
+ /**
58
+ Makes a single path required in `BaseType`.
59
+ */
60
+ type SetRequiredDeepSinglePath<BaseType, KeyPath> = BaseType extends NonRecursiveType
61
+ ? BaseType
62
+ : KeyPath extends `${infer Property}.${infer RestPath}`
63
+ ? {
64
+ [Key in keyof BaseType]: Property extends `${Key & (string | number)}`
65
+ ? SetRequiredDeepSinglePath<BaseType[Key], RestPath>
66
+ : BaseType[Key];
67
+ }
68
+ : SetRequired<BaseType, (KeyPath | StringToNumber<KeyPath & string>) & keyof BaseType>;
@@ -0,0 +1,70 @@
1
+ import type {Except} from './except';
2
+ import type {HomomorphicPick, IfArrayReadonly} from './internal';
3
+ import type {OptionalKeysOf} from './optional-keys-of';
4
+ import type {Simplify} from './simplify';
5
+ import type {UnknownArray} from './unknown-array';
6
+
7
+ /**
8
+ Create a type that makes the given keys required. The remaining keys are kept as is. The sister of the `SetOptional` type.
9
+
10
+ Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are required.
11
+
12
+ @example
13
+ ```
14
+ import type {SetRequired} from 'type-fest';
15
+
16
+ type Foo = {
17
+ a?: number;
18
+ b: string;
19
+ c?: boolean;
20
+ }
21
+
22
+ type SomeRequired = SetRequired<Foo, 'b' | 'c'>;
23
+ // type SomeRequired = {
24
+ // a?: number;
25
+ // b: string; // Was already required and still is.
26
+ // c: boolean; // Is now required.
27
+ // }
28
+
29
+ // Set specific indices in an array to be required.
30
+ type ArrayExample = SetRequired<[number?, number?, number?], 0 | 1>;
31
+ //=> [number, number, number?]
32
+ ```
33
+
34
+ @category Object
35
+ */
36
+ export type SetRequired<BaseType, Keys extends keyof BaseType> =
37
+ BaseType extends UnknownArray
38
+ ? SetArrayRequired<BaseType, Keys> extends infer ResultantArray
39
+ ? IfArrayReadonly<BaseType, Readonly<ResultantArray>, ResultantArray>
40
+ : never
41
+ : Simplify<
42
+ // Pick just the keys that are optional from the base type.
43
+ Except<BaseType, Keys> &
44
+ // Pick the keys that should be required from the base type and make them required.
45
+ Required<HomomorphicPick<BaseType, Keys>>
46
+ >;
47
+
48
+ /**
49
+ Remove the optional modifier from the specified keys in an array.
50
+ */
51
+ type SetArrayRequired<
52
+ TArray extends UnknownArray,
53
+ Keys,
54
+ Counter extends any[] = [],
55
+ Accumulator extends UnknownArray = [],
56
+ > = TArray extends unknown // For distributing `TArray` when it's a union
57
+ ? keyof TArray & `${number}` extends never
58
+ // Exit if `TArray` is empty (e.g., []), or
59
+ // `TArray` contains no non-rest elements preceding the rest element (e.g., `[...string[]]` or `[...string[], string]`).
60
+ ? [...Accumulator, ...TArray]
61
+ : TArray extends readonly [(infer First)?, ...infer Rest]
62
+ ? '0' extends OptionalKeysOf<TArray> // If the first element of `TArray` is optional
63
+ ? `${Counter['length']}` extends `${Keys & (string | number)}` // If the current index needs to be required
64
+ ? SetArrayRequired<Rest, Keys, [...Counter, any], [...Accumulator, First]>
65
+ // If the current element is optional, but it doesn't need to be required,
66
+ // then we can exit early, since no further elements can now be made required.
67
+ : [...Accumulator, ...TArray]
68
+ : SetArrayRequired<Rest, Keys, [...Counter, any], [...Accumulator, TArray[0]]>
69
+ : never // Should never happen, since `[(infer F)?, ...infer R]` is a top-type for arrays.
70
+ : never; // Should never happen
@@ -0,0 +1,29 @@
1
+ import type {IsUnknown} from './is-unknown';
2
+
3
+ /**
4
+ Create a function type with a return type of your choice and the same parameters as the given function type.
5
+
6
+ Use-case: You want to define a wrapped function that returns something different while receiving the same parameters. For example, you might want to wrap a function that can throw an error into one that will return `undefined` instead.
7
+
8
+ @example
9
+ ```
10
+ import type {SetReturnType} from 'type-fest';
11
+
12
+ type MyFunctionThatCanThrow = (foo: SomeType, bar: unknown) => SomeOtherType;
13
+
14
+ type MyWrappedFunction = SetReturnType<MyFunctionThatCanThrow, SomeOtherType | undefined>;
15
+ //=> type MyWrappedFunction = (foo: SomeType, bar: unknown) => SomeOtherType | undefined;
16
+ ```
17
+
18
+ @category Function
19
+ */
20
+ export type SetReturnType<Function_ extends (...arguments_: any[]) => any, TypeToReturn> =
21
+ // Just using `Parameters<Fn>` isn't ideal because it doesn't handle the `this` fake parameter.
22
+ Function_ extends (this: infer ThisArgument, ...arguments_: infer Arguments) => any ? (
23
+ // If a function did not specify the `this` fake parameter, it will be inferred to `unknown`.
24
+ // We want to detect this situation just to display a friendlier type upon hovering on an IntelliSense-powered IDE.
25
+ IsUnknown<ThisArgument> extends true ? (...arguments_: Arguments) => TypeToReturn : (this: ThisArgument, ...arguments_: Arguments) => TypeToReturn
26
+ ) : (
27
+ // This part should be unreachable, but we make it meaningful just in case…
28
+ (...arguments_: Parameters<Function_>) => TypeToReturn
29
+ );
@@ -0,0 +1,178 @@
1
+ import type {NonRecursiveType, UnionMin, UnionMax, TupleLength, StaticPartOfArray, VariablePartOfArray, IsArrayReadonly, SetArrayAccess, ApplyDefaultOptions} from './internal';
2
+ import type {IsNever} from './is-never';
3
+ import type {UnknownArray} from './unknown-array';
4
+
5
+ /**
6
+ SharedUnionFieldsDeep options.
7
+
8
+ @see {@link SharedUnionFieldsDeep}
9
+ */
10
+ export type SharedUnionFieldsDeepOptions = {
11
+ /**
12
+ When set to true, this option impacts each element within arrays or tuples. If all union values are arrays or tuples, it constructs an array of the shortest possible length, ensuring every element exists in the union array.
13
+
14
+ @default false
15
+ */
16
+ recurseIntoArrays?: boolean;
17
+ };
18
+
19
+ type DefaultSharedUnionFieldsDeepOptions = {
20
+ recurseIntoArrays: false;
21
+ };
22
+
23
+ /**
24
+ Create a type with shared fields from a union of object types, deeply traversing nested structures.
25
+
26
+ Use the {@link SharedUnionFieldsDeepOptions `Options`} to specify the behavior for arrays.
27
+
28
+ Use-cases:
29
+ - You want a safe object type where each key exists in the union object.
30
+ - You want to focus on the common fields of the union type and don't want to have to care about the other fields.
31
+
32
+ @example
33
+ ```
34
+ import type {SharedUnionFieldsDeep} from 'type-fest';
35
+
36
+ type Cat = {
37
+ info: {
38
+ name: string;
39
+ type: 'cat';
40
+ catType: string;
41
+ };
42
+ };
43
+
44
+ type Dog = {
45
+ info: {
46
+ name: string;
47
+ type: 'dog';
48
+ dogType: string;
49
+ };
50
+ };
51
+
52
+ function displayPetInfo(petInfo: (Cat | Dog)['info']) {
53
+ // typeof petInfo =>
54
+ // {
55
+ // name: string;
56
+ // type: 'cat';
57
+ // catType: string; // Needn't care about this field, because it's not a common pet info field.
58
+ // } | {
59
+ // name: string;
60
+ // type: 'dog';
61
+ // dogType: string; // Needn't care about this field, because it's not a common pet info field.
62
+ // }
63
+
64
+ // petInfo type is complex and have some needless fields
65
+
66
+ console.log('name: ', petInfo.name);
67
+ console.log('type: ', petInfo.type);
68
+ }
69
+
70
+ function displayPetInfo(petInfo: SharedUnionFieldsDeep<Cat | Dog>['info']) {
71
+ // typeof petInfo =>
72
+ // {
73
+ // name: string;
74
+ // type: 'cat' | 'dog';
75
+ // }
76
+
77
+ // petInfo type is simple and clear
78
+
79
+ console.log('name: ', petInfo.name);
80
+ console.log('type: ', petInfo.type);
81
+ }
82
+ ```
83
+
84
+ @see SharedUnionFields
85
+
86
+ @category Object
87
+ @category Union
88
+ */
89
+ export type SharedUnionFieldsDeep<Union, Options extends SharedUnionFieldsDeepOptions = {}> =
90
+ ApplyDefaultOptions<SharedUnionFieldsDeepOptions, DefaultSharedUnionFieldsDeepOptions, Options> extends infer OptionsWithDefaults extends Required<SharedUnionFieldsDeepOptions>
91
+ // `Union extends` will convert `Union`
92
+ // to a [distributive conditionaltype](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
93
+ // But this is not what we want, so we need to wrap `Union` with `[]` to prevent it.
94
+ ? [Union] extends [NonRecursiveType | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown>]
95
+ ? Union
96
+ : [Union] extends [UnknownArray]
97
+ ? OptionsWithDefaults['recurseIntoArrays'] extends true
98
+ ? SetArrayAccess<SharedArrayUnionFieldsDeep<Union, OptionsWithDefaults>, IsArrayReadonly<Union>>
99
+ : Union
100
+ : [Union] extends [object]
101
+ ? SharedObjectUnionFieldsDeep<Union, OptionsWithDefaults>
102
+ : Union
103
+ : never;
104
+
105
+ /**
106
+ Same as `SharedUnionFieldsDeep`, but accepts only `object`s and as inputs. Internal helper for `SharedUnionFieldsDeep`.
107
+ */
108
+ type SharedObjectUnionFieldsDeep<Union, Options extends Required<SharedUnionFieldsDeepOptions>> =
109
+ // `keyof Union` can extract the same key in union type, if there is no same key, return never.
110
+ keyof Union extends infer Keys
111
+ ? IsNever<Keys> extends false
112
+ ? {
113
+ [Key in keyof Union]:
114
+ Union[Key] extends NonRecursiveType
115
+ ? Union[Key]
116
+ // Remove `undefined` from the union to support optional
117
+ // fields, then recover `undefined` if union was already undefined.
118
+ : SharedUnionFieldsDeep<Exclude<Union[Key], undefined>, Options> | (
119
+ undefined extends Required<Union>[Key] ? undefined : never
120
+ )
121
+ }
122
+ : {}
123
+ : Union;
124
+
125
+ /**
126
+ Same as `SharedUnionFieldsDeep`, but accepts only `UnknownArray`s and as inputs. Internal helper for `SharedUnionFieldsDeep`.
127
+ */
128
+ type SharedArrayUnionFieldsDeep<Union extends UnknownArray, Options extends Required<SharedUnionFieldsDeepOptions>> =
129
+ // Restore the readonly modifier of the array.
130
+ SetArrayAccess<
131
+ InternalSharedArrayUnionFieldsDeep<Union, Options>,
132
+ IsArrayReadonly<Union>
133
+ >;
134
+
135
+ /**
136
+ Internal helper for `SharedArrayUnionFieldsDeep`. Needn't care the `readonly` modifier of arrays.
137
+ */
138
+ type InternalSharedArrayUnionFieldsDeep<
139
+ Union extends UnknownArray,
140
+ Options extends Required<SharedUnionFieldsDeepOptions>,
141
+ ResultTuple extends UnknownArray = [],
142
+ > =
143
+ // We should build a minimum possible length tuple where each element in the tuple exists in the union tuple.
144
+ IsNever<TupleLength<Union>> extends true
145
+ // Rule 1: If all the arrays in the union have non-fixed lengths,
146
+ // like `Array<string> | [number, ...string[]]`
147
+ // we should build a tuple that is [the_fixed_parts_of_union, ...the_rest_of_union[]].
148
+ // For example: `InternalSharedArrayUnionFieldsDeep<Array<string> | [number, ...string[]]>`
149
+ // => `[string | number, ...string[]]`.
150
+ ? ResultTuple['length'] extends UnionMax<StaticPartOfArray<Union>['length']>
151
+ ? [
152
+ // The fixed-length part of the tuple.
153
+ ...ResultTuple,
154
+ // The rest of the union.
155
+ // Due to `ResultTuple` is the maximum possible fixed-length part of the tuple,
156
+ // so we can use `StaticPartOfArray` to get the rest of the union.
157
+ ...Array<
158
+ SharedUnionFieldsDeep<VariablePartOfArray<Union>[number], Options>
159
+ >,
160
+ ]
161
+ // Build the fixed-length tuple recursively.
162
+ : InternalSharedArrayUnionFieldsDeep<
163
+ Union, Options,
164
+ [...ResultTuple, SharedUnionFieldsDeep<Union[ResultTuple['length']], Options>]
165
+ >
166
+ // Rule 2: If at least one of the arrays in the union have fixed lengths,
167
+ // like `Array<string> | [number, string]`,
168
+ // we should build a tuple of the smallest possible length to ensure any
169
+ // item in the result tuple exists in the union tuple.
170
+ // For example: `InternalSharedArrayUnionFieldsDeep<Array<string> | [number, string]>`
171
+ // => `[string | number, string]`.
172
+ : ResultTuple['length'] extends UnionMin<TupleLength<Union>>
173
+ ? ResultTuple
174
+ // As above, build tuple recursively.
175
+ : InternalSharedArrayUnionFieldsDeep<
176
+ Union, Options,
177
+ [...ResultTuple, SharedUnionFieldsDeep<Union[ResultTuple['length']], Options>]
178
+ >;
@@ -0,0 +1,76 @@
1
+ import type {NonRecursiveType, IsUnion} from './internal';
2
+ import type {IsNever} from './is-never';
3
+ import type {Simplify} from './simplify';
4
+ import type {UnknownArray} from './unknown-array';
5
+
6
+ /**
7
+ Create a type with shared fields from a union of object types.
8
+
9
+ Use-cases:
10
+ - You want a safe object type where each key exists in the union object.
11
+ - You want to focus on the common fields of the union type and don't want to have to care about the other fields.
12
+
13
+ @example
14
+ ```
15
+ import type {SharedUnionFields} from 'type-fest';
16
+
17
+ type Cat = {
18
+ name: string;
19
+ type: 'cat';
20
+ catType: string;
21
+ };
22
+
23
+ type Dog = {
24
+ name: string;
25
+ type: 'dog';
26
+ dogType: string;
27
+ };
28
+
29
+ function displayPetInfo(petInfo: Cat | Dog) {
30
+ // typeof petInfo =>
31
+ // {
32
+ // name: string;
33
+ // type: 'cat';
34
+ // catType: string; // Needn't care about this field, because it's not a common pet info field.
35
+ // } | {
36
+ // name: string;
37
+ // type: 'dog';
38
+ // dogType: string; // Needn't care about this field, because it's not a common pet info field.
39
+ // }
40
+
41
+ // petInfo type is complex and have some needless fields
42
+
43
+ console.log('name: ', petInfo.name);
44
+ console.log('type: ', petInfo.type);
45
+ }
46
+
47
+ function displayPetInfo(petInfo: SharedUnionFields<Cat | Dog>) {
48
+ // typeof petInfo =>
49
+ // {
50
+ // name: string;
51
+ // type: 'cat' | 'dog';
52
+ // }
53
+
54
+ // petInfo type is simple and clear
55
+
56
+ console.log('name: ', petInfo.name);
57
+ console.log('type: ', petInfo.type);
58
+ }
59
+ ```
60
+
61
+ @see SharedUnionFieldsDeep
62
+ @see AllUnionFields
63
+
64
+ @category Object
65
+ @category Union
66
+ */
67
+ export type SharedUnionFields<Union> =
68
+ Extract<Union, NonRecursiveType | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown> | UnknownArray> extends infer SkippedMembers
69
+ ? Exclude<Union, SkippedMembers> extends infer RelevantMembers
70
+ ?
71
+ | SkippedMembers
72
+ | (IsNever<RelevantMembers> extends true
73
+ ? never
74
+ : Simplify<Pick<RelevantMembers, keyof RelevantMembers>>)
75
+ : never
76
+ : never;
@@ -0,0 +1,115 @@
1
+ import type {ConditionalSimplifyDeep} from './conditional-simplify';
2
+ import type {NonRecursiveType} from './internal';
3
+
4
+ /**
5
+ Deeply simplifies an object type.
6
+
7
+ You can exclude certain types from being simplified by providing them in the second generic `ExcludeType`.
8
+
9
+ Useful to flatten the type output to improve type hints shown in editors.
10
+
11
+ @example
12
+ ```
13
+ import type {SimplifyDeep} from 'type-fest';
14
+
15
+ type PositionX = {
16
+ left: number;
17
+ right: number;
18
+ };
19
+
20
+ type PositionY = {
21
+ top: number;
22
+ bottom: number;
23
+ };
24
+
25
+ type Properties1 = {
26
+ height: number;
27
+ position: PositionY;
28
+ };
29
+
30
+ type Properties2 = {
31
+ width: number;
32
+ position: PositionX;
33
+ };
34
+
35
+ type Properties = Properties1 & Properties2;
36
+ // In your editor, hovering over `Props` will show the following:
37
+ //
38
+ // type Properties = Properties1 & Properties2;
39
+
40
+ type SimplifyDeepProperties = SimplifyDeep<Properties1 & Properties2>;
41
+ // But if wrapped in SimplifyDeep, hovering over `SimplifyDeepProperties` will show a flattened object with all the properties:
42
+ //
43
+ // SimplifyDeepProperties = {
44
+ // height: number;
45
+ // width: number;
46
+ // position: {
47
+ // top: number;
48
+ // bottom: number;
49
+ // left: number;
50
+ // right: number;
51
+ // };
52
+ // };
53
+ ```
54
+
55
+ @example
56
+ ```
57
+ import type {SimplifyDeep} from 'type-fest';
58
+
59
+ // A complex type that you don't want or need to simplify
60
+ type ComplexType = {
61
+ a: string;
62
+ b: 'b';
63
+ c: number;
64
+ ...
65
+ };
66
+
67
+ type PositionX = {
68
+ left: number;
69
+ right: number;
70
+ };
71
+
72
+ type PositionY = {
73
+ top: number;
74
+ bottom: number;
75
+ };
76
+
77
+ // You want to simplify all other types
78
+ type Properties1 = {
79
+ height: number;
80
+ position: PositionY;
81
+ foo: ComplexType;
82
+ };
83
+
84
+ type Properties2 = {
85
+ width: number;
86
+ position: PositionX;
87
+ foo: ComplexType;
88
+ };
89
+
90
+ type SimplifyDeepProperties = SimplifyDeep<Properties1 & Properties2, ComplexType>;
91
+ // If wrapped in `SimplifyDeep` and set `ComplexType` to exclude, hovering over `SimplifyDeepProperties` will
92
+ // show a flattened object with all the properties except `ComplexType`:
93
+ //
94
+ // SimplifyDeepProperties = {
95
+ // height: number;
96
+ // width: number;
97
+ // position: {
98
+ // top: number;
99
+ // bottom: number;
100
+ // left: number;
101
+ // right: number;
102
+ // };
103
+ // foo: ComplexType;
104
+ // };
105
+ ```
106
+
107
+ @see Simplify
108
+ @category Object
109
+ */
110
+ export type SimplifyDeep<Type, ExcludeType = never> =
111
+ ConditionalSimplifyDeep<
112
+ Type,
113
+ ExcludeType | NonRecursiveType | Set<unknown> | Map<unknown, unknown>,
114
+ object
115
+ >;
@@ -0,0 +1,58 @@
1
+ /**
2
+ Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
3
+
4
+ @example
5
+ ```
6
+ import type {Simplify} from 'type-fest';
7
+
8
+ type PositionProps = {
9
+ top: number;
10
+ left: number;
11
+ };
12
+
13
+ type SizeProps = {
14
+ width: number;
15
+ height: number;
16
+ };
17
+
18
+ // In your editor, hovering over `Props` will show a flattened object with all the properties.
19
+ type Props = Simplify<PositionProps & SizeProps>;
20
+ ```
21
+
22
+ Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
23
+
24
+ If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
25
+
26
+ @example
27
+ ```
28
+ import type {Simplify} from 'type-fest';
29
+
30
+ interface SomeInterface {
31
+ foo: number;
32
+ bar?: string;
33
+ baz: number | undefined;
34
+ }
35
+
36
+ type SomeType = {
37
+ foo: number;
38
+ bar?: string;
39
+ baz: number | undefined;
40
+ };
41
+
42
+ const literal = {foo: 123, bar: 'hello', baz: 456};
43
+ const someType: SomeType = literal;
44
+ const someInterface: SomeInterface = literal;
45
+
46
+ function fn(object: Record<string, unknown>): void {}
47
+
48
+ fn(literal); // Good: literal object type is sealed
49
+ fn(someType); // Good: type is sealed
50
+ fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
51
+ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
52
+ ```
53
+
54
+ @link https://github.com/microsoft/TypeScript/issues/15300
55
+ @see SimplifyDeep
56
+ @category Object
57
+ */
58
+ export type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
@@ -0,0 +1,29 @@
1
+ import type {IfEmptyObject} from './if-empty-object';
2
+ import type {IsUnion} from './internal';
3
+
4
+ /**
5
+ Create a type that only accepts an object with a single key.
6
+
7
+ @example
8
+ ```
9
+ import type {SingleKeyObject} from 'type-fest';
10
+
11
+ const someFunction = <T>(parameter: SingleKeyObject<T>) => {};
12
+
13
+ someFunction({
14
+ value: true
15
+ });
16
+
17
+ someFunction({
18
+ value: true,
19
+ otherKey: true
20
+ });
21
+ // Error: Argument of type '{value: boolean; otherKey: boolean}' is not assignable to parameter of type 'never'.ts(2345)
22
+ ```
23
+
24
+ @category Object
25
+ */
26
+ export type SingleKeyObject<ObjectType> =
27
+ IsUnion<keyof ObjectType> extends true
28
+ ? never
29
+ : IfEmptyObject<ObjectType, never, ObjectType>;
@@ -0,0 +1,45 @@
1
+ import type {DefaultDelimiterCaseOptions, DelimiterCase} from './delimiter-case';
2
+ import type {ApplyDefaultOptions} from './internal';
3
+ import type {WordsOptions} from './words';
4
+
5
+ /**
6
+ Convert a string literal to snake-case.
7
+
8
+ This can be useful when, for example, converting a camel-cased object property to a snake-cased SQL column name.
9
+
10
+ @example
11
+ ```
12
+ import type {SnakeCase} from 'type-fest';
13
+
14
+ // Simple
15
+
16
+ const someVariable: SnakeCase<'fooBar'> = 'foo_bar';
17
+ const noSplitOnNumbers: SnakeCase<'p2pNetwork'> = 'p2p_network';
18
+ const splitOnNumbers: SnakeCase<'p2pNetwork', {splitOnNumbers: true}> = 'p_2_p_network';
19
+
20
+ // Advanced
21
+
22
+ type SnakeCasedProperties<T> = {
23
+ [K in keyof T as SnakeCase<K>]: T[K]
24
+ };
25
+
26
+ interface ModelProps {
27
+ isHappy: boolean;
28
+ fullFamilyName: string;
29
+ foo: number;
30
+ }
31
+
32
+ const dbResult: SnakeCasedProperties<ModelProps> = {
33
+ 'is_happy': true,
34
+ 'full_family_name': 'Carla Smith',
35
+ foo: 123
36
+ };
37
+ ```
38
+
39
+ @category Change case
40
+ @category Template literal
41
+ */
42
+ export type SnakeCase<
43
+ Value,
44
+ Options extends WordsOptions = {},
45
+ > = DelimiterCase<Value, '_', ApplyDefaultOptions<WordsOptions, DefaultDelimiterCaseOptions, Options>>;