Skip to content

Commit 55f069a

Browse files
authored
Probably gonna fix sindresorhus#72
I have added optional 'locale' option to `options`
1 parent 20591fb commit 55f069a

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

index.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

3-
const preserveCamelCase = string => {
3+
4+
const preserveCamelCase = (string, locale) => {
45
let isLastCharLower = false;
56
let isLastCharUpper = false;
67
let isLastLastCharUpper = false;
@@ -20,9 +21,9 @@ const preserveCamelCase = string => {
2021
isLastCharUpper = false;
2122
isLastCharLower = true;
2223
} else {
23-
isLastCharLower = character.toLocaleLowerCase() === character && character.toLocaleUpperCase() !== character;
24+
isLastCharLower = character.toLocaleLowerCase(locale) === character && character.toLocaleUpperCase(locale) !== character;
2425
isLastLastCharUpper = isLastCharUpper;
25-
isLastCharUpper = character.toLocaleUpperCase() === character && character.toLocaleLowerCase() !== character;
26+
isLastCharUpper = character.toLocaleUpperCase(locale) === character && character.toLocaleLowerCase(locale) !== character;
2627
}
2728
}
2829

@@ -35,11 +36,11 @@ const camelCase = (input, options) => {
3536
}
3637

3738
options = {
38-
...{pascalCase: false},
39+
...{pascalCase: false, locale: null},
3940
...options
4041
};
41-
42-
const postProcess = x => options.pascalCase ? x.charAt(0).toLocaleUpperCase() + x.slice(1) : x;
42+
const locale = (options.locale != null) ? options.locale : undefined; // It's going to use default if locale option is null
43+
const postProcess = x => options.pascalCase ? x.charAt(0).toLocaleUpperCase(locale) + x.slice(1) : x;
4344

4445
if (Array.isArray(input)) {
4546
input = input.map(x => x.trim())
@@ -54,20 +55,20 @@ const camelCase = (input, options) => {
5455
}
5556

5657
if (input.length === 1) {
57-
return options.pascalCase ? input.toLocaleUpperCase() : input.toLocaleLowerCase();
58+
return options.pascalCase ? input.toLocaleUpperCase(locale) : input.toLocaleLowerCase(locale);
5859
}
5960

60-
const hasUpperCase = input !== input.toLocaleLowerCase();
61+
const hasUpperCase = input !== input.toLocaleLowerCase(locale);
6162

6263
if (hasUpperCase) {
63-
input = preserveCamelCase(input);
64+
input = preserveCamelCase(input, locale);
6465
}
6566

6667
input = input
6768
.replace(/^[_.\- ]+/, '')
68-
.toLocaleLowerCase()
69-
.replace(/[_.\- ]+([\p{Alpha}\p{N}_]|$)/gu, (_, p1) => p1.toLocaleUpperCase())
70-
.replace(/\d+([\p{Alpha}\p{N}_]|$)/gu, m => m.toLocaleUpperCase());
69+
.toLocaleLowerCase(locale)
70+
.replace(/[_.\- ]+([\p{Alpha}\p{N}_]|$)/gu, (_, p1) => p1.toLocaleUpperCase(locale))
71+
.replace(/\d+([\p{Alpha}\p{N}_]|$)/gu, m => m.toLocaleUpperCase(locale));
7172

7273
return postProcess(input);
7374
};

0 commit comments

Comments
 (0)