Skip to content

Commit 6f12d6d

Browse files
authored
A separator as input should return an empty string (#99)
1 parent a9e9f4f commit 6f12d6d

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ const camelCase = (input, options) => {
8484
string => string.toLocaleUpperCase(options.locale);
8585

8686
if (input.length === 1) {
87+
if (SEPARATORS.test(input)) {
88+
return '';
89+
}
90+
8791
return options.pascalCase ? toUpperCase(input) : toLowerCase(input);
8892
}
8993

test.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ test('camelCase', t => {
2323
t.is(camelCase('__foo__bar__'), 'fooBar');
2424
t.is(camelCase('foo bar'), 'fooBar');
2525
t.is(camelCase(' foo bar '), 'fooBar');
26-
t.is(camelCase('-'), '-');
27-
t.is(camelCase(' - '), '-');
26+
t.is(camelCase('-'), '');
27+
t.is(camelCase(' - '), '');
2828
t.is(camelCase('fooBar'), 'fooBar');
2929
t.is(camelCase('fooBar-baz'), 'fooBarBaz');
3030
t.is(camelCase('foìBar-baz'), 'foìBarBaz');
@@ -40,6 +40,13 @@ test('camelCase', t => {
4040
t.is(camelCase(['', '']), '');
4141
t.is(camelCase('--'), '');
4242
t.is(camelCase(''), '');
43+
t.is(camelCase('_'), '');
44+
t.is(camelCase(' '), '');
45+
t.is(camelCase('.'), '');
46+
t.is(camelCase('..'), '');
47+
t.is(camelCase('--'), '');
48+
t.is(camelCase(' '), '');
49+
t.is(camelCase('__'), '');
4350
t.is(camelCase('--__--_--_'), '');
4451
t.is(camelCase(['---_', '--', '', '-_- ']), '');
4552
t.is(camelCase('foo bar?'), 'fooBar?');
@@ -89,8 +96,8 @@ test('camelCase with pascalCase option', t => {
8996
t.is(camelCase('__foo__bar__', {pascalCase: true}), 'FooBar');
9097
t.is(camelCase('foo bar', {pascalCase: true}), 'FooBar');
9198
t.is(camelCase(' foo bar ', {pascalCase: true}), 'FooBar');
92-
t.is(camelCase('-', {pascalCase: true}), '-');
93-
t.is(camelCase(' - ', {pascalCase: true}), '-');
99+
t.is(camelCase('-', {pascalCase: true}), '');
100+
t.is(camelCase(' - ', {pascalCase: true}), '');
94101
t.is(camelCase('fooBar', {pascalCase: true}), 'FooBar');
95102
t.is(camelCase('fooBar-baz', {pascalCase: true}), 'FooBarBaz');
96103
t.is(camelCase('foìBar-baz', {pascalCase: true}), 'FoìBarBaz');

0 commit comments

Comments
 (0)