forked from sindresorhus/type-fest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpascal-case.d.ts
More file actions
57 lines (44 loc) · 1.3 KB
/
pascal-case.d.ts
File metadata and controls
57 lines (44 loc) · 1.3 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
53
54
55
56
57
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
type PascalCase1 = PascalCase<'foo-bar'>;
//=> 'FooBar'
type PascalCase2 = PascalCase<'foo-BAR-baz', {preserveConsecutiveUppercase: true}>;
//=> 'FooBARBaz'
type PascalCase3 = 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 {};