@@ -8,8 +8,8 @@ import { getWords } from './.internal/getWords'
88 * capitalizeInitial('hello'); // 'Hello'
99 * capitalizeInitial(':> hello'); // ':> Hello'
1010 */
11- function capitalizeInitial ( str : string ) : string {
12- return str . replace ( / \b \w / , ( char : string ) => char . toUpperCase ( ) )
11+ function capitalizeInitial ( str : string , locales ?: Intl . LocalesArgument ) : string {
12+ return str . replace ( / \b \w / , ( char : string ) => char . toLocaleUpperCase ( locales ) )
1313}
1414
1515/**
@@ -22,8 +22,8 @@ function capitalizeInitial(str: string): string {
2222 * capitalizeWords('Sphinx of black quartz:-judge my vow');
2323 * // 'Sphinx Of Black Quartz:-Judge My Vow'
2424 */
25- function capitalizeWords ( str : string ) : string {
26- return str . replace ( / \b \w / g, ( char : string ) => char . toUpperCase ( ) )
25+ function capitalizeWords ( str : string , locales ?: Intl . LocalesArgument ) : string {
26+ return str . replace ( / \b \w / g, ( char : string ) => char . toLocaleUpperCase ( locales ) )
2727}
2828
2929/**
@@ -150,9 +150,9 @@ function isPascalCase(str: string): boolean {
150150 * snakeCase('from-kebab-case'); // 'from_kebab_case'
151151 * snakeCase('snake Case With Numbers123', true); // 'snake_case_with_numbers_one_two_three'
152152 */
153- function snakeCase ( str : string , inWords = false ) : string {
154- if ( isCamelCase ( str ) ) return getWords ( str , 'camel' ) . join ( '_' ) . toLowerCase ( )
155- if ( isPascalCase ( str ) ) return getWords ( str , 'pascal' ) . join ( '_' ) . toLowerCase ( )
153+ function snakeCase ( str : string , inWords = false , locales ?: Intl . LocalesArgument ) : string {
154+ if ( isCamelCase ( str ) ) return getWords ( str , 'camel' ) . join ( '_' ) . toLocaleLowerCase ( locales )
155+ if ( isPascalCase ( str ) ) return getWords ( str , 'pascal' ) . join ( '_' ) . toLocaleLowerCase ( locales )
156156
157157 const numbersInWords = [ 'zero' , 'one' , 'two' , 'three' , 'four' , 'five' , 'six' , 'seven' , 'eight' , 'nine' ]
158158 if ( inWords ) {
@@ -161,7 +161,7 @@ function snakeCase(str: string, inWords = false): string {
161161 }
162162 }
163163
164- return getWords ( str ) . join ( '_' ) . toLowerCase ( )
164+ return getWords ( str ) . join ( '_' ) . toLocaleLowerCase ( locales )
165165}
166166
167167/**
@@ -174,9 +174,9 @@ function snakeCase(str: string, inWords = false): string {
174174 * kebabCase('from_snake_case'); // 'from-snake-case'
175175 * kebabCase('kebab Case With Numbers123', true); // 'kebab-case-with-numbers-one-two-three'
176176 */
177- function kebabCase ( str : string , inWords = false ) : string {
178- if ( isCamelCase ( str ) ) return getWords ( str , 'camel' ) . join ( '-' ) . toLowerCase ( )
179- if ( isPascalCase ( str ) ) return getWords ( str , 'pascal' ) . join ( '-' ) . toLowerCase ( )
177+ function kebabCase ( str : string , inWords = false , locales ?: Intl . LocalesArgument ) : string {
178+ if ( isCamelCase ( str ) ) return getWords ( str , 'camel' ) . join ( '-' ) . toLocaleLowerCase ( locales )
179+ if ( isPascalCase ( str ) ) return getWords ( str , 'pascal' ) . join ( '-' ) . toLocaleLowerCase ( locales )
180180
181181 const numbersInWords = [ 'zero' , 'one' , 'two' , 'three' , 'four' , 'five' , 'six' , 'seven' , 'eight' , 'nine' ]
182182 if ( inWords ) {
@@ -185,7 +185,7 @@ function kebabCase(str: string, inWords = false): string {
185185 }
186186 }
187187
188- return getWords ( str ) . join ( '-' ) . toLowerCase ( )
188+ return getWords ( str ) . join ( '-' ) . toLocaleLowerCase ( locales )
189189}
190190
191191/**
@@ -197,14 +197,16 @@ function kebabCase(str: string, inWords = false): string {
197197 * camelCase('Test CaSe ExamplE'); // 'testCaseExample'
198198 * camelCase('camel Case With Numbers123'); // 'camelCaseWithNumbers'
199199 */
200- function camelCase ( str : string ) : string {
200+ function camelCase ( str : string , locales ?: Intl . LocalesArgument ) : string {
201201 str = str . replace ( / [ ^ a - z A - Z ] / g, ' ' )
202202 if ( isCamelCase ( str ) ) return str
203- if ( isPascalCase ( str ) ) return str . charAt ( 0 ) . toLowerCase ( ) + str . substring ( 1 )
203+ if ( isPascalCase ( str ) ) return str . charAt ( 0 ) . toLocaleLowerCase ( locales ) + str . substring ( 1 )
204204 return getWords ( str ) . reduce ( ( prev : string , curVal : string , i : number ) : string =>
205205 i !== 1
206- ? prev + curVal . charAt ( 0 ) . toUpperCase ( ) + curVal . substring ( 1 ) . toLowerCase ( )
207- : prev . toLowerCase ( ) + curVal . charAt ( 0 ) . toUpperCase ( ) + curVal . substring ( 1 ) . toLowerCase ( )
206+ ? prev + curVal . charAt ( 0 ) . toLocaleUpperCase ( locales ) + curVal . substring ( 1 ) . toLocaleLowerCase ( locales )
207+ : prev . toLocaleLowerCase ( locales ) +
208+ curVal . charAt ( 0 ) . toLocaleUpperCase ( locales ) +
209+ curVal . substring ( 1 ) . toLocaleLowerCase ( locales )
208210 )
209211}
210212
@@ -217,13 +219,13 @@ function camelCase(str: string): string {
217219 * pascalCase('Test CaSe ExamplE'); // 'TestCaseExample'
218220 * pascalCase('pasCal Case With Numbers123'); // 'PascalCaseWithNumbers'
219221 */
220- function pascalCase ( str : string ) : string {
222+ function pascalCase ( str : string , locales ?: Intl . LocalesArgument ) : string {
221223 str = str . replace ( / [ ^ a - z A - Z ] / g, ' ' )
222224 if ( isPascalCase ( str ) ) return str
223- if ( isCamelCase ( str ) ) return str . charAt ( 0 ) . toUpperCase ( ) + str . substring ( 1 )
225+ if ( isCamelCase ( str ) ) return str . charAt ( 0 ) . toLocaleUpperCase ( locales ) + str . substring ( 1 )
224226 return getWords ( str ) . reduce (
225227 ( prev : string , curVal : string ) : string =>
226- prev + curVal . charAt ( 0 ) . toUpperCase ( ) + curVal . substring ( 1 ) . toLowerCase ( ) ,
228+ prev + curVal . charAt ( 0 ) . toLocaleUpperCase ( locales ) + curVal . substring ( 1 ) . toLocaleLowerCase ( locales ) ,
227229
228230 ''
229231 )
0 commit comments