Skip to content

Commit 852d016

Browse files
jericirenejsom-smsindresorhus
authored
Add splitOnPunctuation option to {Camel,Pascal,Kebab,Snake}Cased types (#1394)
Co-authored-by: Som Shekhar Mukherjee <iamssmkhrj@gmail.com> Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
1 parent 7373aba commit 852d016

26 files changed

+306
-10
lines changed

source/camel-case.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {ApplyDefaultOptions} from './internal/index.d.ts';
2-
import type {Words, WordsOptions} from './words.d.ts';
2+
import type {_DefaultWordsOptions, Words, WordsOptions} from './words.d.ts';
33

44
/**
55
CamelCase options.
@@ -15,8 +15,7 @@ export type CamelCaseOptions = WordsOptions & {
1515
preserveConsecutiveUppercase?: boolean;
1616
};
1717

18-
export type _DefaultCamelCaseOptions = {
19-
splitOnNumbers: true;
18+
export type _DefaultCamelCaseOptions = _DefaultWordsOptions & {
2019
preserveConsecutiveUppercase: false;
2120
};
2221

@@ -51,6 +50,7 @@ import type {CamelCase} from 'type-fest';
5150
5251
const someVariable: CamelCase<'foo-bar'> = 'fooBar';
5352
const preserveConsecutiveUppercase: CamelCase<'foo-BAR-baz', {preserveConsecutiveUppercase: true}> = 'fooBARBaz';
53+
const splitOnPunctuation: CamelCase<'foo-bar:BAZ', {splitOnPunctuation: true}> = 'fooBarBaz';
5454
5555
// Advanced
5656

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ const preserveConsecutiveUppercase: CamelCasedPropertiesDeep<{fooBAR: {fooBARBiz
4848
}],
4949
},
5050
};
51+
52+
const splitOnPunctuation: CamelCasedPropertiesDeep<{'user@info': {'user::id': number; 'user::name': string}}, {splitOnPunctuation: true}> = {
53+
userInfo: {
54+
userId: 1,
55+
userName: 'Tom',
56+
},
57+
};
5158
```
5259
5360
@category Change case

source/camel-cased-properties.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const result: CamelCasedProperties<User> = {
2626
const preserveConsecutiveUppercase: CamelCasedProperties<{fooBAR: string}, {preserveConsecutiveUppercase: true}> = {
2727
fooBAR: 'string',
2828
};
29+
30+
const splitOnPunctuation: CamelCasedProperties<{'foo::bar': string}, {splitOnPunctuation: true}> = {
31+
fooBar: 'string',
32+
};
2933
```
3034
3135
@category Change case

source/kebab-case.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {KebabCase} from 'type-fest';
1515
1616
const someVariable: KebabCase<'fooBar'> = 'foo-bar';
1717
const someVariableNoSplitOnNumbers: KebabCase<'p2pNetwork', {splitOnNumbers: false}> = 'p2p-network';
18+
const someVariableWithPunctuation: KebabCase<'div.card::after', {splitOnPunctuation: true}> = 'div-card-after';
1819
1920
// Advanced
2021

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ const splitOnNumbers: KebabCasedPropertiesDeep<{line1: {line2: [{line3: string}]
5151
],
5252
},
5353
};
54+
55+
const splitOnPunctuation: KebabCasedPropertiesDeep<{'user@info': {'user::id': number; 'user::name': string}}, {splitOnPunctuation: true}> = {
56+
'user-info': {
57+
'user-id': 1,
58+
'user-name': 'Tom',
59+
},
60+
};
5461
```
5562
5663
@category Change case

source/kebab-cased-properties.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ const result: KebabCasedProperties<User> = {
2828
const splitOnNumbers: KebabCasedProperties<{line1: string}, {splitOnNumbers: true}> = {
2929
'line-1': 'string',
3030
};
31+
32+
const splitOnPunctuation: KebabCasedProperties<{'foo::bar': string}, {splitOnPunctuation: true}> = {
33+
'foo-bar': 'string',
34+
};
3135
```
3236
3337
@category Change case

source/pascal-case.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {PascalCase} from 'type-fest';
1212
1313
const someVariable: PascalCase<'foo-bar'> = 'FooBar';
1414
const preserveConsecutiveUppercase: PascalCase<'foo-BAR-baz', {preserveConsecutiveUppercase: true}> = 'FooBARBaz';
15+
const splitOnPunctuation: PascalCase<'foo-bar>>baz', {splitOnPunctuation: true}> = 'FooBarBaz';
1516
1617
// Advanced
1718

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ const preserveConsecutiveUppercase: PascalCasedPropertiesDeep<{fooBAR: {fooBARBi
4848
}],
4949
},
5050
};
51+
52+
const splitOnPunctuation: PascalCasedPropertiesDeep<{'user@info': {'user::id': number; 'user::name': string}}, {splitOnPunctuation: true}> = {
53+
UserInfo: {
54+
UserId: 1,
55+
UserName: 'Tom',
56+
},
57+
};
5158
```
5259
5360
@category Change case

source/pascal-cased-properties.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ const result: PascalCasedProperties<User> = {
2727
const preserveConsecutiveUppercase: PascalCasedProperties<{fooBAR: string}, {preserveConsecutiveUppercase: true}> = {
2828
FooBAR: 'string',
2929
};
30+
31+
const splitOnPunctuation: PascalCasedProperties<{'foo::bar': string}, {splitOnPunctuation: true}> = {
32+
FooBar: 'string',
33+
};
3034
```
3135
3236
@category Change case

source/snake-case.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {SnakeCase} from 'type-fest';
1616
const someVariable: SnakeCase<'fooBar'> = 'foo_bar';
1717
const noSplitOnNumbers: SnakeCase<'p2pNetwork'> = 'p2p_network';
1818
const splitOnNumbers: SnakeCase<'p2pNetwork', {splitOnNumbers: true}> = 'p_2_p_network';
19+
const splitOnPunctuation: SnakeCase<'div.card::after', {splitOnPunctuation: true}> = 'div_card_after';
1920
2021
// Advanced
2122

0 commit comments

Comments
 (0)