Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 = {};
19 changes: 19 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 @@
assert(target.FooBar2);
assert(target.FooBar3);
assert(target.FooBar4);
assert(target.Foo00);
});

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

it('should load when caseStyle = lower', () => {
Expand All @@ -293,6 +295,7 @@
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 @@
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,21 @@
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);
assert(!target['Foo_00']);

Check failure on line 361 in test/loader/file_loader.test.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 20)

["Foo_00"] is better written in dot notation

Check failure on line 361 in test/loader/file_loader.test.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 18)

["Foo_00"] is better written in dot notation

Check failure on line 361 in test/loader/file_loader.test.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

["Foo_00"] is better written in dot notation

Check failure on line 361 in test/loader/file_loader.test.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 14.19.0)

["Foo_00"] is better written in dot notation

Check failure on line 361 in test/loader/file_loader.test.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

["Foo_00"] is better written in dot notation

Check failure on line 361 in test/loader/file_loader.test.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16)

["Foo_00"] is better written in dot notation

Check failure on line 361 in test/loader/file_loader.test.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 14.19.0)

["Foo_00"] is better written in dot notation

Check failure on line 361 in test/loader/file_loader.test.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 14)

["Foo_00"] is better written in dot notation

Check failure on line 361 in test/loader/file_loader.test.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 20)

["Foo_00"] is better written in dot notation

Check failure on line 361 in test/loader/file_loader.test.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 18)

["Foo_00"] is better written in dot notation

Check failure on line 361 in test/loader/file_loader.test.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 14)

["Foo_00"] is better written in dot notation

Check failure on line 361 in test/loader/file_loader.test.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 14.19.0)

["Foo_00"] is better written in dot notation

Check failure on line 361 in test/loader/file_loader.test.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 16)

["Foo_00"] is better written in dot notation

Check failure on line 361 in test/loader/file_loader.test.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 14)

["Foo_00"] is better written in dot notation

Check failure on line 361 in test/loader/file_loader.test.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 16)

["Foo_00"] is better written in dot notation
});
});

Expand Down
Loading