Skip to content

Commit 8226c1b

Browse files
authored
CamelCase / CamelCasedProperties / CamelCasedPropertiesDeep / PascalCase / PascalCasedProperties / PascalCasedPropertiesDeep: Disable preserveConsecutiveUppercase option by default (#1130)
1 parent 1e73c2f commit 8226c1b

12 files changed

+69
-23
lines changed

source/camel-case.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ export type CamelCaseOptions = {
1010
/**
1111
Whether to preserved consecutive uppercase letter.
1212
13-
@default true
13+
@default false
1414
*/
1515
preserveConsecutiveUppercase?: boolean;
1616
};
1717

1818
export type DefaultCamelCaseOptions = {
19-
preserveConsecutiveUppercase: true;
19+
preserveConsecutiveUppercase: false;
2020
};
2121

2222
/**

source/camel-cased-properties-deep.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ const result: CamelCasedPropertiesDeep<UserWithFriends> = {
4141
],
4242
};
4343
44-
const preserveConsecutiveUppercase: CamelCasedPropertiesDeep<{fooBAR: { fooBARBiz: [{ fooBARBaz: string }] }}, {preserveConsecutiveUppercase: false}> = {
45-
fooBar: {
46-
fooBarBiz: [{
47-
fooBarBaz: 'string',
44+
const preserveConsecutiveUppercase: CamelCasedPropertiesDeep<{fooBAR: {fooBARBiz: [{fooBARBaz: string}]}}, {preserveConsecutiveUppercase: true}> = {
45+
fooBAR: {
46+
fooBARBiz: [{
47+
fooBARBaz: 'string',
4848
}],
4949
},
5050
};

source/camel-cased-properties.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const result: CamelCasedProperties<User> = {
2323
userName: 'Tom',
2424
};
2525
26-
const preserveConsecutiveUppercase: CamelCasedProperties<{fooBAR: string}, {preserveConsecutiveUppercase: false}> = {
27-
fooBar: 'string',
26+
const preserveConsecutiveUppercase: CamelCasedProperties<{fooBAR: string}, {preserveConsecutiveUppercase: true}> = {
27+
fooBAR: 'string',
2828
};
2929
```
3030

source/pascal-case.d.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,30 @@ import type {PascalCase} from 'type-fest';
1111
// Simple
1212
1313
const someVariable: PascalCase<'foo-bar'> = 'FooBar';
14+
const preserveConsecutiveUppercase: PascalCase<'foo-BAR-baz', {preserveConsecutiveUppercase: true}> = 'FooBARBaz';
1415
1516
// Advanced
1617
17-
type PascalCaseProps<T> = {
18+
type PascalCasedProperties<T> = {
1819
[K in keyof T as PascalCase<K>]: T[K]
1920
};
2021
2122
interface RawOptions {
2223
'dry-run': boolean;
2324
'full_family_name': string;
2425
foo: number;
25-
}
26+
BAR: string;
27+
QUZ_QUX: number;
28+
'OTHER-FIELD': boolean;
29+
};
2630
27-
const dbResult: CamelCasedProperties<ModelProps> = {
31+
const dbResult: PascalCasedProperties<RawOptions> = {
2832
DryRun: true,
2933
FullFamilyName: 'bar.js',
30-
Foo: 123
34+
Foo: 123,
35+
Bar: 'foo',
36+
QuzQux: 6,
37+
OtherField: false,
3138
};
3239
```
3340

source/pascal-cased-properties-deep.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ const result: PascalCasedPropertiesDeep<UserWithFriends> = {
4040
},
4141
],
4242
};
43+
44+
const preserveConsecutiveUppercase: PascalCasedPropertiesDeep<{fooBAR: {fooBARBiz: [{fooBARBaz: string}]}}, {preserveConsecutiveUppercase: true}> = {
45+
FooBAR: {
46+
FooBARBiz: [{
47+
FooBARBaz: 'string',
48+
}],
49+
},
50+
};
4351
```
4452
4553
@category Change case

source/pascal-cased-properties.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const result: PascalCasedProperties<User> = {
2323
UserId: 1,
2424
UserName: 'Tom',
2525
};
26+
27+
const preserveConsecutiveUppercase: PascalCasedProperties<{fooBAR: string}, {preserveConsecutiveUppercase: true}> = {
28+
FooBAR: 'string',
29+
};
2630
```
2731
2832
@category Change case

test-d/camel-case.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ expectAssignable<CamelCasedProperties<RawOptions>>({
6767
otherField: false,
6868
});
6969

70-
expectType<CamelCase<'fooBAR'>>('fooBAR');
71-
expectType<CamelCase<'fooBAR', {preserveConsecutiveUppercase: false}>>('fooBar');
70+
expectType<CamelCase<'fooBAR'>>('fooBar');
71+
expectType<CamelCase<'fooBAR', {preserveConsecutiveUppercase: true}>>('fooBAR');
7272

73-
expectType<CamelCase<'fooBARBiz'>>('fooBARBiz');
74-
expectType<CamelCase<'fooBARBiz', {preserveConsecutiveUppercase: false}>>('fooBarBiz');
73+
expectType<CamelCase<'fooBARBiz'>>('fooBarBiz');
74+
expectType<CamelCase<'fooBARBiz', {preserveConsecutiveUppercase: true}>>('fooBARBiz');
7575

76-
expectType<CamelCase<'foo BAR-Biz_BUZZ'>>('fooBARBizBUZZ');
76+
expectType<CamelCase<'foo BAR-Biz_BUZZ', {preserveConsecutiveUppercase: true}>>('fooBARBizBUZZ');
7777
expectType<CamelCase<'foo BAR-Biz_BUZZ', {preserveConsecutiveUppercase: false}>>('fooBarBizBuzz');
78-
expectType<CamelCase<'foo\tBAR-Biz_BUZZ', {preserveConsecutiveUppercase: false}>>('fooBarBizBuzz');
78+
expectType<CamelCase<'foo\tBAR-Biz_BUZZ'>>('fooBarBizBuzz');
7979

80+
expectType<CamelCase<string, {preserveConsecutiveUppercase: true}>>('string' as string);
8081
expectType<CamelCase<string>>('string' as string);
81-
expectType<CamelCase<string, {preserveConsecutiveUppercase: false}>>('string' as string);

test-d/camel-cased-properties-deep.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ expectType<Set<{fooBar: string}>>(bar);
1313

1414
type bazBizDeep = {fooBAR: number; baz: {fooBAR: Array<{BARFoo: string}>}};
1515

16-
declare const baz: CamelCasedPropertiesDeep<bazBizDeep>;
16+
declare const baz: CamelCasedPropertiesDeep<bazBizDeep, {preserveConsecutiveUppercase: true}>;
1717
expectType<{fooBAR: number; baz: {fooBAR: Array<{bARFoo: string}>}}>(baz);
1818

19-
declare const biz: CamelCasedPropertiesDeep<bazBizDeep, {preserveConsecutiveUppercase: false}>;
19+
declare const biz: CamelCasedPropertiesDeep<bazBizDeep>;
2020
expectType<{fooBar: number; baz: {fooBar: Array<{barFoo: string}>}}>(biz);
2121

2222
declare const tuple: CamelCasedPropertiesDeep<{tuple: [number, string, {D: string}]}>;

test-d/camel-cased-properties.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ expectType<Array<{helloWorld: string}>>(bar);
1010
declare const fooBar: CamelCasedProperties<() => {a: string}>;
1111
expectType<() => {a: string}>(fooBar);
1212

13-
declare const baz: CamelCasedProperties<{fooBAR: number; BARFoo: string}>;
13+
declare const baz: CamelCasedProperties<{fooBAR: number; BARFoo: string}, {preserveConsecutiveUppercase: true}>;
1414
expectType<{fooBAR: number; bARFoo: string}>(baz);
1515

16-
declare const biz: CamelCasedProperties<{fooBAR: number; BARFoo: string}, {preserveConsecutiveUppercase: false}>;
16+
declare const biz: CamelCasedProperties<{fooBAR: number; BARFoo: string}>;
1717
expectType<{fooBar: number; barFoo: string}>(biz);
1818

1919
// Verify example

test-d/pascal-case.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,16 @@ expectType<'FooBar'>(pascalFromKebab);
99

1010
const pascalFromComplexKebab: PascalCase<'foo-bar-abc-123'> = 'FooBarAbc123';
1111
expectType<'FooBarAbc123'>(pascalFromComplexKebab);
12+
13+
expectType<PascalCase<'fooBAR'>>('FooBar');
14+
expectType<PascalCase<'fooBAR', {preserveConsecutiveUppercase: true}>>('FooBAR');
15+
16+
expectType<PascalCase<'fooBARBiz'>>('FooBarBiz');
17+
expectType<PascalCase<'fooBARBiz', {preserveConsecutiveUppercase: true}>>('FooBARBiz');
18+
19+
expectType<PascalCase<'foo BAR-Biz_BUZZ', {preserveConsecutiveUppercase: true}>>('FooBARBizBUZZ');
20+
expectType<PascalCase<'foo BAR-Biz_BUZZ', {preserveConsecutiveUppercase: false}>>('FooBarBizBuzz');
21+
expectType<PascalCase<'foo\tBAR-Biz_BUZZ'>>('FooBarBizBuzz');
22+
23+
expectType<PascalCase<string, {preserveConsecutiveUppercase: true}>>({} as Capitalize<string>);
24+
expectType<PascalCase<string>>({} as Capitalize<string>);

0 commit comments

Comments
 (0)