From 3ed0f21ce9cdca73d1705dd92c77a6de7bf5a5e0 Mon Sep 17 00:00:00 2001 From: Robert Williams Date: Thu, 19 Nov 2015 17:59:43 -0600 Subject: [PATCH 1/3] fix issue where module tries to load .DStore and other non-json files. --- lib/node-i18n.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/node-i18n.js b/lib/node-i18n.js index f5de4c5..2f5f67b 100644 --- a/lib/node-i18n.js +++ b/lib/node-i18n.js @@ -43,9 +43,11 @@ module.exports = function (options) { this.load = function(){ _.each(this.files, function(file){ - fileContents = require(self.options.dir + '/' + file) - fileLocale = _.keys(fileContents)[0] - self.words[fileLocale] = _.extend(self.words[fileLocale] || {}, fileContents[fileLocale]) + if (/\.json$/.test(file)) { + var fileContents = require(self.options.dir + '/' + file) + var fileLocale = _.keys(fileContents)[0] + self.words[fileLocale] = _.extend(self.words[fileLocale] || {}, fileContents[fileLocale]) + } }) return this } From 44c145b3418d42e9b9ad321083f24b5de464cf62 Mon Sep 17 00:00:00 2001 From: Robert Williams Date: Thu, 19 Nov 2015 18:12:15 -0600 Subject: [PATCH 2/3] fixed array to not include non-json files --- lib/node-i18n.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/node-i18n.js b/lib/node-i18n.js index 2f5f67b..b684d58 100644 --- a/lib/node-i18n.js +++ b/lib/node-i18n.js @@ -37,17 +37,15 @@ module.exports = function (options) { var self = this this.options = options this.words = {} - this.files = fs.readdirSync(this.options.dir) + this.files = _.filter(fs.readdirSync(this.options.dir), /\.json$/.test) this.locales = function() { return self.options.enabled } this.load = function(){ _.each(this.files, function(file){ - if (/\.json$/.test(file)) { - var fileContents = require(self.options.dir + '/' + file) - var fileLocale = _.keys(fileContents)[0] - self.words[fileLocale] = _.extend(self.words[fileLocale] || {}, fileContents[fileLocale]) - } + var fileContents = require(self.options.dir + '/' + file); + var fileLocale = _.keys(fileContents)[0]; + self.words[fileLocale] = _.extend(self.words[fileLocale] || {}, fileContents[fileLocale]) }) return this } From 830e08a644c5e657db00381c07a151505e7713d0 Mon Sep 17 00:00:00 2001 From: Robert Williams Date: Thu, 19 Nov 2015 18:17:02 -0600 Subject: [PATCH 3/3] fixed array to not include non-json files --- lib/node-i18n.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/node-i18n.js b/lib/node-i18n.js index b684d58..d152ba7 100644 --- a/lib/node-i18n.js +++ b/lib/node-i18n.js @@ -37,7 +37,9 @@ module.exports = function (options) { var self = this this.options = options this.words = {} - this.files = _.filter(fs.readdirSync(this.options.dir), /\.json$/.test) + this.files = _.filter(fs.readdirSync(this.options.dir), function(file){ + return /\.json$/.test(file); + }); this.locales = function() { return self.options.enabled }