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