Skip to content

Commit 81cc16a

Browse files
DanielSeehausensindresorhus
authored andcommittedApr 3, 2019
Fix regression with how numbers are treated (#53)
Fixes #52
1 parent 7501406 commit 81cc16a

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed
 

‎index.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ const camelCase = (input, options) => {
5656
return options.pascalCase ? input.toUpperCase() : input.toLowerCase();
5757
}
5858

59-
if (/^[a-z\d]+$/.test(input)) {
60-
return postProcess(input);
61-
}
62-
6359
const hasUpperCase = input !== input.toLowerCase();
6460

6561
if (hasUpperCase) {
@@ -69,7 +65,8 @@ const camelCase = (input, options) => {
6965
input = input
7066
.replace(/^[_.\- ]+/, '')
7167
.toLowerCase()
72-
.replace(/[_.\- ]+(\w|$)/g, (m, p1) => p1.toUpperCase());
68+
.replace(/[_.\- ]+(\w|$)/g, (_, p1) => p1.toUpperCase())
69+
.replace(/\d+(\w|$)/g, m => m.toUpperCase());
7370

7471
return postProcess(input);
7572
};

‎test.js

+16
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ test('camelCase', t => {
4949
t.is(camelCase([]), '');
5050
t.is(camelCase('mGridCol6@md'), 'mGridCol6@md');
5151
t.is(camelCase('A::a'), 'a::a');
52+
t.is(camelCase('Hello1World'), 'hello1World');
53+
t.is(camelCase('Hello11World'), 'hello11World');
54+
t.is(camelCase('hello1world'), 'hello1World');
55+
t.is(camelCase('Hello1World11foo'), 'hello1World11Foo');
56+
t.is(camelCase('Hello1'), 'hello1');
57+
t.is(camelCase('hello1'), 'hello1');
58+
t.is(camelCase('1Hello'), '1Hello');
59+
t.is(camelCase('1hello'), '1Hello');
5260
});
5361

5462
test('camelCase with pascalCase option', t => {
@@ -99,6 +107,14 @@ test('camelCase with pascalCase option', t => {
99107
t.is(camelCase([], {pascalCase: true}), '');
100108
t.is(camelCase('mGridCol6@md', {pascalCase: true}), 'MGridCol6@md');
101109
t.is(camelCase('A::a', {pascalCase: true}), 'A::a');
110+
t.is(camelCase('Hello1World', {pascalCase: true}), 'Hello1World');
111+
t.is(camelCase('Hello11World', {pascalCase: true}), 'Hello11World');
112+
t.is(camelCase('hello1world', {pascalCase: true}), 'Hello1World');
113+
t.is(camelCase('hello1World', {pascalCase: true}), 'Hello1World');
114+
t.is(camelCase('hello1', {pascalCase: true}), 'Hello1');
115+
t.is(camelCase('Hello1', {pascalCase: true}), 'Hello1');
116+
t.is(camelCase('1hello', {pascalCase: true}), '1Hello');
117+
t.is(camelCase('1Hello', {pascalCase: true}), '1Hello');
102118
});
103119

104120
test('invalid input', t => {

0 commit comments

Comments
 (0)
Please sign in to comment.