-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathpascal-case.d.ts
More file actions
52 lines (41 loc) · 1.32 KB
/
pascal-case.d.ts
File metadata and controls
52 lines (41 loc) · 1.32 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import type {CamelCase, CamelCaseOptions, _DefaultCamelCaseOptions} from './camel-case.d.ts';
import type {ApplyDefaultOptions} from './internal/index.d.ts';
/**
Convert a string literal to pascal-case.
@example
```
import type {PascalCase} from 'type-fest';
// Simple
const someVariable: PascalCase<'foo-bar'> = 'FooBar';
const preserveConsecutiveUppercase: PascalCase<'foo-BAR-baz', {preserveConsecutiveUppercase: true}> = 'FooBARBaz';
const splitOnPunctuation: PascalCase<'foo-bar>>baz', {splitOnPunctuation: true}> = 'FooBarBaz';
// Advanced
type PascalCasedProperties<T> = {
[K in keyof T as PascalCase<K>]: T[K]
};
type RawOptions = {
'dry-run': boolean;
'full_family_name': string;
foo: number;
BAR: string;
QUZ_QUX: number;
'OTHER-FIELD': boolean;
};
const dbResult: PascalCasedProperties<RawOptions> = {
DryRun: true,
FullFamilyName: 'bar.js',
Foo: 123,
Bar: 'foo',
QuzQux: 6,
OtherField: false,
};
```
@category Change case
@category Template literal
*/
export type PascalCase<Value, Options extends CamelCaseOptions = {}> =
_PascalCase<Value, ApplyDefaultOptions<CamelCaseOptions, _DefaultCamelCaseOptions, Options>>;
type _PascalCase<Value, Options extends Required<CamelCaseOptions>> = CamelCase<Value, Options> extends string
? Capitalize<CamelCase<Value, Options>>
: CamelCase<Value, Options>;
export {};