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,52 @@
|
|
|
1
|
+
import type {IsNull} from './is-null';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Returns a boolean for whether the given type is `unknown`.
|
|
5
|
+
|
|
6
|
+
@link https://github.com/dsherret/conditional-type-checks/pull/16
|
|
7
|
+
|
|
8
|
+
Useful in type utilities, such as when dealing with unknown data from API calls.
|
|
9
|
+
|
|
10
|
+
@example
|
|
11
|
+
```
|
|
12
|
+
import type {IsUnknown} from 'type-fest';
|
|
13
|
+
|
|
14
|
+
// https://github.com/pajecawav/tiny-global-store/blob/master/src/index.ts
|
|
15
|
+
type Action<TState, TPayload = void> =
|
|
16
|
+
IsUnknown<TPayload> extends true
|
|
17
|
+
? (state: TState) => TState,
|
|
18
|
+
: (state: TState, payload: TPayload) => TState;
|
|
19
|
+
|
|
20
|
+
class Store<TState> {
|
|
21
|
+
constructor(private state: TState) {}
|
|
22
|
+
|
|
23
|
+
execute<TPayload = void>(action: Action<TState, TPayload>, payload?: TPayload): TState {
|
|
24
|
+
this.state = action(this.state, payload);
|
|
25
|
+
return this.state;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// ... other methods
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const store = new Store({value: 1});
|
|
32
|
+
declare const someExternalData: unknown;
|
|
33
|
+
|
|
34
|
+
store.execute(state => ({value: state.value + 1}));
|
|
35
|
+
//=> `TPayload` is `void`
|
|
36
|
+
|
|
37
|
+
store.execute((state, payload) => ({value: state.value + payload}), 5);
|
|
38
|
+
//=> `TPayload` is `5`
|
|
39
|
+
|
|
40
|
+
store.execute((state, payload) => ({value: state.value + payload}), someExternalData);
|
|
41
|
+
//=> Errors: `action` is `(state: TState) => TState`
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
@category Utilities
|
|
45
|
+
*/
|
|
46
|
+
export type IsUnknown<T> = (
|
|
47
|
+
unknown extends T // `T` can be `unknown` or `any`
|
|
48
|
+
? IsNull<T> extends false // `any` can be `null`, but `unknown` can't be
|
|
49
|
+
? true
|
|
50
|
+
: false
|
|
51
|
+
: false
|
|
52
|
+
);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Get the element type of an `Iterable`/`AsyncIterable`. For example, `Array`, `Set`, `Map`, generator, stream, etc.
|
|
3
|
+
|
|
4
|
+
This can be useful, for example, if you want to get the type that is yielded in a generator function. Often the return type of those functions are not specified.
|
|
5
|
+
|
|
6
|
+
This type works with both `Iterable`s and `AsyncIterable`s, so it can be use with synchronous and asynchronous generators.
|
|
7
|
+
|
|
8
|
+
Here is an example of `IterableElement` in action with a generator function:
|
|
9
|
+
|
|
10
|
+
@example
|
|
11
|
+
```
|
|
12
|
+
import type {IterableElement} from 'type-fest';
|
|
13
|
+
|
|
14
|
+
function * iAmGenerator() {
|
|
15
|
+
yield 1;
|
|
16
|
+
yield 2;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type MeNumber = IterableElement<ReturnType<typeof iAmGenerator>>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
And here is an example with an async generator:
|
|
23
|
+
|
|
24
|
+
@example
|
|
25
|
+
```
|
|
26
|
+
import type {IterableElement} from 'type-fest';
|
|
27
|
+
|
|
28
|
+
async function * iAmGeneratorAsync() {
|
|
29
|
+
yield 'hi';
|
|
30
|
+
yield true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type MeStringOrBoolean = IterableElement<ReturnType<typeof iAmGeneratorAsync>>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Many types in JavaScript/TypeScript are iterables. This type works on all types that implement those interfaces.
|
|
37
|
+
|
|
38
|
+
An example with an array of strings:
|
|
39
|
+
|
|
40
|
+
@example
|
|
41
|
+
```
|
|
42
|
+
import type {IterableElement} from 'type-fest';
|
|
43
|
+
|
|
44
|
+
type MeString = IterableElement<string[]>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
@example
|
|
48
|
+
```
|
|
49
|
+
import type {IterableElement} from 'type-fest';
|
|
50
|
+
|
|
51
|
+
const fruits = new Set(['🍎', '🍌', '🍉'] as const);
|
|
52
|
+
|
|
53
|
+
type Fruit = IterableElement<typeof fruits>;
|
|
54
|
+
//=> '🍎' | '🍌' | '🍉'
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
@category Iterable
|
|
58
|
+
*/
|
|
59
|
+
export type IterableElement<TargetIterable> =
|
|
60
|
+
TargetIterable extends Iterable<infer ElementType> ?
|
|
61
|
+
ElementType :
|
|
62
|
+
TargetIterable extends AsyncIterable<infer ElementType> ?
|
|
63
|
+
ElementType :
|
|
64
|
+
never;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// The builtin `join` method supports all these natively in the same way that typescript handles them so we can safely accept all of them.
|
|
2
|
+
type JoinableItem = string | number | bigint | boolean | undefined | null;
|
|
3
|
+
|
|
4
|
+
// `null` and `undefined` are treated uniquely in the built-in join method, in a way that differs from the default `toString` that would result in the type `${undefined}`. That's why we need to handle it specifically with this helper.
|
|
5
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join#description
|
|
6
|
+
type NullishCoalesce<
|
|
7
|
+
Value extends JoinableItem,
|
|
8
|
+
Fallback extends string,
|
|
9
|
+
> = Value extends undefined | null ? NonNullable<Value> | Fallback : Value;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
Join an array of strings and/or numbers using the given string as a delimiter.
|
|
13
|
+
|
|
14
|
+
Use-case: Defining key paths in a nested object. For example, for dot-notation fields in MongoDB queries.
|
|
15
|
+
|
|
16
|
+
@example
|
|
17
|
+
```
|
|
18
|
+
import type {Join} from 'type-fest';
|
|
19
|
+
|
|
20
|
+
// Mixed (strings & numbers) items; result is: 'foo.0.baz'
|
|
21
|
+
const path: Join<['foo', 0, 'baz'], '.'> = ['foo', 0, 'baz'].join('.');
|
|
22
|
+
|
|
23
|
+
// Only string items; result is: 'foo.bar.baz'
|
|
24
|
+
const path: Join<['foo', 'bar', 'baz'], '.'> = ['foo', 'bar', 'baz'].join('.');
|
|
25
|
+
|
|
26
|
+
// Only number items; result is: '1.2.3'
|
|
27
|
+
const path: Join<[1, 2, 3], '.'> = [1, 2, 3].join('.');
|
|
28
|
+
|
|
29
|
+
// Only bigint items; result is '1.2.3'
|
|
30
|
+
const path: Join<[1n, 2n, 3n], '.'> = [1n, 2n, 3n].join('.');
|
|
31
|
+
|
|
32
|
+
// Only boolean items; result is: 'true.false.true'
|
|
33
|
+
const path: Join<[true, false, true], '.'> = [true, false, true].join('.');
|
|
34
|
+
|
|
35
|
+
// Contains nullish items; result is: 'foo..baz..xyz'
|
|
36
|
+
const path: Join<['foo', undefined, 'baz', null, 'xyz'], '.'> = ['foo', undefined, 'baz', null, 'xyz'].join('.');
|
|
37
|
+
|
|
38
|
+
// Partial tuple shapes (rest param last); result is: `prefix.${string}`
|
|
39
|
+
const path: Join<['prefix', ...string[]], '.'> = ['prefix'].join('.');
|
|
40
|
+
|
|
41
|
+
// Partial tuple shapes (rest param first); result is: `${string}.suffix`
|
|
42
|
+
const path: Join<[...string[], 'suffix'], '.'> = ['suffix'].join('.');
|
|
43
|
+
|
|
44
|
+
// Tuples items with nullish unions; result is '.' | 'hello.' | '.world' | 'hello.world'
|
|
45
|
+
const path: Join<['hello' | undefined, 'world' | null], '.'> = ['hello', 'world'].join('.');
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
@category Array
|
|
49
|
+
@category Template literal
|
|
50
|
+
*/
|
|
51
|
+
export type Join<
|
|
52
|
+
Items extends readonly JoinableItem[],
|
|
53
|
+
Delimiter extends string,
|
|
54
|
+
> = Items extends readonly []
|
|
55
|
+
? ''
|
|
56
|
+
: Items extends readonly [JoinableItem?]
|
|
57
|
+
? `${NullishCoalesce<Items[0], ''>}`
|
|
58
|
+
: Items extends readonly [
|
|
59
|
+
infer First extends JoinableItem,
|
|
60
|
+
...infer Tail extends readonly JoinableItem[],
|
|
61
|
+
]
|
|
62
|
+
? `${NullishCoalesce<First, ''>}${Delimiter}${Join<Tail, Delimiter>}`
|
|
63
|
+
: Items extends readonly [
|
|
64
|
+
...infer Head extends readonly JoinableItem[],
|
|
65
|
+
infer Last extends JoinableItem,
|
|
66
|
+
]
|
|
67
|
+
? `${Join<Head, Delimiter>}${Delimiter}${NullishCoalesce<Last, ''>}`
|
|
68
|
+
: string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type {JsonPrimitive} from './basic';
|
|
2
|
+
|
|
3
|
+
type JsonifiableObject = {[Key in string]?: Jsonifiable} | {toJSON: () => Jsonifiable};
|
|
4
|
+
type JsonifiableArray = readonly Jsonifiable[];
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
Matches a value that can be losslessly converted to JSON.
|
|
8
|
+
|
|
9
|
+
Can be used to type values that you expect to pass to `JSON.stringify`.
|
|
10
|
+
|
|
11
|
+
`undefined` is allowed in object fields (for example, `{a?: number}`) as a special case even though `JSON.stringify({a: undefined})` is `{}` because it makes this class more widely useful and checking for undefined-but-present values is likely an anti-pattern.
|
|
12
|
+
|
|
13
|
+
@example
|
|
14
|
+
```
|
|
15
|
+
import type {Jsonifiable} from 'type-fest';
|
|
16
|
+
|
|
17
|
+
// @ts-expect-error
|
|
18
|
+
const error: Jsonifiable = {
|
|
19
|
+
map: new Map([['a', 1]]),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
JSON.stringify(error);
|
|
23
|
+
//=> {"map": {}}
|
|
24
|
+
|
|
25
|
+
const good: Jsonifiable = {
|
|
26
|
+
number: 3,
|
|
27
|
+
date: new Date(),
|
|
28
|
+
missing: undefined,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
JSON.stringify(good);
|
|
32
|
+
//=> {"number": 3, "date": "2022-10-17T22:22:35.920Z"}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
@category JSON
|
|
36
|
+
*/
|
|
37
|
+
export type Jsonifiable = JsonPrimitive | JsonifiableObject | JsonifiableArray;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type {JsonPrimitive, JsonValue} from './basic';
|
|
2
|
+
import type {EmptyObject} from './empty-object';
|
|
3
|
+
import type {UndefinedToOptional} from './internal';
|
|
4
|
+
import type {IsAny} from './is-any';
|
|
5
|
+
import type {IsNever} from './is-never';
|
|
6
|
+
import type {IsUnknown} from './is-unknown';
|
|
7
|
+
import type {NegativeInfinity, PositiveInfinity} from './numeric';
|
|
8
|
+
import type {TypedArray} from './typed-array';
|
|
9
|
+
import type {UnknownArray} from './unknown-array';
|
|
10
|
+
|
|
11
|
+
// Note: The return value has to be `any` and not `unknown` so it can match `void`.
|
|
12
|
+
type NotJsonable = ((...arguments_: any[]) => any) | undefined | symbol;
|
|
13
|
+
|
|
14
|
+
type NeverToNull<T> = IsNever<T> extends true ? null : T;
|
|
15
|
+
type UndefinedToNull<T> = T extends undefined ? null : T;
|
|
16
|
+
|
|
17
|
+
// Handles tuples and arrays
|
|
18
|
+
type JsonifyList<T extends UnknownArray> = T extends readonly []
|
|
19
|
+
? []
|
|
20
|
+
: T extends readonly [infer F, ...infer R]
|
|
21
|
+
? [NeverToNull<Jsonify<F>>, ...JsonifyList<R>]
|
|
22
|
+
: IsUnknown<T[number]> extends true
|
|
23
|
+
? []
|
|
24
|
+
: Array<T[number] extends NotJsonable ? null : Jsonify<UndefinedToNull<T[number]>>>;
|
|
25
|
+
|
|
26
|
+
type FilterJsonableKeys<T extends object> = {
|
|
27
|
+
[Key in keyof T]: T[Key] extends NotJsonable ? never : Key;
|
|
28
|
+
}[keyof T];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
JSON serialize objects (not including arrays) and classes.
|
|
32
|
+
*/
|
|
33
|
+
type JsonifyObject<T extends object> = {
|
|
34
|
+
[Key in keyof Pick<T, FilterJsonableKeys<T>>]: Jsonify<T[Key]>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
Transform a type to one that is assignable to the `JsonValue` type.
|
|
39
|
+
|
|
40
|
+
This includes:
|
|
41
|
+
1. Transforming JSON `interface` to a `type` that is assignable to `JsonValue`.
|
|
42
|
+
2. Transforming non-JSON value that is *jsonable* to a type that is assignable to `JsonValue`, where *jsonable* means the non-JSON value implements the `.toJSON()` method that returns a value that is assignable to `JsonValue`.
|
|
43
|
+
|
|
44
|
+
@remarks
|
|
45
|
+
|
|
46
|
+
An interface cannot be structurally compared to `JsonValue` because an interface can be re-opened to add properties that may not be satisfy `JsonValue`.
|
|
47
|
+
|
|
48
|
+
@example
|
|
49
|
+
```
|
|
50
|
+
import type {Jsonify, JsonValue} from 'type-fest';
|
|
51
|
+
|
|
52
|
+
interface Geometry {
|
|
53
|
+
type: 'Point' | 'Polygon';
|
|
54
|
+
coordinates: [number, number];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const point: Geometry = {
|
|
58
|
+
type: 'Point',
|
|
59
|
+
coordinates: [1, 1]
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const problemFn = (data: JsonValue) => {
|
|
63
|
+
// Does something with data
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
problemFn(point); // Error: type Geometry is not assignable to parameter of type JsonValue because it is an interface
|
|
67
|
+
|
|
68
|
+
const fixedFn = <T>(data: Jsonify<T>) => {
|
|
69
|
+
// Does something with data
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
fixedFn(point); // Good: point is assignable. Jsonify<T> transforms Geometry into value assignable to JsonValue
|
|
73
|
+
fixedFn(new Date()); // Error: As expected, Date is not assignable. Jsonify<T> cannot transforms Date into value assignable to JsonValue
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Non-JSON values such as `Date` implement `.toJSON()`, so they can be transformed to a value assignable to `JsonValue`:
|
|
77
|
+
|
|
78
|
+
@example
|
|
79
|
+
```
|
|
80
|
+
import type {Jsonify} from 'type-fest';
|
|
81
|
+
|
|
82
|
+
const time = {
|
|
83
|
+
timeValue: new Date()
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// `Jsonify<typeof time>` is equivalent to `{timeValue: string}`
|
|
87
|
+
const timeJson = JSON.parse(JSON.stringify(time)) as Jsonify<typeof time>;
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
@link https://github.com/Microsoft/TypeScript/issues/1897#issuecomment-710744173
|
|
91
|
+
|
|
92
|
+
@category JSON
|
|
93
|
+
*/
|
|
94
|
+
export type Jsonify<T> = IsAny<T> extends true
|
|
95
|
+
? any
|
|
96
|
+
: T extends PositiveInfinity | NegativeInfinity
|
|
97
|
+
? null
|
|
98
|
+
: T extends JsonPrimitive
|
|
99
|
+
? T
|
|
100
|
+
: // Any object with toJSON is special case
|
|
101
|
+
T extends {toJSON(): infer J}
|
|
102
|
+
? (() => J) extends () => JsonValue // Is J assignable to JsonValue?
|
|
103
|
+
? J // Then T is Jsonable and its Jsonable value is J
|
|
104
|
+
: Jsonify<J> // Maybe if we look a level deeper we'll find a JsonValue
|
|
105
|
+
: // Instanced primitives are objects
|
|
106
|
+
T extends Number
|
|
107
|
+
? number
|
|
108
|
+
: T extends String
|
|
109
|
+
? string
|
|
110
|
+
: T extends Boolean
|
|
111
|
+
? boolean
|
|
112
|
+
: T extends Map<any, any> | Set<any>
|
|
113
|
+
? EmptyObject
|
|
114
|
+
: T extends TypedArray
|
|
115
|
+
? Record<string, number>
|
|
116
|
+
: T extends NotJsonable
|
|
117
|
+
? never // Non-JSONable type union was found not empty
|
|
118
|
+
: T extends UnknownArray
|
|
119
|
+
? JsonifyList<T>
|
|
120
|
+
: T extends object
|
|
121
|
+
? JsonifyObject<UndefinedToOptional<T>> // JsonifyObject recursive call for its children
|
|
122
|
+
: never; // Otherwise any other non-object is removed
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type {DefaultDelimiterCaseOptions, DelimiterCase} from './delimiter-case';
|
|
2
|
+
import type {ApplyDefaultOptions} from './internal';
|
|
3
|
+
import type {WordsOptions} from './words';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
Convert a string literal to kebab-case.
|
|
7
|
+
|
|
8
|
+
This can be useful when, for example, converting a camel-cased object property to a kebab-cased CSS class name or a command-line flag.
|
|
9
|
+
|
|
10
|
+
@example
|
|
11
|
+
```
|
|
12
|
+
import type {KebabCase} from 'type-fest';
|
|
13
|
+
|
|
14
|
+
// Simple
|
|
15
|
+
|
|
16
|
+
const someVariable: KebabCase<'fooBar'> = 'foo-bar';
|
|
17
|
+
const someVariableNoSplitOnNumbers: KebabCase<'p2pNetwork', {splitOnNumbers: false}> = 'p2p-network';
|
|
18
|
+
|
|
19
|
+
// Advanced
|
|
20
|
+
|
|
21
|
+
type KebabCasedProperties<T> = {
|
|
22
|
+
[K in keyof T as KebabCase<K>]: T[K]
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
interface CliOptions {
|
|
26
|
+
dryRun: boolean;
|
|
27
|
+
includeFile: string;
|
|
28
|
+
foo: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const rawCliOptions: KebabCasedProperties<CliOptions> = {
|
|
32
|
+
'dry-run': true,
|
|
33
|
+
'include-file': 'bar.js',
|
|
34
|
+
foo: 123
|
|
35
|
+
};
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
@category Change case
|
|
39
|
+
@category Template literal
|
|
40
|
+
*/
|
|
41
|
+
export type KebabCase<
|
|
42
|
+
Value,
|
|
43
|
+
Options extends WordsOptions = {},
|
|
44
|
+
> = DelimiterCase<Value, '-', ApplyDefaultOptions<WordsOptions, DefaultDelimiterCaseOptions, Options>>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type {DefaultDelimiterCaseOptions} from './delimiter-case';
|
|
2
|
+
import type {DelimiterCasedPropertiesDeep} from './delimiter-cased-properties-deep';
|
|
3
|
+
import type {ApplyDefaultOptions} from './internal';
|
|
4
|
+
import type {WordsOptions} from './words';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
Convert object properties to kebab case recursively.
|
|
8
|
+
|
|
9
|
+
This can be useful when, for example, converting some API types from a different style.
|
|
10
|
+
|
|
11
|
+
@see KebabCase
|
|
12
|
+
@see KebabCasedProperties
|
|
13
|
+
|
|
14
|
+
@example
|
|
15
|
+
```
|
|
16
|
+
import type [KebabCasedPropertiesDeep] from 'type-fest';
|
|
17
|
+
|
|
18
|
+
interface User {
|
|
19
|
+
userId: number;
|
|
20
|
+
userName: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface UserWithFriends {
|
|
24
|
+
userInfo: User;
|
|
25
|
+
userFriends: User[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const result: KebabCasedPropertiesDeep<UserWithFriends> = {
|
|
29
|
+
'user-info': {
|
|
30
|
+
'user-id': 1,
|
|
31
|
+
'user-name': 'Tom',
|
|
32
|
+
},
|
|
33
|
+
'user-friends': [
|
|
34
|
+
{
|
|
35
|
+
'user-id': 2,
|
|
36
|
+
'user-name': 'Jerry',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
'user-id': 3,
|
|
40
|
+
'user-name': 'Spike',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const splitOnNumbers: KebabCasedPropertiesDeep<{line1: { line2: [{ line3: string }] }}, {splitOnNumbers: true}> = {
|
|
46
|
+
'line-1': {
|
|
47
|
+
'line-2': [
|
|
48
|
+
{
|
|
49
|
+
'line-3': 'string',
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
@category Change case
|
|
57
|
+
@category Template literal
|
|
58
|
+
@category Object
|
|
59
|
+
*/
|
|
60
|
+
export type KebabCasedPropertiesDeep<
|
|
61
|
+
Value,
|
|
62
|
+
Options extends WordsOptions = {},
|
|
63
|
+
> = DelimiterCasedPropertiesDeep<Value, '-', ApplyDefaultOptions<WordsOptions, DefaultDelimiterCaseOptions, Options>>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type {DefaultDelimiterCaseOptions} from './delimiter-case';
|
|
2
|
+
import type {DelimiterCasedProperties} from './delimiter-cased-properties';
|
|
3
|
+
import type {ApplyDefaultOptions} from './internal';
|
|
4
|
+
import type {WordsOptions} from './words';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
Convert object properties to kebab case but not recursively.
|
|
8
|
+
|
|
9
|
+
This can be useful when, for example, converting some API types from a different style.
|
|
10
|
+
|
|
11
|
+
@see KebabCase
|
|
12
|
+
@see KebabCasedPropertiesDeep
|
|
13
|
+
|
|
14
|
+
@example
|
|
15
|
+
```
|
|
16
|
+
import type {KebabCasedProperties} from 'type-fest';
|
|
17
|
+
|
|
18
|
+
interface User {
|
|
19
|
+
userId: number;
|
|
20
|
+
userName: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const result: KebabCasedProperties<User> = {
|
|
24
|
+
'user-id': 1,
|
|
25
|
+
'user-name': 'Tom',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const splitOnNumbers: KebabCasedProperties<{line1: string}, {splitOnNumbers: true}> = {
|
|
29
|
+
'line-1': 'string',
|
|
30
|
+
};
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
@category Change case
|
|
34
|
+
@category Template literal
|
|
35
|
+
@category Object
|
|
36
|
+
*/
|
|
37
|
+
export type KebabCasedProperties<
|
|
38
|
+
Value,
|
|
39
|
+
Options extends WordsOptions = {},
|
|
40
|
+
> = DelimiterCasedProperties<Value, '-', ApplyDefaultOptions<WordsOptions, DefaultDelimiterCaseOptions, Options>>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type {UnionToIntersection} from './union-to-intersection';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Create a union of all keys from a given type, even those exclusive to specific union members.
|
|
5
|
+
|
|
6
|
+
Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
|
|
7
|
+
|
|
8
|
+
@link https://stackoverflow.com/a/49402091
|
|
9
|
+
|
|
10
|
+
@example
|
|
11
|
+
```
|
|
12
|
+
import type {KeysOfUnion} from 'type-fest';
|
|
13
|
+
|
|
14
|
+
type A = {
|
|
15
|
+
common: string;
|
|
16
|
+
a: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type B = {
|
|
20
|
+
common: string;
|
|
21
|
+
b: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type C = {
|
|
25
|
+
common: string;
|
|
26
|
+
c: boolean;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type Union = A | B | C;
|
|
30
|
+
|
|
31
|
+
type CommonKeys = keyof Union;
|
|
32
|
+
//=> 'common'
|
|
33
|
+
|
|
34
|
+
type AllKeys = KeysOfUnion<Union>;
|
|
35
|
+
//=> 'common' | 'a' | 'b' | 'c'
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
@category Object
|
|
39
|
+
*/
|
|
40
|
+
export type KeysOfUnion<ObjectType> =
|
|
41
|
+
// Hack to fix https://github.com/sindresorhus/type-fest/issues/1008
|
|
42
|
+
keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Extracts the type of the last element of an array.
|
|
3
|
+
|
|
4
|
+
Use-case: Defining the return type of functions that extract the last element of an array, for example [`lodash.last`](https://lodash.com/docs/4.17.15#last).
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import type {LastArrayElement} from 'type-fest';
|
|
9
|
+
|
|
10
|
+
declare function lastOf<V extends readonly any[]>(array: V): LastArrayElement<V>;
|
|
11
|
+
|
|
12
|
+
const array = ['foo', 2];
|
|
13
|
+
|
|
14
|
+
typeof lastOf(array);
|
|
15
|
+
//=> number
|
|
16
|
+
|
|
17
|
+
const array = ['foo', 2] as const;
|
|
18
|
+
|
|
19
|
+
typeof lastOf(array);
|
|
20
|
+
//=> 2
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
@category Array
|
|
24
|
+
@category Template literal
|
|
25
|
+
*/
|
|
26
|
+
export type LastArrayElement<Elements extends readonly unknown[], ElementBeforeTailingSpreadElement = never> =
|
|
27
|
+
// If the last element of an array is a spread element, the `LastArrayElement` result should be `'the type of the element before the spread element' | 'the type of the spread element'`.
|
|
28
|
+
Elements extends readonly []
|
|
29
|
+
? ElementBeforeTailingSpreadElement
|
|
30
|
+
: Elements extends readonly [...infer U, infer V]
|
|
31
|
+
? V
|
|
32
|
+
: Elements extends readonly [infer U, ...infer V]
|
|
33
|
+
// If we return `V[number] | U` directly, it would be wrong for `[[string, boolean, object, ...number[]]`.
|
|
34
|
+
// So we need to recurse type `V` and carry over the type of the element before the spread element.
|
|
35
|
+
? LastArrayElement<V, U>
|
|
36
|
+
: Elements extends ReadonlyArray<infer U>
|
|
37
|
+
? U | ElementBeforeTailingSpreadElement
|
|
38
|
+
: never;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type {GreaterThan} from './greater-than';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Returns a boolean for whether a given number is less than or equal to another number.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import type {LessThanOrEqual} from 'type-fest';
|
|
9
|
+
|
|
10
|
+
LessThanOrEqual<1, -5>;
|
|
11
|
+
//=> false
|
|
12
|
+
|
|
13
|
+
LessThanOrEqual<1, 1>;
|
|
14
|
+
//=> true
|
|
15
|
+
|
|
16
|
+
LessThanOrEqual<1, 5>;
|
|
17
|
+
//=> true
|
|
18
|
+
```
|
|
19
|
+
*/
|
|
20
|
+
export type LessThanOrEqual<A extends number, B extends number> = number extends A | B
|
|
21
|
+
? never
|
|
22
|
+
: GreaterThan<A, B> extends true ? false : true;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type {GreaterThanOrEqual} from './greater-than-or-equal';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Returns a boolean for whether a given number is less than another number.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import type {LessThan} from 'type-fest';
|
|
9
|
+
|
|
10
|
+
LessThan<1, -5>;
|
|
11
|
+
//=> false
|
|
12
|
+
|
|
13
|
+
LessThan<1, 1>;
|
|
14
|
+
//=> false
|
|
15
|
+
|
|
16
|
+
LessThan<1, 5>;
|
|
17
|
+
//=> true
|
|
18
|
+
```
|
|
19
|
+
*/
|
|
20
|
+
export type LessThan<A extends number, B extends number> = number extends A | B
|
|
21
|
+
? never
|
|
22
|
+
: GreaterThanOrEqual<A, B> extends infer Result
|
|
23
|
+
? Result extends true
|
|
24
|
+
? false
|
|
25
|
+
: true
|
|
26
|
+
: never; // Should never happen
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type {LiteralToPrimitive} from './literal-to-primitive';
|
|
2
|
+
import type {OmitIndexSignature} from './omit-index-signature';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
Like `LiteralToPrimitive` except it converts literal types inside an object or array deeply.
|
|
6
|
+
|
|
7
|
+
For example, given a constant object, it returns a new object type with the same keys but with all the values converted to primitives.
|
|
8
|
+
|
|
9
|
+
@see LiteralToPrimitive
|
|
10
|
+
|
|
11
|
+
Use-case: Deal with data that is imported from a JSON file.
|
|
12
|
+
|
|
13
|
+
@example
|
|
14
|
+
```
|
|
15
|
+
import type {LiteralToPrimitiveDeep, TsConfigJson} from 'type-fest';
|
|
16
|
+
import tsconfig from 'path/to/tsconfig.json';
|
|
17
|
+
|
|
18
|
+
function doSomethingWithTSConfig(config: LiteralToPrimitiveDeep<TsConfigJson>) { ... }
|
|
19
|
+
|
|
20
|
+
// No casting is needed to pass the type check
|
|
21
|
+
doSomethingWithTSConfig(tsconfig);
|
|
22
|
+
|
|
23
|
+
// If LiteralToPrimitiveDeep is not used, you need to cast the imported data like this:
|
|
24
|
+
doSomethingWithTSConfig(tsconfig as TsConfigJson);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
@category Type
|
|
28
|
+
@category Object
|
|
29
|
+
*/
|
|
30
|
+
export type LiteralToPrimitiveDeep<T> = T extends object
|
|
31
|
+
? T extends Array<infer U>
|
|
32
|
+
? Array<LiteralToPrimitiveDeep<U>>
|
|
33
|
+
: {
|
|
34
|
+
[K in keyof OmitIndexSignature<T>]: LiteralToPrimitiveDeep<T[K]>;
|
|
35
|
+
}
|
|
36
|
+
: LiteralToPrimitive<T>;
|