refact(endsWith): endsWith is fast than regexp
This commit is contained in:
10
index.js
10
index.js
@@ -35,16 +35,14 @@ module.exports = function (app, options) {
|
||||
var names = fs.readdirSync(localeDir);
|
||||
for (var i = 0; i < names.length; i++) {
|
||||
var name = names[i];
|
||||
if (!/\.(?:js|json|properties)$/.test(name)) {
|
||||
continue;
|
||||
}
|
||||
var filepath = path.join(localeDir, name);
|
||||
// support en_US.js => en-US.js
|
||||
var locale = formatLocale(name.split('.')[0]);
|
||||
if (/\.properties$/.test(name)) {
|
||||
resources[locale] = ini.parse(fs.readFileSync(filepath, 'utf8'));
|
||||
} else {
|
||||
|
||||
if (name.endsWith('.js') || name.endsWith('.json')) {
|
||||
resources[locale] = require(filepath);
|
||||
} else if (name.endsWith('.properties')) {
|
||||
resources[locale] = ini.parse(fs.readFileSync(filepath, 'utf8'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user