vtils

Home > types > CamelCase

CamelCase type

Convert a string literal to camel-case.

This can be useful when, for example, converting some kebab-cased command-line flags or a snake-cased database result.

Signature:

export declare type CamelCase<K> = K extends string ? CamelCaseStringArray<Split<K extends Uppercase<K> ? Lowercase<K> : K, WordSeparators>> : K;

Example

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

// Simple

const someVariable: CamelCase<‘foo-bar’> = ‘fooBar’;

// Advanced

type CamelCasedProperties = { \[K in keyof T as CamelCase\]: T\[K\] };

interface RawOptions { ‘dry-run’: boolean; ‘full_family_name’: string; foo: number; BAR: string; QUZ_QUX: number; ‘OTHER-FIELD’: boolean; }

const dbResult: CamelCasedProperties = { dryRun: true, fullFamilyName: 'bar.js', foo: 123, bar: 'foo', quzQux: 6, otherField: false }; \`\`\`

Template Literals