Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/loader/file_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ function defaultCamelize(filepath, caseStyle) {
// FooBar.js > FooBar
// FooBar.js > FooBar
// FooBar.js > fooBar (if lowercaseFirst is true)
property = property.replace(/[_-][a-z]/ig, s => s.substring(1).toUpperCase());
// aaa_00.js > aaa00 (digits after separator should also be handled)
property = property.replace(/[_-][a-z0-9]/ig, s => s.substring(1).toUpperCase());
let first = property[0];
switch (caseStyle) {
case 'lower':
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/load_dirs/camelize/foo_00.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = {};
18 changes: 18 additions & 0 deletions test/loader/file_loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ describe('test/loader/file_loader.test.js', () => {
assert(target.FooBar2);
assert(target.FooBar3);
assert(target.FooBar4);
assert(target.Foo00);
});

it('should load when caseStyle = camel', () => {
Expand All @@ -279,6 +280,7 @@ describe('test/loader/file_loader.test.js', () => {
assert(target.fooBar2);
assert(target.FooBar3);
assert(target.fooBar4);
assert(target.foo00);
});

it('should load when caseStyle = lower', () => {
Expand All @@ -293,6 +295,7 @@ describe('test/loader/file_loader.test.js', () => {
assert(target.fooBar2);
assert(target.fooBar3);
assert(target.fooBar4);
assert(target.foo00);
});

it('should load when caseStyle is function', () => {
Expand All @@ -312,6 +315,7 @@ describe('test/loader/file_loader.test.js', () => {
assert(target.fooBar2);
assert(target.FooBar3);
assert(target['foo-bar4']);
assert(target.foo00);
});

it('should throw when caseStyle do not return array', () => {
Expand Down Expand Up @@ -340,6 +344,20 @@ describe('test/loader/file_loader.test.js', () => {
assert(target.fooBar2);
assert(target.fooBar3);
assert(target.fooBar4);
assert(target.foo00);
});

it('should handle separator before digits correctly', () => {
const target = {};
new FileLoader({
directory: path.join(dirBase, 'camelize'),
target,
caseStyle: 'upper',
}).load();

// foo_00.js should camelize to Foo00, not Foo_00
assert(target.Foo00);
assert(!target.Foo_00);
});
});

Expand Down