persona-community-5/.pnpm-store/v3/files/71/7366ad07da7f1f15640853a0e0f724501adf66923f62a9dcd68bb6cf3020b215dd6cdb38e8bf15c3b5b752473c244200d134d4cc469663bcdff967d088f7ef
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

79 lines
2.0 KiB
Plaintext

import type {ApplyDefaultOptions, AsciiPunctuation, StartsWith} from './internal';
import type {IsStringLiteral} from './is-literal';
import type {Merge} from './merge';
import type {DefaultWordsOptions, Words, WordsOptions} from './words';
export type DefaultDelimiterCaseOptions = Merge<DefaultWordsOptions, {splitOnNumbers: false}>;
/**
Convert an array of words to delimiter case starting with a delimiter with input capitalization.
*/
type DelimiterCaseFromArray<
Words extends string[],
Delimiter extends string,
OutputString extends string = '',
> = Words extends [
infer FirstWord extends string,
...infer RemainingWords extends string[],
]
? DelimiterCaseFromArray<RemainingWords, Delimiter, `${OutputString}${
StartsWith<FirstWord, AsciiPunctuation> extends true ? '' : Delimiter
}${FirstWord}`>
: OutputString;
type RemoveFirstLetter<S extends string> = S extends `${infer _}${infer Rest}`
? Rest
: '';
/**
Convert a string literal to a custom string delimiter casing.
This can be useful when, for example, converting a camel-cased object property to an oddly cased one.
@see KebabCase
@see SnakeCase
@example
```
import type {DelimiterCase} from 'type-fest';
// Simple
const someVariable: DelimiterCase<'fooBar', '#'> = 'foo#bar';
const someVariableNoSplitOnNumbers: DelimiterCase<'p2pNetwork', '#', {splitOnNumbers: false}> = 'p2p#network';
// Advanced
type OddlyCasedProperties<T> = {
[K in keyof T as DelimiterCase<K, '#'>]: T[K]
};
interface SomeOptions {
dryRun: boolean;
includeFile: string;
foo: number;
}
const rawCliOptions: OddlyCasedProperties<SomeOptions> = {
'dry#run': true,
'include#file': 'bar.js',
foo: 123
};
```
@category Change case
@category Template literal
*/
export type DelimiterCase<
Value,
Delimiter extends string,
Options extends WordsOptions = {},
> = Value extends string
? IsStringLiteral<Value> extends false
? Value
: Lowercase<RemoveFirstLetter<DelimiterCaseFromArray<
Words<Value, ApplyDefaultOptions<WordsOptions, DefaultDelimiterCaseOptions, Options>>,
Delimiter
>>>
: Value;