vtils

Home > types > DelimiterCase

DelimiterCase type

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.

Signature:

export declare type DelimiterCase<Value, Delimiter extends string> = Value extends string
	? StringArrayToDelimiterCase<
		SplitIncludingDelimiters<Value, WordSeparators | UpperCaseCharacters>,
		true,
		WordSeparators,
		UpperCaseCharacters,
		Delimiter
	>
	: Value;

Example

``` import {DelimiterCase} from ‘type-fest’;

// Simple

const someVariable: DelimiterCase<‘fooBar’, ‘#’> = ‘foo#bar’;

// Advanced

type OddlyCasedProperties = { \[K in keyof T as DelimiterCase<K, '\#'>\]: T\[K\] };

interface SomeOptions { dryRun: boolean; includeFile: string; foo: number; }

const rawCliOptions: OddlyCasedProperties = { 'dry\#run': true, 'include\#file': 'bar.js', foo: 123 }; \`\`\`

Template Literals