@@ -16,19 +16,19 @@ export function isUppercase(char = ""): boolean | undefined {
16
16
return char . toUpperCase ( ) === char ;
17
17
}
18
18
19
- export function splitByCase < T extends string > ( string_ : T ) : SplitByCase < T > ;
19
+ export function splitByCase < T extends string > ( str : T ) : SplitByCase < T > ;
20
20
export function splitByCase <
21
21
T extends string ,
22
22
Separator extends readonly string [ ] ,
23
- > ( string_ : T , separators : Separator ) : SplitByCase < T , Separator [ number ] > ;
23
+ > ( str : T , separators : Separator ) : SplitByCase < T , Separator [ number ] > ;
24
24
export function splitByCase <
25
25
T extends string ,
26
26
Separator extends readonly string [ ] ,
27
- > ( string_ : T , separators ?: Separator ) {
27
+ > ( str : T , separators ?: Separator ) {
28
28
const splitters = separators ?? STR_SPLITTERS ;
29
29
const parts : string [ ] = [ ] ;
30
30
31
- if ( ! string_ || typeof string_ !== "string" ) {
31
+ if ( ! str || typeof str !== "string" ) {
32
32
return parts as SplitByCase < T , Separator [ number ] > ;
33
33
}
34
34
@@ -37,7 +37,7 @@ export function splitByCase<
37
37
let previousUpper : boolean | undefined ;
38
38
let previousSplitter : boolean | undefined ;
39
39
40
- for ( const char of string_ ) {
40
+ for ( const char of str ) {
41
41
// Splitter
42
42
const isSplitter = ( splitters as unknown as string ) . includes ( char ) ;
43
43
if ( isSplitter === true ) {
@@ -77,63 +77,59 @@ export function splitByCase<
77
77
return parts as SplitByCase < T , Separator [ number ] > ;
78
78
}
79
79
80
- export function upperFirst < S extends string > ( string_ : S ) : Capitalize < S > {
81
- return (
82
- string_ ? string_ [ 0 ] . toUpperCase ( ) + string_ . slice ( 1 ) : ""
83
- ) as Capitalize < S > ;
80
+ export function upperFirst < S extends string > ( str : S ) : Capitalize < S > {
81
+ return ( str ? str [ 0 ] . toUpperCase ( ) + str . slice ( 1 ) : "" ) as Capitalize < S > ;
84
82
}
85
83
86
- export function lowerFirst < S extends string > ( string_ : S ) : Uncapitalize < S > {
87
- return (
88
- string_ ? string_ [ 0 ] . toLowerCase ( ) + string_ . slice ( 1 ) : ""
89
- ) as Uncapitalize < S > ;
84
+ export function lowerFirst < S extends string > ( str : S ) : Uncapitalize < S > {
85
+ return ( str ? str [ 0 ] . toLowerCase ( ) + str . slice ( 1 ) : "" ) as Uncapitalize < S > ;
90
86
}
91
87
92
88
export function pascalCase ( ) : "" ;
93
89
export function pascalCase < T extends string | readonly string [ ] > (
94
- string_ : T ,
90
+ str : T ,
95
91
) : PascalCase < T > ;
96
- export function pascalCase < T extends string | readonly string [ ] > ( string_ ?: T ) {
97
- return string_
98
- ? ( ( Array . isArray ( string_ ) ? string_ : splitByCase ( string_ as string ) )
92
+ export function pascalCase < T extends string | readonly string [ ] > ( str ?: T ) {
93
+ return str
94
+ ? ( ( Array . isArray ( str ) ? str : splitByCase ( str as string ) )
99
95
. map ( ( p ) => upperFirst ( p ) )
100
96
. join ( "" ) as PascalCase < T > )
101
97
: "" ;
102
98
}
103
99
104
100
export function camelCase ( ) : "" ;
105
101
export function camelCase < T extends string | readonly string [ ] > (
106
- string_ : T ,
102
+ str : T ,
107
103
) : CamelCase < T > ;
108
- export function camelCase < T extends string | readonly string [ ] > ( string_ ?: T ) {
109
- return lowerFirst ( pascalCase ( string_ || "" ) ) as CamelCase < T > ;
104
+ export function camelCase < T extends string | readonly string [ ] > ( str ?: T ) {
105
+ return lowerFirst ( pascalCase ( str || "" ) ) as CamelCase < T > ;
110
106
}
111
107
112
108
export function kebabCase ( ) : "" ;
113
109
export function kebabCase < T extends string | readonly string [ ] > (
114
- string_ : T ,
110
+ str : T ,
115
111
) : KebabCase < T > ;
116
112
export function kebabCase <
117
113
T extends string | readonly string [ ] ,
118
114
Joiner extends string ,
119
- > ( string_ : T , joiner : Joiner ) : KebabCase < T , Joiner > ;
115
+ > ( str : T , joiner : Joiner ) : KebabCase < T , Joiner > ;
120
116
export function kebabCase <
121
117
T extends string | readonly string [ ] ,
122
118
Joiner extends string ,
123
- > ( string_ ?: T , joiner ?: Joiner ) {
124
- return string_
125
- ? ( ( Array . isArray ( string_ ) ? string_ : splitByCase ( string_ as string ) )
119
+ > ( str ?: T , joiner ?: Joiner ) {
120
+ return str
121
+ ? ( ( Array . isArray ( str ) ? str : splitByCase ( str as string ) )
126
122
. map ( ( p ) => p . toLowerCase ( ) )
127
123
. join ( joiner ?? "-" ) as KebabCase < T , Joiner > )
128
124
: "" ;
129
125
}
130
126
131
127
export function snakeCase ( ) : "" ;
132
128
export function snakeCase < T extends string | readonly string [ ] > (
133
- string_ : T ,
129
+ str : T ,
134
130
) : SnakeCase < T > ;
135
- export function snakeCase < T extends string | readonly string [ ] > ( string_ ?: T ) {
136
- return kebabCase ( string_ || "" , "_" ) as SnakeCase < T > ;
131
+ export function snakeCase < T extends string | readonly string [ ] > ( str ?: T ) {
132
+ return kebabCase ( str || "" , "_" ) as SnakeCase < T > ;
137
133
}
138
134
139
135
export * from "./types" ;
0 commit comments