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,89 @@
|
|
|
1
|
+
import type {KeysOfUnion} from './keys-of-union';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Omits keys from a type, distributing the operation over a union.
|
|
5
|
+
|
|
6
|
+
TypeScript's `Omit` doesn't distribute over unions, leading to the erasure of unique properties from union members when omitting keys. This creates a type that only retains properties common to all union members, making it impossible to access member-specific properties after the Omit. Essentially, using `Omit` on a union type merges the types into a less specific one, hindering type narrowing and property access based on discriminants. This type solves that.
|
|
7
|
+
|
|
8
|
+
Example:
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
type A = {
|
|
12
|
+
discriminant: 'A';
|
|
13
|
+
foo: string;
|
|
14
|
+
a: number;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type B = {
|
|
18
|
+
discriminant: 'B';
|
|
19
|
+
foo: string;
|
|
20
|
+
b: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type Union = A | B;
|
|
24
|
+
|
|
25
|
+
type OmittedUnion = Omit<Union, 'foo'>;
|
|
26
|
+
//=> {discriminant: 'A' | 'B'}
|
|
27
|
+
|
|
28
|
+
const omittedUnion: OmittedUnion = createOmittedUnion();
|
|
29
|
+
|
|
30
|
+
if (omittedUnion.discriminant === 'A') {
|
|
31
|
+
// We would like to narrow `omittedUnion`'s type
|
|
32
|
+
// to `A` here, but we can't because `Omit`
|
|
33
|
+
// doesn't distribute over unions.
|
|
34
|
+
|
|
35
|
+
omittedUnion.a;
|
|
36
|
+
//=> Error: `a` is not a property of `{discriminant: 'A' | 'B'}`
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
While `Except` solves this problem, it restricts the keys you can omit to the ones that are present in **ALL** union members, where `DistributedOmit` allows you to omit keys that are present in **ANY** union member.
|
|
41
|
+
|
|
42
|
+
@example
|
|
43
|
+
```
|
|
44
|
+
type A = {
|
|
45
|
+
discriminant: 'A';
|
|
46
|
+
foo: string;
|
|
47
|
+
a: number;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type B = {
|
|
51
|
+
discriminant: 'B';
|
|
52
|
+
foo: string;
|
|
53
|
+
bar: string;
|
|
54
|
+
b: string;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
type C = {
|
|
58
|
+
discriminant: 'C';
|
|
59
|
+
bar: string;
|
|
60
|
+
c: boolean;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// Notice that `foo` exists in `A` and `B`, but not in `C`, and
|
|
64
|
+
// `bar` exists in `B` and `C`, but not in `A`.
|
|
65
|
+
|
|
66
|
+
type Union = A | B | C;
|
|
67
|
+
|
|
68
|
+
type OmittedUnion = DistributedOmit<Union, 'foo' | 'bar'>;
|
|
69
|
+
|
|
70
|
+
const omittedUnion: OmittedUnion = createOmittedUnion();
|
|
71
|
+
|
|
72
|
+
if (omittedUnion.discriminant === 'A') {
|
|
73
|
+
omittedUnion.a;
|
|
74
|
+
//=> OK
|
|
75
|
+
|
|
76
|
+
omittedUnion.foo;
|
|
77
|
+
//=> Error: `foo` is not a property of `{discriminant: 'A'; a: string}`
|
|
78
|
+
|
|
79
|
+
omittedUnion.bar;
|
|
80
|
+
//=> Error: `bar` is not a property of `{discriminant: 'A'; a: string}`
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
@category Object
|
|
85
|
+
*/
|
|
86
|
+
export type DistributedOmit<ObjectType, KeyType extends KeysOfUnion<ObjectType>> =
|
|
87
|
+
ObjectType extends unknown
|
|
88
|
+
? Omit<ObjectType, KeyType>
|
|
89
|
+
: never;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type {KeysOfUnion} from './keys-of-union';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Pick keys from a type, distributing the operation over a union.
|
|
5
|
+
|
|
6
|
+
TypeScript's `Pick` doesn't distribute over unions, leading to the erasure of unique properties from union members when picking keys. This creates a type that only retains properties common to all union members, making it impossible to access member-specific properties after the Pick. Essentially, using `Pick` on a union type merges the types into a less specific one, hindering type narrowing and property access based on discriminants. This type solves that.
|
|
7
|
+
|
|
8
|
+
Example:
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
type A = {
|
|
12
|
+
discriminant: 'A';
|
|
13
|
+
foo: {
|
|
14
|
+
bar: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type B = {
|
|
19
|
+
discriminant: 'B';
|
|
20
|
+
foo: {
|
|
21
|
+
baz: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type Union = A | B;
|
|
26
|
+
|
|
27
|
+
type PickedUnion = Pick<Union, 'discriminant' | 'foo'>;
|
|
28
|
+
//=> {discriminant: 'A' | 'B', foo: {bar: string} | {baz: string}}
|
|
29
|
+
|
|
30
|
+
const pickedUnion: PickedUnion = createPickedUnion();
|
|
31
|
+
|
|
32
|
+
if (pickedUnion.discriminant === 'A') {
|
|
33
|
+
// We would like to narrow `pickedUnion`'s type
|
|
34
|
+
// to `A` here, but we can't because `Pick`
|
|
35
|
+
// doesn't distribute over unions.
|
|
36
|
+
|
|
37
|
+
pickedUnion.foo.bar;
|
|
38
|
+
//=> Error: Property 'bar' does not exist on type '{bar: string} | {baz: string}'.
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
@example
|
|
43
|
+
```
|
|
44
|
+
type A = {
|
|
45
|
+
discriminant: 'A';
|
|
46
|
+
foo: {
|
|
47
|
+
bar: string;
|
|
48
|
+
};
|
|
49
|
+
extraneous: boolean;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
type B = {
|
|
53
|
+
discriminant: 'B';
|
|
54
|
+
foo: {
|
|
55
|
+
baz: string;
|
|
56
|
+
};
|
|
57
|
+
extraneous: boolean;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Notice that `foo.bar` exists in `A` but not in `B`.
|
|
61
|
+
|
|
62
|
+
type Union = A | B;
|
|
63
|
+
|
|
64
|
+
type PickedUnion = DistributedPick<Union, 'discriminant' | 'foo'>;
|
|
65
|
+
|
|
66
|
+
const pickedUnion: PickedUnion = createPickedUnion();
|
|
67
|
+
|
|
68
|
+
if (pickedUnion.discriminant === 'A') {
|
|
69
|
+
pickedUnion.foo.bar;
|
|
70
|
+
//=> OK
|
|
71
|
+
|
|
72
|
+
pickedUnion.extraneous;
|
|
73
|
+
//=> Error: Property `extraneous` does not exist on type `Pick<A, 'discriminant' | 'foo'>`.
|
|
74
|
+
|
|
75
|
+
pickedUnion.foo.baz;
|
|
76
|
+
//=> Error: `bar` is not a property of `{discriminant: 'A'; a: string}`.
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
@category Object
|
|
81
|
+
*/
|
|
82
|
+
export type DistributedPick<ObjectType, KeyType extends KeysOfUnion<ObjectType>> =
|
|
83
|
+
ObjectType extends unknown
|
|
84
|
+
? Pick<ObjectType, Extract<KeyType, keyof ObjectType>>
|
|
85
|
+
: never;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
declare const emptyObjectSymbol: unique symbol;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Represents a strictly empty plain object, the `{}` value.
|
|
5
|
+
|
|
6
|
+
When you annotate something as the type `{}`, it can be anything except `null` and `undefined`. This means that you cannot use `{}` to represent an empty plain object ([read more](https://stackoverflow.com/questions/47339869/typescript-empty-object-and-any-difference/52193484#52193484)).
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {EmptyObject} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
// The following illustrates the problem with `{}`.
|
|
13
|
+
const foo1: {} = {}; // Pass
|
|
14
|
+
const foo2: {} = []; // Pass
|
|
15
|
+
const foo3: {} = 42; // Pass
|
|
16
|
+
const foo4: {} = {a: 1}; // Pass
|
|
17
|
+
|
|
18
|
+
// With `EmptyObject` only the first case is valid.
|
|
19
|
+
const bar1: EmptyObject = {}; // Pass
|
|
20
|
+
const bar2: EmptyObject = 42; // Fail
|
|
21
|
+
const bar3: EmptyObject = []; // Fail
|
|
22
|
+
const bar4: EmptyObject = {a: 1}; // Fail
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<never, never>` do not work. See {@link https://github.com/sindresorhus/type-fest/issues/395 #395}.
|
|
26
|
+
|
|
27
|
+
@category Object
|
|
28
|
+
*/
|
|
29
|
+
export type EmptyObject = {[emptyObjectSymbol]?: never};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
Returns a `boolean` for whether the type is strictly equal to an empty plain object, the `{}` value.
|
|
33
|
+
|
|
34
|
+
@example
|
|
35
|
+
```
|
|
36
|
+
import type {IsEmptyObject} from 'type-fest';
|
|
37
|
+
|
|
38
|
+
type Pass = IsEmptyObject<{}>; //=> true
|
|
39
|
+
type Fail = IsEmptyObject<[]>; //=> false
|
|
40
|
+
type Fail = IsEmptyObject<null>; //=> false
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
@see EmptyObject
|
|
44
|
+
@category Object
|
|
45
|
+
*/
|
|
46
|
+
export type IsEmptyObject<T> = T extends EmptyObject ? true : false;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type {Simplify} from './simplify';
|
|
2
|
+
|
|
3
|
+
// Returns `never` if the key is optional otherwise return the key type.
|
|
4
|
+
type RequiredFilter<Type, Key extends keyof Type> = undefined extends Type[Key]
|
|
5
|
+
? Type[Key] extends undefined
|
|
6
|
+
? Key
|
|
7
|
+
: never
|
|
8
|
+
: Key;
|
|
9
|
+
|
|
10
|
+
// Returns `never` if the key is required otherwise return the key type.
|
|
11
|
+
type OptionalFilter<Type, Key extends keyof Type> = undefined extends Type[Key]
|
|
12
|
+
? Type[Key] extends undefined
|
|
13
|
+
? never
|
|
14
|
+
: Key
|
|
15
|
+
: never;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
Enforce optional keys (by adding the `?` operator) for keys that have a union with `undefined`.
|
|
19
|
+
|
|
20
|
+
@example
|
|
21
|
+
```
|
|
22
|
+
import type {EnforceOptional} from 'type-fest';
|
|
23
|
+
|
|
24
|
+
type Foo = {
|
|
25
|
+
a: string;
|
|
26
|
+
b?: string;
|
|
27
|
+
c: undefined;
|
|
28
|
+
d: number | undefined;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type FooBar = EnforceOptional<Foo>;
|
|
32
|
+
// => {
|
|
33
|
+
// a: string;
|
|
34
|
+
// b?: string;
|
|
35
|
+
// c: undefined;
|
|
36
|
+
// d?: number;
|
|
37
|
+
// }
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
@internal
|
|
41
|
+
@category Object
|
|
42
|
+
*/
|
|
43
|
+
export type EnforceOptional<ObjectType> = Simplify<{
|
|
44
|
+
[Key in keyof ObjectType as RequiredFilter<ObjectType, Key>]: ObjectType[Key]
|
|
45
|
+
} & {
|
|
46
|
+
[Key in keyof ObjectType as OptionalFilter<ObjectType, Key>]?: Exclude<ObjectType[Key], undefined>
|
|
47
|
+
}>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type {ArrayEntry, MapEntry, ObjectEntry, SetEntry} from './entry';
|
|
2
|
+
|
|
3
|
+
type ArrayEntries<BaseType extends readonly unknown[]> = Array<ArrayEntry<BaseType>>;
|
|
4
|
+
type MapEntries<BaseType> = Array<MapEntry<BaseType>>;
|
|
5
|
+
type ObjectEntries<BaseType> = Array<ObjectEntry<BaseType>>;
|
|
6
|
+
type SetEntries<BaseType extends Set<unknown>> = Array<SetEntry<BaseType>>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
Many collections have an `entries` method which returns an array of a given object's own enumerable string-keyed property [key, value] pairs. The `Entries` type will return the type of that collection's entries.
|
|
10
|
+
|
|
11
|
+
For example the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries|`Object`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries|`Map`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries|`Array`}, and {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries|`Set`} collections all have this method. Note that `WeakMap` and `WeakSet` do not have this method since their entries are not enumerable.
|
|
12
|
+
|
|
13
|
+
@see `Entry` if you want to just access the type of a single entry.
|
|
14
|
+
|
|
15
|
+
@example
|
|
16
|
+
```
|
|
17
|
+
import type {Entries} from 'type-fest';
|
|
18
|
+
|
|
19
|
+
interface Example {
|
|
20
|
+
someKey: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const manipulatesEntries = (examples: Entries<Example>) => examples.map(example => [
|
|
24
|
+
// Does some arbitrary processing on the key (with type information available)
|
|
25
|
+
example[0].toUpperCase(),
|
|
26
|
+
|
|
27
|
+
// Does some arbitrary processing on the value (with type information available)
|
|
28
|
+
example[1].toFixed()
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
const example: Example = {someKey: 1};
|
|
32
|
+
const entries = Object.entries(example) as Entries<Example>;
|
|
33
|
+
const output = manipulatesEntries(entries);
|
|
34
|
+
|
|
35
|
+
// Objects
|
|
36
|
+
const objectExample = {a: 1};
|
|
37
|
+
const objectEntries: Entries<typeof objectExample> = [['a', 1]];
|
|
38
|
+
|
|
39
|
+
// Arrays
|
|
40
|
+
const arrayExample = ['a', 1];
|
|
41
|
+
const arrayEntries: Entries<typeof arrayExample> = [[0, 'a'], [1, 1]];
|
|
42
|
+
|
|
43
|
+
// Maps
|
|
44
|
+
const mapExample = new Map([['a', 1]]);
|
|
45
|
+
const mapEntries: Entries<typeof mapExample> = [['a', 1]];
|
|
46
|
+
|
|
47
|
+
// Sets
|
|
48
|
+
const setExample = new Set(['a', 1]);
|
|
49
|
+
const setEntries: Entries<typeof setExample> = [['a', 'a'], [1, 1]];
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
@category Object
|
|
53
|
+
@category Map
|
|
54
|
+
@category Set
|
|
55
|
+
@category Array
|
|
56
|
+
*/
|
|
57
|
+
export type Entries<BaseType> =
|
|
58
|
+
BaseType extends Map<unknown, unknown> ? MapEntries<BaseType>
|
|
59
|
+
: BaseType extends Set<unknown> ? SetEntries<BaseType>
|
|
60
|
+
: BaseType extends readonly unknown[] ? ArrayEntries<BaseType>
|
|
61
|
+
: BaseType extends object ? ObjectEntries<BaseType>
|
|
62
|
+
: never;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
type MapKey<BaseType> = BaseType extends Map<infer KeyType, unknown> ? KeyType : never;
|
|
2
|
+
type MapValue<BaseType> = BaseType extends Map<unknown, infer ValueType> ? ValueType : never;
|
|
3
|
+
|
|
4
|
+
export type ArrayEntry<BaseType extends readonly unknown[]> = [number, BaseType[number]];
|
|
5
|
+
export type MapEntry<BaseType> = [MapKey<BaseType>, MapValue<BaseType>];
|
|
6
|
+
export type ObjectEntry<BaseType> = [keyof BaseType, BaseType[keyof BaseType]];
|
|
7
|
+
export type SetEntry<BaseType> = BaseType extends Set<infer ItemType> ? [ItemType, ItemType] : never;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
Many collections have an `entries` method which returns an array of a given object's own enumerable string-keyed property [key, value] pairs. The `Entry` type will return the type of that collection's entry.
|
|
11
|
+
|
|
12
|
+
For example the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries|`Object`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries|`Map`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries|`Array`}, and {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries|`Set`} collections all have this method. Note that `WeakMap` and `WeakSet` do not have this method since their entries are not enumerable.
|
|
13
|
+
|
|
14
|
+
@see `Entries` if you want to just access the type of the array of entries (which is the return of the `.entries()` method).
|
|
15
|
+
|
|
16
|
+
@example
|
|
17
|
+
```
|
|
18
|
+
import type {Entry} from 'type-fest';
|
|
19
|
+
|
|
20
|
+
interface Example {
|
|
21
|
+
someKey: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const manipulatesEntry = (example: Entry<Example>) => [
|
|
25
|
+
// Does some arbitrary processing on the key (with type information available)
|
|
26
|
+
example[0].toUpperCase(),
|
|
27
|
+
|
|
28
|
+
// Does some arbitrary processing on the value (with type information available)
|
|
29
|
+
example[1].toFixed(),
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const example: Example = {someKey: 1};
|
|
33
|
+
const entry = Object.entries(example)[0] as Entry<Example>;
|
|
34
|
+
const output = manipulatesEntry(entry);
|
|
35
|
+
|
|
36
|
+
// Objects
|
|
37
|
+
const objectExample = {a: 1};
|
|
38
|
+
const objectEntry: Entry<typeof objectExample> = ['a', 1];
|
|
39
|
+
|
|
40
|
+
// Arrays
|
|
41
|
+
const arrayExample = ['a', 1];
|
|
42
|
+
const arrayEntryString: Entry<typeof arrayExample> = [0, 'a'];
|
|
43
|
+
const arrayEntryNumber: Entry<typeof arrayExample> = [1, 1];
|
|
44
|
+
|
|
45
|
+
// Maps
|
|
46
|
+
const mapExample = new Map([['a', 1]]);
|
|
47
|
+
const mapEntry: Entry<typeof mapExample> = ['a', 1];
|
|
48
|
+
|
|
49
|
+
// Sets
|
|
50
|
+
const setExample = new Set(['a', 1]);
|
|
51
|
+
const setEntryString: Entry<typeof setExample> = ['a', 'a'];
|
|
52
|
+
const setEntryNumber: Entry<typeof setExample> = [1, 1];
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
@category Object
|
|
56
|
+
@category Map
|
|
57
|
+
@category Array
|
|
58
|
+
@category Set
|
|
59
|
+
*/
|
|
60
|
+
export type Entry<BaseType> =
|
|
61
|
+
BaseType extends Map<unknown, unknown> ? MapEntry<BaseType>
|
|
62
|
+
: BaseType extends Set<unknown> ? SetEntry<BaseType>
|
|
63
|
+
: BaseType extends readonly unknown[] ? ArrayEntry<BaseType>
|
|
64
|
+
: BaseType extends object ? ObjectEntry<BaseType>
|
|
65
|
+
: never;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type {ArrayElement, ObjectValue} from './internal';
|
|
2
|
+
import type {IsEqual} from './is-equal';
|
|
3
|
+
import type {KeysOfUnion} from './keys-of-union';
|
|
4
|
+
import type {IsUnknown} from './is-unknown';
|
|
5
|
+
import type {Primitive} from './primitive';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
Create a type from `ParameterType` and `InputType` and change keys exclusive to `InputType` to `never`.
|
|
9
|
+
- Generate a list of keys that exists in `InputType` but not in `ParameterType`.
|
|
10
|
+
- Mark these excess keys as `never`.
|
|
11
|
+
*/
|
|
12
|
+
type ExactObject<ParameterType, InputType> = {[Key in keyof ParameterType]: Exact<ParameterType[Key], ObjectValue<InputType, Key>>}
|
|
13
|
+
& Record<Exclude<keyof InputType, KeysOfUnion<ParameterType>>, never>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
Create a type that does not allow extra properties, meaning it only allows properties that are explicitly declared.
|
|
17
|
+
|
|
18
|
+
This is useful for function type-guarding to reject arguments with excess properties. Due to the nature of TypeScript, it does not complain if excess properties are provided unless the provided value is an object literal.
|
|
19
|
+
|
|
20
|
+
*Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/12936) if you want to have this type as a built-in in TypeScript.*
|
|
21
|
+
|
|
22
|
+
@example
|
|
23
|
+
```
|
|
24
|
+
type OnlyAcceptName = {name: string};
|
|
25
|
+
|
|
26
|
+
function onlyAcceptName(arguments_: OnlyAcceptName) {}
|
|
27
|
+
|
|
28
|
+
// TypeScript complains about excess properties when an object literal is provided.
|
|
29
|
+
onlyAcceptName({name: 'name', id: 1});
|
|
30
|
+
//=> `id` is excess
|
|
31
|
+
|
|
32
|
+
// TypeScript does not complain about excess properties when the provided value is a variable (not an object literal).
|
|
33
|
+
const invalidInput = {name: 'name', id: 1};
|
|
34
|
+
onlyAcceptName(invalidInput); // No errors
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Having `Exact` allows TypeScript to reject excess properties.
|
|
38
|
+
|
|
39
|
+
@example
|
|
40
|
+
```
|
|
41
|
+
import {Exact} from 'type-fest';
|
|
42
|
+
|
|
43
|
+
type OnlyAcceptName = {name: string};
|
|
44
|
+
|
|
45
|
+
function onlyAcceptNameImproved<T extends Exact<OnlyAcceptName, T>>(arguments_: T) {}
|
|
46
|
+
|
|
47
|
+
const invalidInput = {name: 'name', id: 1};
|
|
48
|
+
onlyAcceptNameImproved(invalidInput); // Compilation error
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
[Read more](https://stackoverflow.com/questions/49580725/is-it-possible-to-restrict-typescript-object-to-contain-only-properties-defined)
|
|
52
|
+
|
|
53
|
+
@category Utilities
|
|
54
|
+
*/
|
|
55
|
+
export type Exact<ParameterType, InputType> =
|
|
56
|
+
// Before distributing, check if the two types are equal and if so, return the parameter type immediately
|
|
57
|
+
IsEqual<ParameterType, InputType> extends true ? ParameterType
|
|
58
|
+
// If the parameter is a primitive, return it as is immediately to avoid it being converted to a complex type
|
|
59
|
+
: ParameterType extends Primitive ? ParameterType
|
|
60
|
+
// If the parameter is an unknown, return it as is immediately to avoid it being converted to a complex type
|
|
61
|
+
: IsUnknown<ParameterType> extends true ? unknown
|
|
62
|
+
// If the parameter is a Function, return it as is because this type is not capable of handling function, leave it to TypeScript
|
|
63
|
+
: ParameterType extends Function ? ParameterType
|
|
64
|
+
// Convert union of array to array of union: A[] & B[] => (A & B)[]
|
|
65
|
+
: ParameterType extends unknown[] ? Array<Exact<ArrayElement<ParameterType>, ArrayElement<InputType>>>
|
|
66
|
+
// In TypeScript, Array is a subtype of ReadonlyArray, so always test Array before ReadonlyArray.
|
|
67
|
+
: ParameterType extends readonly unknown[] ? ReadonlyArray<Exact<ArrayElement<ParameterType>, ArrayElement<InputType>>>
|
|
68
|
+
: ExactObject<ParameterType, InputType>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type {ApplyDefaultOptions} from './internal';
|
|
2
|
+
import type {IsEqual} from './is-equal';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
Filter out keys from an object.
|
|
6
|
+
|
|
7
|
+
Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
8
|
+
Returns `never` if `Key` extends `Exclude`.
|
|
9
|
+
Returns `Key` otherwise.
|
|
10
|
+
|
|
11
|
+
@example
|
|
12
|
+
```
|
|
13
|
+
type Filtered = Filter<'foo', 'foo'>;
|
|
14
|
+
//=> never
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
@example
|
|
18
|
+
```
|
|
19
|
+
type Filtered = Filter<'bar', string>;
|
|
20
|
+
//=> never
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
@example
|
|
24
|
+
```
|
|
25
|
+
type Filtered = Filter<'bar', 'foo'>;
|
|
26
|
+
//=> 'bar'
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
@see {Except}
|
|
30
|
+
*/
|
|
31
|
+
type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
|
|
32
|
+
|
|
33
|
+
type ExceptOptions = {
|
|
34
|
+
/**
|
|
35
|
+
Disallow assigning non-specified properties.
|
|
36
|
+
|
|
37
|
+
Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
|
|
38
|
+
|
|
39
|
+
@default false
|
|
40
|
+
*/
|
|
41
|
+
requireExactProps?: boolean;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type DefaultExceptOptions = {
|
|
45
|
+
requireExactProps: false;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
Create a type from an object type without certain keys.
|
|
50
|
+
|
|
51
|
+
We recommend setting the `requireExactProps` option to `true`.
|
|
52
|
+
|
|
53
|
+
This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
|
|
54
|
+
|
|
55
|
+
This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
|
|
56
|
+
|
|
57
|
+
@example
|
|
58
|
+
```
|
|
59
|
+
import type {Except} from 'type-fest';
|
|
60
|
+
|
|
61
|
+
type Foo = {
|
|
62
|
+
a: number;
|
|
63
|
+
b: string;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
type FooWithoutA = Except<Foo, 'a'>;
|
|
67
|
+
//=> {b: string}
|
|
68
|
+
|
|
69
|
+
const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
|
|
70
|
+
//=> errors: 'a' does not exist in type '{ b: string; }'
|
|
71
|
+
|
|
72
|
+
type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
|
73
|
+
//=> {a: number} & Partial<Record<"b", never>>
|
|
74
|
+
|
|
75
|
+
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
76
|
+
//=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
|
|
77
|
+
|
|
78
|
+
// The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.
|
|
79
|
+
|
|
80
|
+
// Consider the following example:
|
|
81
|
+
|
|
82
|
+
type UserData = {
|
|
83
|
+
[metadata: string]: string;
|
|
84
|
+
email: string;
|
|
85
|
+
name: string;
|
|
86
|
+
role: 'admin' | 'user';
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// `Omit` clearly doesn't behave as expected in this case:
|
|
90
|
+
type PostPayload = Omit<UserData, 'email'>;
|
|
91
|
+
//=> type PostPayload = { [x: string]: string; [x: number]: string; }
|
|
92
|
+
|
|
93
|
+
// In situations like this, `Except` works better.
|
|
94
|
+
// It simply removes the `email` key while preserving all the other keys.
|
|
95
|
+
type PostPayload = Except<UserData, 'email'>;
|
|
96
|
+
//=> type PostPayload = { [x: string]: string; name: string; role: 'admin' | 'user'; }
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
@category Object
|
|
100
|
+
*/
|
|
101
|
+
export type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> =
|
|
102
|
+
_Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
|
|
103
|
+
|
|
104
|
+
type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = {
|
|
105
|
+
[KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
|
|
106
|
+
} & (Options['requireExactProps'] extends true
|
|
107
|
+
? Partial<Record<KeysType, never>>
|
|
108
|
+
: {});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Tries to find the type of a global with the given name.
|
|
3
|
+
|
|
4
|
+
Limitations: Due to peculiarities with the behavior of `globalThis`, "globally defined" only includes `var` declarations in `declare global` blocks, not `let` or `const` declarations.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import type {FindGlobalType} from 'type-fest';
|
|
9
|
+
|
|
10
|
+
declare global {
|
|
11
|
+
const foo: number; // let and const don't work
|
|
12
|
+
var bar: string; // var works
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type FooType = FindGlobalType<'foo'> //=> never (let/const don't work)
|
|
16
|
+
type BarType = FindGlobalType<'bar'> //=> string
|
|
17
|
+
type OtherType = FindGlobalType<'other'> //=> never (no global named 'other')
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
@category Utilities
|
|
21
|
+
*/
|
|
22
|
+
export type FindGlobalType<Name extends string> = typeof globalThis extends Record<Name, infer T> ? T : never;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
Tries to find one or more types from their globally-defined constructors.
|
|
26
|
+
|
|
27
|
+
Use-case: Conditionally referencing DOM types only when the DOM library present.
|
|
28
|
+
|
|
29
|
+
*Limitations:* Due to peculiarities with the behavior of `globalThis`, "globally defined" has a narrow definition in this case. Declaring a class in a `declare global` block won't work, instead you must declare its type using an interface and declare its constructor as a `var` (*not* `let`/`const`) inside the `declare global` block.
|
|
30
|
+
|
|
31
|
+
@example
|
|
32
|
+
```
|
|
33
|
+
import type {FindGlobalInstanceType} from 'type-fest';
|
|
34
|
+
|
|
35
|
+
class Point {
|
|
36
|
+
constructor(public x: number, public y: number) {}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type PointLike = Point | FindGlobalInstanceType<'DOMPoint'>;
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
@example
|
|
43
|
+
```
|
|
44
|
+
import type {FindGlobalInstanceType} from 'type-fest';
|
|
45
|
+
|
|
46
|
+
declare global {
|
|
47
|
+
// Class syntax won't add the key to `globalThis`
|
|
48
|
+
class Foo {}
|
|
49
|
+
|
|
50
|
+
// interface + constructor style works
|
|
51
|
+
interface Bar {}
|
|
52
|
+
var Bar: new () => Bar; // Not let or const
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type FindFoo = FindGlobalInstanceType<'Foo'>; // Doesn't work
|
|
56
|
+
type FindBar = FindGlobalInstanceType<'Bar'>; // Works
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
@category Utilities
|
|
60
|
+
*/
|
|
61
|
+
export type FindGlobalInstanceType<Name extends string> =
|
|
62
|
+
Name extends string
|
|
63
|
+
? typeof globalThis extends Record<Name, abstract new (...arguments: any[]) => infer T> ? T : never
|
|
64
|
+
: never;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Methods to exclude.
|
|
3
|
+
*/
|
|
4
|
+
type ArrayLengthMutationKeys = 'splice' | 'push' | 'pop' | 'shift' | 'unshift';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
Create a type that represents an array of the given type and length. The array's length and the `Array` prototype methods that manipulate its length are excluded in the resulting type.
|
|
8
|
+
|
|
9
|
+
Please participate in [this issue](https://github.com/microsoft/TypeScript/issues/26223) if you want to have a similar type built into TypeScript.
|
|
10
|
+
|
|
11
|
+
Use-cases:
|
|
12
|
+
- Declaring fixed-length tuples or arrays with a large number of items.
|
|
13
|
+
- Creating a range union (for example, `0 | 1 | 2 | 3 | 4` from the keys of such a type) without having to resort to recursive types.
|
|
14
|
+
- Creating an array of coordinates with a static length, for example, length of 3 for a 3D vector.
|
|
15
|
+
|
|
16
|
+
Note: This type does not prevent out-of-bounds access. Prefer `ReadonlyTuple` unless you need mutability.
|
|
17
|
+
|
|
18
|
+
@example
|
|
19
|
+
```
|
|
20
|
+
import type {FixedLengthArray} from 'type-fest';
|
|
21
|
+
|
|
22
|
+
type FencingTeam = FixedLengthArray<string, 3>;
|
|
23
|
+
|
|
24
|
+
const guestFencingTeam: FencingTeam = ['Josh', 'Michael', 'Robert'];
|
|
25
|
+
|
|
26
|
+
const homeFencingTeam: FencingTeam = ['George', 'John'];
|
|
27
|
+
//=> error TS2322: Type string[] is not assignable to type 'FencingTeam'
|
|
28
|
+
|
|
29
|
+
guestFencingTeam.push('Sam');
|
|
30
|
+
//=> error TS2339: Property 'push' does not exist on type 'FencingTeam'
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
@category Array
|
|
34
|
+
@see ReadonlyTuple
|
|
35
|
+
*/
|
|
36
|
+
export type FixedLengthArray<Element, Length extends number, ArrayPrototype = [Element, ...Element[]]> = Pick<
|
|
37
|
+
ArrayPrototype,
|
|
38
|
+
Exclude<keyof ArrayPrototype, ArrayLengthMutationKeys>
|
|
39
|
+
> & {
|
|
40
|
+
[index: number]: Element;
|
|
41
|
+
[Symbol.iterator]: () => IterableIterator<Element>;
|
|
42
|
+
readonly length: Length;
|
|
43
|
+
};
|