refact(endsWith): endsWith is fast than regexp

This commit is contained in:
闲耘™
2015-08-30 20:48:36 +08:00
parent fe92c90b53
commit 3039718c1b
3 changed files with 78 additions and 10 deletions

View File

@@ -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'));
}
}
}