Skip to content

Commit

Permalink
A separator as input should return an empty string (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
tychenjiajun committed Jun 6, 2022
1 parent a9e9f4f commit 6f12d6d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions index.js
Expand Up @@ -84,6 +84,10 @@ const camelCase = (input, options) => {
string => string.toLocaleUpperCase(options.locale);

if (input.length === 1) {
if (SEPARATORS.test(input)) {
return '';
}

return options.pascalCase ? toUpperCase(input) : toLowerCase(input);
}

Expand Down
15 changes: 11 additions & 4 deletions test.js
Expand Up @@ -23,8 +23,8 @@ test('camelCase', t => {
t.is(camelCase('__foo__bar__'), 'fooBar');
t.is(camelCase('foo bar'), 'fooBar');
t.is(camelCase(' foo bar '), 'fooBar');
t.is(camelCase('-'), '-');
t.is(camelCase(' - '), '-');
t.is(camelCase('-'), '');
t.is(camelCase(' - '), '');
t.is(camelCase('fooBar'), 'fooBar');
t.is(camelCase('fooBar-baz'), 'fooBarBaz');
t.is(camelCase('foìBar-baz'), 'foìBarBaz');
Expand All @@ -40,6 +40,13 @@ test('camelCase', t => {
t.is(camelCase(['', '']), '');
t.is(camelCase('--'), '');
t.is(camelCase(''), '');
t.is(camelCase('_'), '');
t.is(camelCase(' '), '');
t.is(camelCase('.'), '');
t.is(camelCase('..'), '');
t.is(camelCase('--'), '');
t.is(camelCase(' '), '');
t.is(camelCase('__'), '');
t.is(camelCase('--__--_--_'), '');
t.is(camelCase(['---_', '--', '', '-_- ']), '');
t.is(camelCase('foo bar?'), 'fooBar?');
Expand Down Expand Up @@ -89,8 +96,8 @@ test('camelCase with pascalCase option', t => {
t.is(camelCase('__foo__bar__', {pascalCase: true}), 'FooBar');
t.is(camelCase('foo bar', {pascalCase: true}), 'FooBar');
t.is(camelCase(' foo bar ', {pascalCase: true}), 'FooBar');
t.is(camelCase('-', {pascalCase: true}), '-');
t.is(camelCase(' - ', {pascalCase: true}), '-');
t.is(camelCase('-', {pascalCase: true}), '');
t.is(camelCase(' - ', {pascalCase: true}), '');
t.is(camelCase('fooBar', {pascalCase: true}), 'FooBar');
t.is(camelCase('fooBar-baz', {pascalCase: true}), 'FooBarBaz');
t.is(camelCase('foìBar-baz', {pascalCase: true}), 'FoìBarBaz');
Expand Down

0 comments on commit 6f12d6d

Please sign in to comment.