From 1da34d446ec1aa0035bb16728d57dd9441025a08 Mon Sep 17 00:00:00 2001 From: David Ellis Date: Wed, 19 Mar 2014 00:51:29 -0700 Subject: [PATCH] Simplify the module definition and use JS to our advantage in getting necessary source for browser --- lib/localize.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/lib/localize.js b/lib/localize.js index 100fb5d..d77ce8f 100644 --- a/lib/localize.js +++ b/lib/localize.js @@ -2,15 +2,8 @@ // is a GNU gettext-inspired (but not conformant) localization library for // Node.js -// Libraries, if in a CommonJS environment -if(typeof(require) !== 'undefined') { - var path = require('path'); - var fs = require('fs'); - // Path ``fs`` to use ``path.exists`` and ``path.existsSync`` if ``fs.exists`` and ``fs.existsSync`` don't exist. - // Reason? So Node 0.8.x-compliant code will run on Node 0.6.x, 0.4.x, etc. - fs.exists = fs.exists ? fs.exists : path.exists; - fs.existsSync = fs.existsSync ? fs.existsSync : path.existsSync; -} +var path = require('path'); +var fs = require('fs'); function Localize(translations, dateFormats, defaultLocale) { @@ -409,8 +402,5 @@ function Localize(translations, dateFormats, defaultLocale) { return this; } -// Publish as a module, if in a CommonJS environment -if(typeof(module) !== 'undefined') { - Localize.source = fs.readFileSync(require.resolve('./localize'), 'utf8'); // Append a source string to the Localize object for easy exporting to the client - module.exports = Localize; -} +Localize.source = Localize.toString(); +module.exports = Localize;