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.
- package/LICENSE +52 -0
- package/README.md +168 -0
- package/dist/ai/config-wizard.js +282 -0
- package/dist/ai/enricher.js +290 -0
- package/dist/ai/prompts.js +231 -0
- package/dist/ai/provider.js +265 -0
- package/dist/cli.js +442 -0
- package/dist/config/config.js +315 -0
- package/dist/config/default-config.js +223 -0
- package/dist/core/blocks.js +145 -0
- package/dist/core/commit-planner.js +273 -0
- package/dist/core/dependency.js +284 -0
- package/dist/core/file-stats.js +341 -0
- package/dist/core/history.js +72 -0
- package/dist/core/planner.js +25 -0
- package/dist/core/scoring.js +166 -0
- package/dist/core/strategy.js +486 -0
- package/dist/git/branch-naming.js +120 -0
- package/dist/git/executor.js +378 -0
- package/dist/git/git.js +239 -0
- package/dist/output/report-styles.generated.js +10 -0
- package/dist/output/report.js +726 -0
- package/dist/output/ui.js +417 -0
- package/dist/shared/constants.js +59 -0
- package/dist/shared/types.js +7 -0
- package/dist/shared/utils.js +73 -0
- package/node_modules/@colors/colors/LICENSE +26 -0
- package/node_modules/@colors/colors/README.md +219 -0
- package/node_modules/@colors/colors/examples/normal-usage.js +83 -0
- package/node_modules/@colors/colors/examples/safe-string.js +80 -0
- package/node_modules/@colors/colors/index.d.ts +136 -0
- package/node_modules/@colors/colors/lib/colors.js +211 -0
- package/node_modules/@colors/colors/lib/custom/trap.js +46 -0
- package/node_modules/@colors/colors/lib/custom/zalgo.js +110 -0
- package/node_modules/@colors/colors/lib/extendStringPrototype.js +110 -0
- package/node_modules/@colors/colors/lib/index.js +13 -0
- package/node_modules/@colors/colors/lib/maps/america.js +10 -0
- package/node_modules/@colors/colors/lib/maps/rainbow.js +12 -0
- package/node_modules/@colors/colors/lib/maps/random.js +11 -0
- package/node_modules/@colors/colors/lib/maps/zebra.js +5 -0
- package/node_modules/@colors/colors/lib/styles.js +95 -0
- package/node_modules/@colors/colors/lib/system/has-flag.js +35 -0
- package/node_modules/@colors/colors/lib/system/supports-colors.js +151 -0
- package/node_modules/@colors/colors/package.json +45 -0
- package/node_modules/@colors/colors/safe.d.ts +48 -0
- package/node_modules/@colors/colors/safe.js +10 -0
- package/node_modules/@colors/colors/themes/generic-logging.js +12 -0
- package/node_modules/ansi-align/LICENSE +13 -0
- package/node_modules/ansi-align/README.md +80 -0
- package/node_modules/ansi-align/index.js +61 -0
- package/node_modules/ansi-align/node_modules/ansi-regex/index.d.ts +37 -0
- package/node_modules/ansi-align/node_modules/ansi-regex/index.js +10 -0
- package/node_modules/ansi-align/node_modules/ansi-regex/license +9 -0
- package/node_modules/ansi-align/node_modules/ansi-regex/package.json +55 -0
- package/node_modules/ansi-align/node_modules/ansi-regex/readme.md +78 -0
- package/node_modules/ansi-align/node_modules/emoji-regex/LICENSE-MIT.txt +20 -0
- package/node_modules/ansi-align/node_modules/emoji-regex/README.md +73 -0
- package/node_modules/ansi-align/node_modules/emoji-regex/es2015/index.js +6 -0
- package/node_modules/ansi-align/node_modules/emoji-regex/es2015/text.js +6 -0
- package/node_modules/ansi-align/node_modules/emoji-regex/index.d.ts +23 -0
- package/node_modules/ansi-align/node_modules/emoji-regex/index.js +6 -0
- package/node_modules/ansi-align/node_modules/emoji-regex/package.json +50 -0
- package/node_modules/ansi-align/node_modules/emoji-regex/text.js +6 -0
- package/node_modules/ansi-align/node_modules/string-width/index.d.ts +29 -0
- package/node_modules/ansi-align/node_modules/string-width/index.js +47 -0
- package/node_modules/ansi-align/node_modules/string-width/license +9 -0
- package/node_modules/ansi-align/node_modules/string-width/package.json +56 -0
- package/node_modules/ansi-align/node_modules/string-width/readme.md +50 -0
- package/node_modules/ansi-align/node_modules/strip-ansi/index.d.ts +17 -0
- package/node_modules/ansi-align/node_modules/strip-ansi/index.js +4 -0
- package/node_modules/ansi-align/node_modules/strip-ansi/license +9 -0
- package/node_modules/ansi-align/node_modules/strip-ansi/package.json +54 -0
- package/node_modules/ansi-align/node_modules/strip-ansi/readme.md +46 -0
- package/node_modules/ansi-align/package.json +43 -0
- package/node_modules/ansi-regex/index.d.ts +33 -0
- package/node_modules/ansi-regex/index.js +14 -0
- package/node_modules/ansi-regex/license +9 -0
- package/node_modules/ansi-regex/package.json +61 -0
- package/node_modules/ansi-regex/readme.md +66 -0
- package/node_modules/ansi-styles/index.d.ts +236 -0
- package/node_modules/ansi-styles/index.js +223 -0
- package/node_modules/ansi-styles/license +9 -0
- package/node_modules/ansi-styles/package.json +54 -0
- package/node_modules/ansi-styles/readme.md +173 -0
- package/node_modules/boxen/index.d.ts +267 -0
- package/node_modules/boxen/index.js +376 -0
- package/node_modules/boxen/license +9 -0
- package/node_modules/boxen/package.json +69 -0
- package/node_modules/boxen/readme.md +300 -0
- package/node_modules/camelcase/index.d.ts +102 -0
- package/node_modules/camelcase/index.js +110 -0
- package/node_modules/camelcase/license +9 -0
- package/node_modules/camelcase/package.json +47 -0
- package/node_modules/camelcase/readme.md +135 -0
- package/node_modules/chalk/license +9 -0
- package/node_modules/chalk/package.json +83 -0
- package/node_modules/chalk/readme.md +297 -0
- package/node_modules/chalk/source/index.d.ts +325 -0
- package/node_modules/chalk/source/index.js +225 -0
- package/node_modules/chalk/source/utilities.js +33 -0
- package/node_modules/chalk/source/vendor/ansi-styles/index.d.ts +236 -0
- package/node_modules/chalk/source/vendor/ansi-styles/index.js +223 -0
- package/node_modules/chalk/source/vendor/supports-color/browser.d.ts +1 -0
- package/node_modules/chalk/source/vendor/supports-color/browser.js +34 -0
- package/node_modules/chalk/source/vendor/supports-color/index.d.ts +55 -0
- package/node_modules/chalk/source/vendor/supports-color/index.js +190 -0
- package/node_modules/cli-boxes/boxes.json +82 -0
- package/node_modules/cli-boxes/index.d.ts +127 -0
- package/node_modules/cli-boxes/index.js +6 -0
- package/node_modules/cli-boxes/license +9 -0
- package/node_modules/cli-boxes/package.json +42 -0
- package/node_modules/cli-boxes/readme.md +115 -0
- package/node_modules/cli-table3/LICENSE +21 -0
- package/node_modules/cli-table3/README.md +236 -0
- package/node_modules/cli-table3/index.d.ts +96 -0
- package/node_modules/cli-table3/index.js +1 -0
- package/node_modules/cli-table3/node_modules/ansi-regex/index.d.ts +37 -0
- package/node_modules/cli-table3/node_modules/ansi-regex/index.js +10 -0
- package/node_modules/cli-table3/node_modules/ansi-regex/license +9 -0
- package/node_modules/cli-table3/node_modules/ansi-regex/package.json +55 -0
- package/node_modules/cli-table3/node_modules/ansi-regex/readme.md +78 -0
- package/node_modules/cli-table3/node_modules/emoji-regex/LICENSE-MIT.txt +20 -0
- package/node_modules/cli-table3/node_modules/emoji-regex/README.md +73 -0
- package/node_modules/cli-table3/node_modules/emoji-regex/es2015/index.js +6 -0
- package/node_modules/cli-table3/node_modules/emoji-regex/es2015/text.js +6 -0
- package/node_modules/cli-table3/node_modules/emoji-regex/index.d.ts +23 -0
- package/node_modules/cli-table3/node_modules/emoji-regex/index.js +6 -0
- package/node_modules/cli-table3/node_modules/emoji-regex/package.json +50 -0
- package/node_modules/cli-table3/node_modules/emoji-regex/text.js +6 -0
- package/node_modules/cli-table3/node_modules/string-width/index.d.ts +29 -0
- package/node_modules/cli-table3/node_modules/string-width/index.js +47 -0
- package/node_modules/cli-table3/node_modules/string-width/license +9 -0
- package/node_modules/cli-table3/node_modules/string-width/package.json +56 -0
- package/node_modules/cli-table3/node_modules/string-width/readme.md +50 -0
- package/node_modules/cli-table3/node_modules/strip-ansi/index.d.ts +17 -0
- package/node_modules/cli-table3/node_modules/strip-ansi/index.js +4 -0
- package/node_modules/cli-table3/node_modules/strip-ansi/license +9 -0
- package/node_modules/cli-table3/node_modules/strip-ansi/package.json +54 -0
- package/node_modules/cli-table3/node_modules/strip-ansi/readme.md +46 -0
- package/node_modules/cli-table3/package.json +100 -0
- package/node_modules/cli-table3/src/cell.js +409 -0
- package/node_modules/cli-table3/src/debug.js +28 -0
- package/node_modules/cli-table3/src/layout-manager.js +254 -0
- package/node_modules/cli-table3/src/table.js +106 -0
- package/node_modules/cli-table3/src/utils.js +344 -0
- package/node_modules/commander/LICENSE +22 -0
- package/node_modules/commander/Readme.md +1157 -0
- package/node_modules/commander/esm.mjs +16 -0
- package/node_modules/commander/index.js +24 -0
- package/node_modules/commander/lib/argument.js +149 -0
- package/node_modules/commander/lib/command.js +2509 -0
- package/node_modules/commander/lib/error.js +39 -0
- package/node_modules/commander/lib/help.js +520 -0
- package/node_modules/commander/lib/option.js +330 -0
- package/node_modules/commander/lib/suggestSimilar.js +101 -0
- package/node_modules/commander/package-support.json +16 -0
- package/node_modules/commander/package.json +84 -0
- package/node_modules/commander/typings/esm.d.mts +3 -0
- package/node_modules/commander/typings/index.d.ts +969 -0
- package/node_modules/emoji-regex/LICENSE-MIT.txt +20 -0
- package/node_modules/emoji-regex/README.md +107 -0
- package/node_modules/emoji-regex/index.d.ts +3 -0
- package/node_modules/emoji-regex/index.js +4 -0
- package/node_modules/emoji-regex/index.mjs +4 -0
- package/node_modules/emoji-regex/package.json +45 -0
- package/node_modules/get-east-asian-width/index.d.ts +60 -0
- package/node_modules/get-east-asian-width/index.js +30 -0
- package/node_modules/get-east-asian-width/license +9 -0
- package/node_modules/get-east-asian-width/lookup-data.js +18 -0
- package/node_modules/get-east-asian-width/lookup.js +135 -0
- package/node_modules/get-east-asian-width/package.json +71 -0
- package/node_modules/get-east-asian-width/readme.md +65 -0
- package/node_modules/get-east-asian-width/utilities.js +24 -0
- package/node_modules/is-fullwidth-code-point/index.d.ts +17 -0
- package/node_modules/is-fullwidth-code-point/index.js +50 -0
- package/node_modules/is-fullwidth-code-point/license +9 -0
- package/node_modules/is-fullwidth-code-point/package.json +42 -0
- package/node_modules/is-fullwidth-code-point/readme.md +39 -0
- package/node_modules/isbinaryfile/LICENSE.txt +22 -0
- package/node_modules/isbinaryfile/README.md +70 -0
- package/node_modules/isbinaryfile/lib/index.d.ts +3 -0
- package/node_modules/isbinaryfile/lib/index.js +256 -0
- package/node_modules/isbinaryfile/package.json +64 -0
- package/node_modules/string-width/index.d.ts +39 -0
- package/node_modules/string-width/index.js +82 -0
- package/node_modules/string-width/license +9 -0
- package/node_modules/string-width/package.json +64 -0
- package/node_modules/string-width/readme.md +66 -0
- package/node_modules/strip-ansi/index.d.ts +15 -0
- package/node_modules/strip-ansi/index.js +19 -0
- package/node_modules/strip-ansi/license +9 -0
- package/node_modules/strip-ansi/package.json +59 -0
- package/node_modules/strip-ansi/readme.md +37 -0
- package/node_modules/type-fest/index.d.ts +178 -0
- package/node_modules/type-fest/license-cc0 +121 -0
- package/node_modules/type-fest/license-mit +9 -0
- package/node_modules/type-fest/package.json +91 -0
- package/node_modules/type-fest/readme.md +1060 -0
- package/node_modules/type-fest/source/all-union-fields.d.ts +88 -0
- package/node_modules/type-fest/source/and.d.ts +25 -0
- package/node_modules/type-fest/source/array-indices.d.ts +23 -0
- package/node_modules/type-fest/source/array-slice.d.ts +109 -0
- package/node_modules/type-fest/source/array-splice.d.ts +99 -0
- package/node_modules/type-fest/source/array-tail.d.ts +76 -0
- package/node_modules/type-fest/source/array-values.d.ts +22 -0
- package/node_modules/type-fest/source/arrayable.d.ts +29 -0
- package/node_modules/type-fest/source/async-return-type.d.ts +23 -0
- package/node_modules/type-fest/source/asyncify.d.ts +32 -0
- package/node_modules/type-fest/source/basic.d.ts +68 -0
- package/node_modules/type-fest/source/camel-case.d.ts +89 -0
- package/node_modules/type-fest/source/camel-cased-properties-deep.d.ts +97 -0
- package/node_modules/type-fest/source/camel-cased-properties.d.ts +43 -0
- package/node_modules/type-fest/source/conditional-except.d.ts +45 -0
- package/node_modules/type-fest/source/conditional-keys.d.ts +47 -0
- package/node_modules/type-fest/source/conditional-pick-deep.d.ts +118 -0
- package/node_modules/type-fest/source/conditional-pick.d.ts +44 -0
- package/node_modules/type-fest/source/conditional-simplify.d.ts +32 -0
- package/node_modules/type-fest/source/delimiter-case.d.ts +78 -0
- package/node_modules/type-fest/source/delimiter-cased-properties-deep.d.ts +106 -0
- package/node_modules/type-fest/source/delimiter-cased-properties.d.ts +46 -0
- package/node_modules/type-fest/source/distributed-omit.d.ts +89 -0
- package/node_modules/type-fest/source/distributed-pick.d.ts +85 -0
- package/node_modules/type-fest/source/empty-object.d.ts +46 -0
- package/node_modules/type-fest/source/enforce-optional.d.ts +47 -0
- package/node_modules/type-fest/source/entries.d.ts +62 -0
- package/node_modules/type-fest/source/entry.d.ts +65 -0
- package/node_modules/type-fest/source/exact.d.ts +68 -0
- package/node_modules/type-fest/source/except.d.ts +108 -0
- package/node_modules/type-fest/source/find-global-type.d.ts +64 -0
- package/node_modules/type-fest/source/fixed-length-array.d.ts +43 -0
- package/node_modules/type-fest/source/get.d.ts +219 -0
- package/node_modules/type-fest/source/global-this.d.ts +21 -0
- package/node_modules/type-fest/source/greater-than-or-equal.d.ts +22 -0
- package/node_modules/type-fest/source/greater-than.d.ts +56 -0
- package/node_modules/type-fest/source/has-optional-keys.d.ts +21 -0
- package/node_modules/type-fest/source/has-readonly-keys.d.ts +21 -0
- package/node_modules/type-fest/source/has-required-keys.d.ts +59 -0
- package/node_modules/type-fest/source/has-writable-keys.d.ts +21 -0
- package/node_modules/type-fest/source/if-any.d.ts +24 -0
- package/node_modules/type-fest/source/if-empty-object.d.ts +26 -0
- package/node_modules/type-fest/source/if-never.d.ts +24 -0
- package/node_modules/type-fest/source/if-null.d.ts +24 -0
- package/node_modules/type-fest/source/if-unknown.d.ts +24 -0
- package/node_modules/type-fest/source/includes.d.ts +22 -0
- package/node_modules/type-fest/source/int-closed-range.d.ts +35 -0
- package/node_modules/type-fest/source/int-range.d.ts +55 -0
- package/node_modules/type-fest/source/internal/array.d.ts +126 -0
- package/node_modules/type-fest/source/internal/characters.d.ts +67 -0
- package/node_modules/type-fest/source/internal/index.d.ts +8 -0
- package/node_modules/type-fest/source/internal/keys.d.ts +97 -0
- package/node_modules/type-fest/source/internal/numeric.d.ts +118 -0
- package/node_modules/type-fest/source/internal/object.d.ts +236 -0
- package/node_modules/type-fest/source/internal/string.d.ts +210 -0
- package/node_modules/type-fest/source/internal/tuple.d.ts +90 -0
- package/node_modules/type-fest/source/internal/type.d.ts +139 -0
- package/node_modules/type-fest/source/invariant-of.d.ts +76 -0
- package/node_modules/type-fest/source/is-any.d.ts +33 -0
- package/node_modules/type-fest/source/is-equal.d.ts +31 -0
- package/node_modules/type-fest/source/is-float.d.ts +41 -0
- package/node_modules/type-fest/source/is-integer.d.ts +58 -0
- package/node_modules/type-fest/source/is-literal.d.ts +296 -0
- package/node_modules/type-fest/source/is-never.d.ts +42 -0
- package/node_modules/type-fest/source/is-null.d.ts +20 -0
- package/node_modules/type-fest/source/is-tuple.d.ts +89 -0
- package/node_modules/type-fest/source/is-unknown.d.ts +52 -0
- package/node_modules/type-fest/source/iterable-element.d.ts +64 -0
- package/node_modules/type-fest/source/join.d.ts +68 -0
- package/node_modules/type-fest/source/jsonifiable.d.ts +37 -0
- package/node_modules/type-fest/source/jsonify.d.ts +122 -0
- package/node_modules/type-fest/source/kebab-case.d.ts +44 -0
- package/node_modules/type-fest/source/kebab-cased-properties-deep.d.ts +63 -0
- package/node_modules/type-fest/source/kebab-cased-properties.d.ts +40 -0
- package/node_modules/type-fest/source/keys-of-union.d.ts +42 -0
- package/node_modules/type-fest/source/last-array-element.d.ts +38 -0
- package/node_modules/type-fest/source/less-than-or-equal.d.ts +22 -0
- package/node_modules/type-fest/source/less-than.d.ts +26 -0
- package/node_modules/type-fest/source/literal-to-primitive-deep.d.ts +36 -0
- package/node_modules/type-fest/source/literal-to-primitive.d.ts +36 -0
- package/node_modules/type-fest/source/literal-union.d.ts +37 -0
- package/node_modules/type-fest/source/merge-deep.d.ts +486 -0
- package/node_modules/type-fest/source/merge-exclusive.d.ts +41 -0
- package/node_modules/type-fest/source/merge.d.ts +48 -0
- package/node_modules/type-fest/source/multidimensional-array.d.ts +44 -0
- package/node_modules/type-fest/source/multidimensional-readonly-array.d.ts +48 -0
- package/node_modules/type-fest/source/non-empty-object.d.ts +35 -0
- package/node_modules/type-fest/source/non-empty-string.d.ts +28 -0
- package/node_modules/type-fest/source/non-empty-tuple.d.ts +21 -0
- package/node_modules/type-fest/source/numeric.d.ts +222 -0
- package/node_modules/type-fest/source/observable-like.d.ts +63 -0
- package/node_modules/type-fest/source/omit-deep.d.ts +167 -0
- package/node_modules/type-fest/source/omit-index-signature.d.ts +95 -0
- package/node_modules/type-fest/source/opaque.d.ts +1 -0
- package/node_modules/type-fest/source/optional-keys-of.d.ts +39 -0
- package/node_modules/type-fest/source/or.d.ts +25 -0
- package/node_modules/type-fest/source/override-properties.d.ts +36 -0
- package/node_modules/type-fest/source/package-json.d.ts +676 -0
- package/node_modules/type-fest/source/partial-deep.d.ts +151 -0
- package/node_modules/type-fest/source/partial-on-undefined-deep.d.ts +78 -0
- package/node_modules/type-fest/source/pascal-case.d.ts +42 -0
- package/node_modules/type-fest/source/pascal-cased-properties-deep.d.ts +62 -0
- package/node_modules/type-fest/source/pascal-cased-properties.d.ts +36 -0
- package/node_modules/type-fest/source/paths.d.ts +262 -0
- package/node_modules/type-fest/source/pick-deep.d.ts +149 -0
- package/node_modules/type-fest/source/pick-index-signature.d.ts +50 -0
- package/node_modules/type-fest/source/primitive.d.ts +13 -0
- package/node_modules/type-fest/source/promisable.d.ts +25 -0
- package/node_modules/type-fest/source/readonly-deep.d.ts +81 -0
- package/node_modules/type-fest/source/readonly-keys-of.d.ts +30 -0
- package/node_modules/type-fest/source/readonly-tuple.d.ts +41 -0
- package/node_modules/type-fest/source/replace.d.ts +85 -0
- package/node_modules/type-fest/source/require-all-or-none.d.ts +51 -0
- package/node_modules/type-fest/source/require-at-least-one.d.ts +47 -0
- package/node_modules/type-fest/source/require-exactly-one.d.ts +45 -0
- package/node_modules/type-fest/source/require-one-or-none.d.ts +46 -0
- package/node_modules/type-fest/source/required-deep.d.ts +78 -0
- package/node_modules/type-fest/source/required-keys-of.d.ts +30 -0
- package/node_modules/type-fest/source/schema.d.ts +114 -0
- package/node_modules/type-fest/source/screaming-snake-case.d.ts +28 -0
- package/node_modules/type-fest/source/set-field-type.d.ts +65 -0
- package/node_modules/type-fest/source/set-non-nullable-deep.d.ts +83 -0
- package/node_modules/type-fest/source/set-non-nullable.d.ts +39 -0
- package/node_modules/type-fest/source/set-optional.d.ts +38 -0
- package/node_modules/type-fest/source/set-parameter-type.d.ts +117 -0
- package/node_modules/type-fest/source/set-readonly.d.ts +39 -0
- package/node_modules/type-fest/source/set-required-deep.d.ts +68 -0
- package/node_modules/type-fest/source/set-required.d.ts +70 -0
- package/node_modules/type-fest/source/set-return-type.d.ts +29 -0
- package/node_modules/type-fest/source/shared-union-fields-deep.d.ts +178 -0
- package/node_modules/type-fest/source/shared-union-fields.d.ts +76 -0
- package/node_modules/type-fest/source/simplify-deep.d.ts +115 -0
- package/node_modules/type-fest/source/simplify.d.ts +58 -0
- package/node_modules/type-fest/source/single-key-object.d.ts +29 -0
- package/node_modules/type-fest/source/snake-case.d.ts +45 -0
- package/node_modules/type-fest/source/snake-cased-properties-deep.d.ts +63 -0
- package/node_modules/type-fest/source/snake-cased-properties.d.ts +40 -0
- package/node_modules/type-fest/source/split.d.ts +88 -0
- package/node_modules/type-fest/source/spread.d.ts +84 -0
- package/node_modules/type-fest/source/string-key-of.d.ts +25 -0
- package/node_modules/type-fest/source/string-repeat.d.ts +47 -0
- package/node_modules/type-fest/source/string-slice.d.ts +37 -0
- package/node_modules/type-fest/source/stringified.d.ts +23 -0
- package/node_modules/type-fest/source/structured-cloneable.d.ts +92 -0
- package/node_modules/type-fest/source/subtract.d.ts +83 -0
- package/node_modules/type-fest/source/sum.d.ts +78 -0
- package/node_modules/type-fest/source/tagged-union.d.ts +51 -0
- package/node_modules/type-fest/source/tagged.d.ts +256 -0
- package/node_modules/type-fest/source/trim.d.ts +27 -0
- package/node_modules/type-fest/source/tsconfig-json.d.ts +1294 -0
- package/node_modules/type-fest/source/tuple-to-object.d.ts +42 -0
- package/node_modules/type-fest/source/tuple-to-union.d.ts +51 -0
- package/node_modules/type-fest/source/typed-array.d.ts +17 -0
- package/node_modules/type-fest/source/undefined-on-partial-deep.d.ts +80 -0
- package/node_modules/type-fest/source/union-to-intersection.d.ts +61 -0
- package/node_modules/type-fest/source/union-to-tuple.d.ts +56 -0
- package/node_modules/type-fest/source/unknown-array.d.ts +25 -0
- package/node_modules/type-fest/source/unknown-map.d.ts +24 -0
- package/node_modules/type-fest/source/unknown-record.d.ts +31 -0
- package/node_modules/type-fest/source/unknown-set.d.ts +24 -0
- package/node_modules/type-fest/source/value-of.d.ts +42 -0
- package/node_modules/type-fest/source/words.d.ts +118 -0
- package/node_modules/type-fest/source/writable-deep.d.ts +83 -0
- package/node_modules/type-fest/source/writable-keys-of.d.ts +33 -0
- package/node_modules/type-fest/source/writable.d.ts +68 -0
- package/node_modules/widest-line/index.d.ts +12 -0
- package/node_modules/widest-line/index.js +11 -0
- package/node_modules/widest-line/license +9 -0
- package/node_modules/widest-line/package.json +60 -0
- package/node_modules/widest-line/readme.md +26 -0
- package/node_modules/wrap-ansi/index.d.ts +41 -0
- package/node_modules/wrap-ansi/index.js +222 -0
- package/node_modules/wrap-ansi/license +9 -0
- package/node_modules/wrap-ansi/package.json +69 -0
- package/node_modules/wrap-ansi/readme.md +75 -0
- package/package.json +78 -0
- 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>>;
|