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,219 @@
|
|
|
1
|
+
import type {ApplyDefaultOptions, StringDigit, ToString} from './internal';
|
|
2
|
+
import type {LiteralStringUnion} from './literal-union';
|
|
3
|
+
import type {Paths} from './paths';
|
|
4
|
+
import type {Split} from './split';
|
|
5
|
+
import type {StringKeyOf} from './string-key-of';
|
|
6
|
+
|
|
7
|
+
type GetOptions = {
|
|
8
|
+
/**
|
|
9
|
+
Include `undefined` in the return type when accessing properties.
|
|
10
|
+
|
|
11
|
+
Setting this to `false` is not recommended.
|
|
12
|
+
|
|
13
|
+
@default true
|
|
14
|
+
*/
|
|
15
|
+
strict?: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type DefaultGetOptions = {
|
|
19
|
+
strict: true;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
Like the `Get` type but receives an array of strings as a path parameter.
|
|
24
|
+
*/
|
|
25
|
+
type GetWithPath<BaseType, Keys, Options extends Required<GetOptions>> =
|
|
26
|
+
Keys extends readonly []
|
|
27
|
+
? BaseType
|
|
28
|
+
: Keys extends readonly [infer Head, ...infer Tail]
|
|
29
|
+
? GetWithPath<
|
|
30
|
+
PropertyOf<BaseType, Extract<Head, string>, Options>,
|
|
31
|
+
Extract<Tail, string[]>,
|
|
32
|
+
Options
|
|
33
|
+
>
|
|
34
|
+
: never;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
Adds `undefined` to `Type` if `strict` is enabled.
|
|
38
|
+
*/
|
|
39
|
+
type Strictify<Type, Options extends Required<GetOptions>> =
|
|
40
|
+
Options['strict'] extends false ? Type : (Type | undefined);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
If `Options['strict']` is `true`, includes `undefined` in the returned type when accessing properties on `Record<string, any>`.
|
|
44
|
+
|
|
45
|
+
Known limitations:
|
|
46
|
+
- Does not include `undefined` in the type on object types with an index signature (for example, `{a: string; [key: string]: string}`).
|
|
47
|
+
*/
|
|
48
|
+
type StrictPropertyOf<BaseType, Key extends keyof BaseType, Options extends Required<GetOptions>> =
|
|
49
|
+
Record<string, any> extends BaseType
|
|
50
|
+
? string extends keyof BaseType
|
|
51
|
+
? Strictify<BaseType[Key], Options> // Record<string, any>
|
|
52
|
+
: BaseType[Key] // Record<'a' | 'b', any> (Records with a string union as keys have required properties)
|
|
53
|
+
: BaseType[Key];
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
Splits a dot-prop style path into a tuple comprised of the properties in the path. Handles square-bracket notation.
|
|
57
|
+
|
|
58
|
+
@example
|
|
59
|
+
```
|
|
60
|
+
ToPath<'foo.bar.baz'>
|
|
61
|
+
//=> ['foo', 'bar', 'baz']
|
|
62
|
+
|
|
63
|
+
ToPath<'foo[0].bar.baz'>
|
|
64
|
+
//=> ['foo', '0', 'bar', 'baz']
|
|
65
|
+
```
|
|
66
|
+
*/
|
|
67
|
+
type ToPath<S extends string> = Split<FixPathSquareBrackets<S>, '.'>;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
Replaces square-bracketed dot notation with dots, for example, `foo[0].bar` -> `foo.0.bar`.
|
|
71
|
+
*/
|
|
72
|
+
type FixPathSquareBrackets<Path extends string> =
|
|
73
|
+
Path extends `[${infer Head}]${infer Tail}`
|
|
74
|
+
? Tail extends `[${string}`
|
|
75
|
+
? `${Head}.${FixPathSquareBrackets<Tail>}`
|
|
76
|
+
: `${Head}${FixPathSquareBrackets<Tail>}`
|
|
77
|
+
: Path extends `${infer Head}[${infer Middle}]${infer Tail}`
|
|
78
|
+
? `${Head}.${FixPathSquareBrackets<`[${Middle}]${Tail}`>}`
|
|
79
|
+
: Path;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
Returns true if `LongString` is made up out of `Substring` repeated 0 or more times.
|
|
83
|
+
|
|
84
|
+
@example
|
|
85
|
+
```
|
|
86
|
+
ConsistsOnlyOf<'aaa', 'a'> //=> true
|
|
87
|
+
ConsistsOnlyOf<'ababab', 'ab'> //=> true
|
|
88
|
+
ConsistsOnlyOf<'aBa', 'a'> //=> false
|
|
89
|
+
ConsistsOnlyOf<'', 'a'> //=> true
|
|
90
|
+
```
|
|
91
|
+
*/
|
|
92
|
+
type ConsistsOnlyOf<LongString extends string, Substring extends string> =
|
|
93
|
+
LongString extends ''
|
|
94
|
+
? true
|
|
95
|
+
: LongString extends `${Substring}${infer Tail}`
|
|
96
|
+
? ConsistsOnlyOf<Tail, Substring>
|
|
97
|
+
: false;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
Convert a type which may have number keys to one with string keys, making it possible to index using strings retrieved from template types.
|
|
101
|
+
|
|
102
|
+
@example
|
|
103
|
+
```
|
|
104
|
+
type WithNumbers = {foo: string; 0: boolean};
|
|
105
|
+
type WithStrings = WithStringKeys<WithNumbers>;
|
|
106
|
+
|
|
107
|
+
type WithNumbersKeys = keyof WithNumbers;
|
|
108
|
+
//=> 'foo' | 0
|
|
109
|
+
type WithStringsKeys = keyof WithStrings;
|
|
110
|
+
//=> 'foo' | '0'
|
|
111
|
+
```
|
|
112
|
+
*/
|
|
113
|
+
type WithStringKeys<BaseType> = {
|
|
114
|
+
[Key in StringKeyOf<BaseType>]: UncheckedIndex<BaseType, Key>
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
Perform a `T[U]` operation if `T` supports indexing.
|
|
119
|
+
*/
|
|
120
|
+
type UncheckedIndex<T, U extends string | number> = [T] extends [Record<string | number, any>] ? T[U] : never;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
Get a property of an object or array. Works when indexing arrays using number-literal-strings, for example, `PropertyOf<number[], '0'> = number`, and when indexing objects with number keys.
|
|
124
|
+
|
|
125
|
+
Note:
|
|
126
|
+
- Returns `unknown` if `Key` is not a property of `BaseType`, since TypeScript uses structural typing, and it cannot be guaranteed that extra properties unknown to the type system will exist at runtime.
|
|
127
|
+
- Returns `undefined` from nullish values, to match the behaviour of most deep-key libraries like `lodash`, `dot-prop`, etc.
|
|
128
|
+
*/
|
|
129
|
+
type PropertyOf<BaseType, Key extends string, Options extends Required<GetOptions>> =
|
|
130
|
+
BaseType extends null | undefined
|
|
131
|
+
? undefined
|
|
132
|
+
: Key extends keyof BaseType
|
|
133
|
+
? StrictPropertyOf<BaseType, Key, Options>
|
|
134
|
+
// Handle arrays and tuples
|
|
135
|
+
: BaseType extends readonly unknown[]
|
|
136
|
+
? Key extends `${number}`
|
|
137
|
+
// For arrays with unknown length (regular arrays)
|
|
138
|
+
? number extends BaseType['length']
|
|
139
|
+
? Strictify<BaseType[number], Options>
|
|
140
|
+
// For tuples: check if the index is valid
|
|
141
|
+
: Key extends keyof BaseType
|
|
142
|
+
? Strictify<BaseType[Key & keyof BaseType], Options>
|
|
143
|
+
// Out-of-bounds access for tuples
|
|
144
|
+
: unknown
|
|
145
|
+
// Non-numeric string key for arrays/tuples
|
|
146
|
+
: unknown
|
|
147
|
+
// Handle array-like objects
|
|
148
|
+
: BaseType extends {
|
|
149
|
+
[n: number]: infer Item;
|
|
150
|
+
length: number; // Note: This is needed to avoid being too lax with records types using number keys like `{0: string; 1: boolean}`.
|
|
151
|
+
}
|
|
152
|
+
? (
|
|
153
|
+
ConsistsOnlyOf<Key, StringDigit> extends true
|
|
154
|
+
? Strictify<Item, Options>
|
|
155
|
+
: unknown
|
|
156
|
+
)
|
|
157
|
+
: Key extends keyof WithStringKeys<BaseType>
|
|
158
|
+
? StrictPropertyOf<WithStringKeys<BaseType>, Key, Options>
|
|
159
|
+
: unknown;
|
|
160
|
+
|
|
161
|
+
// This works by first splitting the path based on `.` and `[...]` characters into a tuple of string keys. Then it recursively uses the head key to get the next property of the current object, until there are no keys left. Number keys extract the item type from arrays, or are converted to strings to extract types from tuples and dictionaries with number keys.
|
|
162
|
+
/**
|
|
163
|
+
Get a deeply-nested property from an object using a key path, like Lodash's `.get()` function.
|
|
164
|
+
|
|
165
|
+
Use-case: Retrieve a property from deep inside an API response or some other complex object.
|
|
166
|
+
|
|
167
|
+
@example
|
|
168
|
+
```
|
|
169
|
+
import type {Get} from 'type-fest';
|
|
170
|
+
import * as lodash from 'lodash';
|
|
171
|
+
|
|
172
|
+
const get = <BaseType, Path extends string | readonly string[]>(object: BaseType, path: Path): Get<BaseType, Path> =>
|
|
173
|
+
lodash.get(object, path);
|
|
174
|
+
|
|
175
|
+
interface ApiResponse {
|
|
176
|
+
hits: {
|
|
177
|
+
hits: Array<{
|
|
178
|
+
_id: string
|
|
179
|
+
_source: {
|
|
180
|
+
name: Array<{
|
|
181
|
+
given: string[]
|
|
182
|
+
family: string
|
|
183
|
+
}>
|
|
184
|
+
birthDate: string
|
|
185
|
+
}
|
|
186
|
+
}>
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const getName = (apiResponse: ApiResponse) =>
|
|
191
|
+
get(apiResponse, 'hits.hits[0]._source.name');
|
|
192
|
+
//=> Array<{given: string[]; family: string}> | undefined
|
|
193
|
+
|
|
194
|
+
// Path also supports a readonly array of strings
|
|
195
|
+
const getNameWithPathArray = (apiResponse: ApiResponse) =>
|
|
196
|
+
get(apiResponse, ['hits','hits', '0', '_source', 'name'] as const);
|
|
197
|
+
//=> Array<{given: string[]; family: string}> | undefined
|
|
198
|
+
|
|
199
|
+
// Non-strict mode:
|
|
200
|
+
Get<string[], '3', {strict: false}> //=> string
|
|
201
|
+
Get<Record<string, string>, 'foo', {strict: true}> // => string
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
@category Object
|
|
205
|
+
@category Array
|
|
206
|
+
@category Template literal
|
|
207
|
+
*/
|
|
208
|
+
export type Get<
|
|
209
|
+
BaseType,
|
|
210
|
+
Path extends
|
|
211
|
+
| readonly string[]
|
|
212
|
+
| LiteralStringUnion<ToString<Paths<BaseType, {bracketNotation: false; maxRecursionDepth: 2}> | Paths<BaseType, {bracketNotation: true; maxRecursionDepth: 2}>>>,
|
|
213
|
+
Options extends GetOptions = {},
|
|
214
|
+
> =
|
|
215
|
+
GetWithPath<
|
|
216
|
+
BaseType,
|
|
217
|
+
Path extends string ? ToPath<Path> : Path,
|
|
218
|
+
ApplyDefaultOptions<GetOptions, DefaultGetOptions, Options>
|
|
219
|
+
>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Declare locally scoped properties on `globalThis`.
|
|
3
|
+
|
|
4
|
+
When defining a global variable in a declaration file is inappropriate, it can be helpful to define a `type` or `interface` (say `ExtraGlobals`) with the global variable and then cast `globalThis` via code like `globalThis as unknown as ExtraGlobals`.
|
|
5
|
+
|
|
6
|
+
Instead of casting through `unknown`, you can update your `type` or `interface` to extend `GlobalThis` and then directly cast `globalThis`.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {GlobalThis} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
type ExtraGlobals = GlobalThis & {
|
|
13
|
+
readonly GLOBAL_TOKEN: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
(globalThis as ExtraGlobals).GLOBAL_TOKEN;
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
@category Type
|
|
20
|
+
*/
|
|
21
|
+
export type GlobalThis = typeof globalThis;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type {GreaterThan} from './greater-than';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Returns a boolean for whether a given number is greater than or equal to another number.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import type {GreaterThanOrEqual} from 'type-fest';
|
|
9
|
+
|
|
10
|
+
GreaterThanOrEqual<1, -5>;
|
|
11
|
+
//=> true
|
|
12
|
+
|
|
13
|
+
GreaterThanOrEqual<1, 1>;
|
|
14
|
+
//=> true
|
|
15
|
+
|
|
16
|
+
GreaterThanOrEqual<1, 5>;
|
|
17
|
+
//=> false
|
|
18
|
+
```
|
|
19
|
+
*/
|
|
20
|
+
export type GreaterThanOrEqual<A extends number, B extends number> = number extends A | B
|
|
21
|
+
? never
|
|
22
|
+
: A extends B ? true : GreaterThan<A, B>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type {NumberAbsolute, PositiveNumericStringGt} from './internal';
|
|
2
|
+
import type {IsEqual} from './is-equal';
|
|
3
|
+
import type {PositiveInfinity, NegativeInfinity, IsNegative} from './numeric';
|
|
4
|
+
import type {And} from './and';
|
|
5
|
+
import type {Or} from './or';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
Returns a boolean for whether a given number is greater than another number.
|
|
9
|
+
|
|
10
|
+
@example
|
|
11
|
+
```
|
|
12
|
+
import type {GreaterThan} from 'type-fest';
|
|
13
|
+
|
|
14
|
+
GreaterThan<1, -5>;
|
|
15
|
+
//=> true
|
|
16
|
+
|
|
17
|
+
GreaterThan<1, 1>;
|
|
18
|
+
//=> false
|
|
19
|
+
|
|
20
|
+
GreaterThan<1, 5>;
|
|
21
|
+
//=> false
|
|
22
|
+
```
|
|
23
|
+
*/
|
|
24
|
+
export type GreaterThan<A extends number, B extends number> =
|
|
25
|
+
A extends number // For distributing `A`
|
|
26
|
+
? B extends number // For distributing `B`
|
|
27
|
+
? number extends A | B
|
|
28
|
+
? never
|
|
29
|
+
: [
|
|
30
|
+
IsEqual<A, PositiveInfinity>, IsEqual<A, NegativeInfinity>,
|
|
31
|
+
IsEqual<B, PositiveInfinity>, IsEqual<B, NegativeInfinity>,
|
|
32
|
+
] extends infer R extends [boolean, boolean, boolean, boolean]
|
|
33
|
+
? Or<
|
|
34
|
+
And<IsEqual<R[0], true>, IsEqual<R[2], false>>,
|
|
35
|
+
And<IsEqual<R[3], true>, IsEqual<R[1], false>>
|
|
36
|
+
> extends true
|
|
37
|
+
? true
|
|
38
|
+
: Or<
|
|
39
|
+
And<IsEqual<R[1], true>, IsEqual<R[3], false>>,
|
|
40
|
+
And<IsEqual<R[2], true>, IsEqual<R[0], false>>
|
|
41
|
+
> extends true
|
|
42
|
+
? false
|
|
43
|
+
: true extends R[number]
|
|
44
|
+
? false
|
|
45
|
+
: [IsNegative<A>, IsNegative<B>] extends infer R extends [boolean, boolean]
|
|
46
|
+
? [true, false] extends R
|
|
47
|
+
? false
|
|
48
|
+
: [false, true] extends R
|
|
49
|
+
? true
|
|
50
|
+
: [false, false] extends R
|
|
51
|
+
? PositiveNumericStringGt<`${A}`, `${B}`>
|
|
52
|
+
: PositiveNumericStringGt<`${NumberAbsolute<B>}`, `${NumberAbsolute<A>}`>
|
|
53
|
+
: never
|
|
54
|
+
: never
|
|
55
|
+
: never // Should never happen
|
|
56
|
+
: never; // Should never happen
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type {OptionalKeysOf} from './optional-keys-of';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Creates a type that represents `true` or `false` depending on whether the given type has any optional fields.
|
|
5
|
+
|
|
6
|
+
This is useful when you want to create an API whose behavior depends on the presence or absence of optional fields.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {HasOptionalKeys, OptionalKeysOf} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
type UpdateService<Entity extends object> = {
|
|
13
|
+
removeField: HasOptionalKeys<Entity> extends true
|
|
14
|
+
? (field: OptionalKeysOf<Entity>) => Promise<void>
|
|
15
|
+
: never
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
@category Utilities
|
|
20
|
+
*/
|
|
21
|
+
export type HasOptionalKeys<BaseType extends object> = OptionalKeysOf<BaseType> extends never ? false : true;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type {ReadonlyKeysOf} from './readonly-keys-of';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Creates a type that represents `true` or `false` depending on whether the given type has any readonly fields.
|
|
5
|
+
|
|
6
|
+
This is useful when you want to create an API whose behavior depends on the presence or absence of readonly fields.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {HasReadonlyKeys, ReadonlyKeysOf} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
type UpdateService<Entity extends object> = {
|
|
13
|
+
removeField: HasReadonlyKeys<Entity> extends true
|
|
14
|
+
? (field: ReadonlyKeysOf<Entity>) => Promise<void>
|
|
15
|
+
: never
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
@category Utilities
|
|
20
|
+
*/
|
|
21
|
+
export type HasReadonlyKeys<BaseType extends object> = ReadonlyKeysOf<BaseType> extends never ? false : true;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type {RequiredKeysOf} from './required-keys-of';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Creates a type that represents `true` or `false` depending on whether the given type has any required fields.
|
|
5
|
+
|
|
6
|
+
This is useful when you want to create an API whose behavior depends on the presence or absence of required fields.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {HasRequiredKeys} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
type GeneratorOptions<Template extends object> = {
|
|
13
|
+
prop1: number;
|
|
14
|
+
prop2: string;
|
|
15
|
+
} & (HasRequiredKeys<Template> extends true
|
|
16
|
+
? {template: Template}
|
|
17
|
+
: {template?: Template});
|
|
18
|
+
|
|
19
|
+
interface Template1 {
|
|
20
|
+
optionalSubParam?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface Template2 {
|
|
24
|
+
requiredSubParam: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type Options1 = GeneratorOptions<Template1>;
|
|
28
|
+
type Options2 = GeneratorOptions<Template2>;
|
|
29
|
+
|
|
30
|
+
const optA: Options1 = {
|
|
31
|
+
prop1: 0,
|
|
32
|
+
prop2: 'hi'
|
|
33
|
+
};
|
|
34
|
+
const optB: Options1 = {
|
|
35
|
+
prop1: 0,
|
|
36
|
+
prop2: 'hi',
|
|
37
|
+
template: {}
|
|
38
|
+
};
|
|
39
|
+
const optC: Options1 = {
|
|
40
|
+
prop1: 0,
|
|
41
|
+
prop2: 'hi',
|
|
42
|
+
template: {
|
|
43
|
+
optionalSubParam: 'optional value'
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const optD: Options2 = {
|
|
48
|
+
prop1: 0,
|
|
49
|
+
prop2: 'hi',
|
|
50
|
+
template: {
|
|
51
|
+
requiredSubParam: 'required value'
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
@category Utilities
|
|
58
|
+
*/
|
|
59
|
+
export type HasRequiredKeys<BaseType extends object> = RequiredKeysOf<BaseType> extends never ? false : true;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type {WritableKeysOf} from './writable-keys-of';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Creates a type that represents `true` or `false` depending on whether the given type has any writable fields.
|
|
5
|
+
|
|
6
|
+
This is useful when you want to create an API whose behavior depends on the presence or absence of writable fields.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {HasWritableKeys, WritableKeysOf} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
type UpdateService<Entity extends object> = {
|
|
13
|
+
removeField: HasWritableKeys<Entity> extends true
|
|
14
|
+
? (field: WritableKeysOf<Entity>) => Promise<void>
|
|
15
|
+
: never
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
@category Utilities
|
|
20
|
+
*/
|
|
21
|
+
export type HasWritableKeys<BaseType extends object> = WritableKeysOf<BaseType> extends never ? false : true;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type {IsAny} from './is-any';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
An if-else-like type that resolves depending on whether the given type is `any`.
|
|
5
|
+
|
|
6
|
+
@see {@link IsAny}
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {IfAny} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
type ShouldBeTrue = IfAny<any>;
|
|
13
|
+
//=> true
|
|
14
|
+
|
|
15
|
+
type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
|
|
16
|
+
//=> 'bar'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
@category Type Guard
|
|
20
|
+
@category Utilities
|
|
21
|
+
*/
|
|
22
|
+
export type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
|
|
23
|
+
IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
|
|
24
|
+
);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type {IsEmptyObject} from './empty-object';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
An if-else-like type that resolves depending on whether the given type is `{}`.
|
|
5
|
+
|
|
6
|
+
@see {@link IsEmptyObject}
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {IfEmptyObject} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
type ShouldBeTrue = IfEmptyObject<{}>;
|
|
13
|
+
//=> true
|
|
14
|
+
|
|
15
|
+
type ShouldBeBar = IfEmptyObject<{key: any}, 'foo', 'bar'>;
|
|
16
|
+
//=> 'bar'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
@category Type Guard
|
|
20
|
+
@category Utilities
|
|
21
|
+
*/
|
|
22
|
+
export type IfEmptyObject<
|
|
23
|
+
T,
|
|
24
|
+
TypeIfEmptyObject = true,
|
|
25
|
+
TypeIfNotEmptyObject = false,
|
|
26
|
+
> = IsEmptyObject<T> extends true ? TypeIfEmptyObject : TypeIfNotEmptyObject;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type {IsNever} from './is-never';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
An if-else-like type that resolves depending on whether the given type is `never`.
|
|
5
|
+
|
|
6
|
+
@see {@link IsNever}
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {IfNever} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
type ShouldBeTrue = IfNever<never>;
|
|
13
|
+
//=> true
|
|
14
|
+
|
|
15
|
+
type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
|
|
16
|
+
//=> 'bar'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
@category Type Guard
|
|
20
|
+
@category Utilities
|
|
21
|
+
*/
|
|
22
|
+
export type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
|
|
23
|
+
IsNever<T> extends true ? TypeIfNever : TypeIfNotNever
|
|
24
|
+
);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type {IsNull} from './is-null';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
An if-else-like type that resolves depending on whether the given type is `null`.
|
|
5
|
+
|
|
6
|
+
@see {@link IsNull}
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {IfNull} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
type ShouldBeTrue = IfNull<null>;
|
|
13
|
+
//=> true
|
|
14
|
+
|
|
15
|
+
type ShouldBeBar = IfNull<'not null', 'foo', 'bar'>;
|
|
16
|
+
//=> 'bar'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
@category Type Guard
|
|
20
|
+
@category Utilities
|
|
21
|
+
*/
|
|
22
|
+
export type IfNull<T, TypeIfNull = true, TypeIfNotNull = false> = (
|
|
23
|
+
IsNull<T> extends true ? TypeIfNull : TypeIfNotNull
|
|
24
|
+
);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type {IsUnknown} from './is-unknown';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
An if-else-like type that resolves depending on whether the given type is `unknown`.
|
|
5
|
+
|
|
6
|
+
@see {@link IsUnknown}
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {IfUnknown} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
type ShouldBeTrue = IfUnknown<unknown>;
|
|
13
|
+
//=> true
|
|
14
|
+
|
|
15
|
+
type ShouldBeBar = IfUnknown<'not unknown', 'foo', 'bar'>;
|
|
16
|
+
//=> 'bar'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
@category Type Guard
|
|
20
|
+
@category Utilities
|
|
21
|
+
*/
|
|
22
|
+
export type IfUnknown<T, TypeIfUnknown = true, TypeIfNotUnknown = false> = (
|
|
23
|
+
IsUnknown<T> extends true ? TypeIfUnknown : TypeIfNotUnknown
|
|
24
|
+
);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type {IsEqual} from './is-equal';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Returns a boolean for whether the given array includes the given item.
|
|
5
|
+
|
|
6
|
+
This can be useful if another type wants to make a decision based on whether the array includes that item.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {Includes} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
type hasRed<array extends any[]> = Includes<array, 'red'>;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
@category Array
|
|
16
|
+
*/
|
|
17
|
+
export type Includes<Value extends readonly any[], Item> =
|
|
18
|
+
Value extends readonly [Value[0], ...infer rest]
|
|
19
|
+
? IsEqual<Value[0], Item> extends true
|
|
20
|
+
? true
|
|
21
|
+
: Includes<rest, Item>
|
|
22
|
+
: false;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type {IntRange} from './int-range';
|
|
2
|
+
import type {Sum} from './sum';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
Generate a union of numbers.
|
|
6
|
+
|
|
7
|
+
The numbers are created from the given `Start` (inclusive) parameter to the given `End` (inclusive) parameter.
|
|
8
|
+
|
|
9
|
+
You skip over numbers using the `Step` parameter (defaults to `1`). For example, `IntClosedRange<0, 10, 2>` will create a union of `0 | 2 | 4 | 6 | 8 | 10`.
|
|
10
|
+
|
|
11
|
+
Note: `Start` or `End` must be non-negative and smaller than `999`.
|
|
12
|
+
|
|
13
|
+
Use-cases:
|
|
14
|
+
1. This can be used to define a set of valid input/output values. for example:
|
|
15
|
+
```
|
|
16
|
+
type Age = IntClosedRange<0, 120>; //=> 0 | 1 | 2 | ... | 119 | 120
|
|
17
|
+
type FontSize = IntClosedRange<10, 20>; //=> 10 | 11 | ... | 19 | 20
|
|
18
|
+
type EvenNumber = IntClosedRange<0, 10, 2>; //=> 0 | 2 | 4 | 6 | 8 | 10
|
|
19
|
+
```
|
|
20
|
+
2. This can be used to define random numbers in a range. For example, `type RandomNumber = IntClosedRange<0, 100>;`
|
|
21
|
+
|
|
22
|
+
@example
|
|
23
|
+
```
|
|
24
|
+
import type {IntClosedRange} from 'type-fest';
|
|
25
|
+
|
|
26
|
+
// Create union type `0 | 1 | ... | 9`
|
|
27
|
+
type ZeroToNine = IntClosedRange<0, 9>;
|
|
28
|
+
|
|
29
|
+
// Create union type `100 | 200 | 300 | ... | 900`
|
|
30
|
+
type Hundreds = IntClosedRange<100, 900, 100>;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
@see IntRange
|
|
34
|
+
*/
|
|
35
|
+
export type IntClosedRange<Start extends number, End extends number, Skip extends number = 1> = IntRange<Start, Sum<End, 1>, Skip>;
|