Skip to content

Commit 8a16aa9

Browse files
committed
ensure existing camelcasing is preserved
1 parent f425907 commit 8a16aa9

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function pascalcase(str) {
99
if (typeof str !== 'string') {
1010
throw new TypeError('expected a string.');
1111
}
12+
str = str.replace(/([A-Z])/g, ' $1');
1213
if (str.length === 1) { return str.toUpperCase(); }
1314
str = str.replace(/^[\W_]+|[\W_]+$/g, '').toLowerCase();
1415
str = str.charAt(0).toUpperCase() + str.slice(1);

test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ describe('pascalcase', function () {
1414
pascalcase('foo bar baz').should.equal('FooBarBaz');
1515
});
1616

17+
it('should not lowercase existing camelcasing:', function () {
18+
pascalcase('fooBarBaz').should.equal('FooBarBaz');
19+
pascalcase('FooBarBaz').should.equal('FooBarBaz');
20+
pascalcase(' FooBarBaz').should.equal('FooBarBaz');
21+
pascalcase(' fooBarBaz').should.equal('FooBarBaz');
22+
});
23+
1724
it('should work with other non-word-characters:', function () {
1825
pascalcase('foo_bar-baz').should.equal('FooBarBaz');
1926
pascalcase('foo.bar.baz').should.equal('FooBarBaz');

0 commit comments

Comments
 (0)