forked from sindresorhus/type-fest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpascal-case.ts
More file actions
35 lines (25 loc) · 1.6 KB
/
pascal-case.ts
File metadata and controls
35 lines (25 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import {expectType} from 'tsd';
import type {PascalCase} from '../index.d.ts';
const pascalFromCamel: PascalCase<'fooBar'> = 'FooBar';
expectType<'FooBar'>(pascalFromCamel);
const pascalFromKebab: PascalCase<'foo-bar'> = 'FooBar';
expectType<'FooBar'>(pascalFromKebab);
const pascalFromComplexKebab: PascalCase<'foo-bar-abc-123'> = 'FooBarAbc123';
expectType<'FooBarAbc123'>(pascalFromComplexKebab);
expectType<PascalCase<'fooBAR'>>('FooBar');
expectType<PascalCase<'fooBAR', {preserveConsecutiveUppercase: true}>>('FooBAR');
expectType<PascalCase<'fooBARBiz'>>('FooBarBiz');
expectType<PascalCase<'fooBARBiz', {preserveConsecutiveUppercase: true}>>('FooBARBiz');
expectType<PascalCase<'foo BAR-Biz_BUZZ', {preserveConsecutiveUppercase: true}>>('FooBARBizBUZZ');
expectType<PascalCase<'foo BAR-Biz_BUZZ', {preserveConsecutiveUppercase: false}>>('FooBarBizBuzz');
expectType<PascalCase<'foo\tBAR-Biz_BUZZ'>>('FooBarBizBuzz');
expectType<PascalCase<string, {preserveConsecutiveUppercase: true}>>({} as Capitalize<string>);
expectType<PascalCase<string>>({} as Capitalize<string>);
// Punctuation
expectType<PascalCase<'onDialog:close'>>('OnDialog:close');
expectType<PascalCase<'foo-bar>>baz'>>('FooBar>>baz');
expectType<PascalCase<'foo-bar::01'>>('FooBar::01');
expectType<PascalCase<'onDialog:close', {splitOnPunctuation: true}>>('OnDialogClose');
expectType<PascalCase<'foo-bar>>baz', {splitOnPunctuation: true}>>('FooBarBaz');
expectType<PascalCase<'fooBAR:biz', {splitOnPunctuation: true; preserveConsecutiveUppercase: true}>>('FooBARBiz');
expectType<PascalCase<'foo-bar::01', {splitOnPunctuation: true}>>('FooBar01');