test: utils for load

This commit is contained in:
endiliey 2018-08-10 15:26:37 +08:00
parent d80a2555c0
commit cfd11fbb6d
2 changed files with 43 additions and 5 deletions

View file

@ -31,13 +31,13 @@ function encodePath(userpath) {
}
function fileToComponentName(file) {
let str = file.replace(/([A-Z])/g, ' $1');
if (str.length === 1) {
return str.toUpperCase();
}
const ext = extRE.exec(file)[1];
let str = file.replace(extRE, '');
str = str.replace(/([A-Z])/g, ' $1');
str = str.replace(/^[\W_]+|[\W_]+$/g, '').toLowerCase();
str = str.charAt(0).toUpperCase() + str.slice(1);
return str.replace(/[\W_]+(\w|$)/g, (_, ch) => ch.toUpperCase());
str = str.replace(/[\W_]+(\w|$)/g, (_, ch) => ch.toUpperCase());
return ext ? ext.toUpperCase() + str : str;
}
module.exports = {