diff --git a/index.js b/index.js index beaaaec..2babbda 100644 --- a/index.js +++ b/index.js @@ -3,14 +3,15 @@ // This file is licensed under the Artistic License 2.0. // License text available at https://opensource.org/licenses/Artistic-2.0 +var SG = require('strong-globalize'); +SG.SetRootDir(__dirname); + /** * Export the connector */ var loopback = require('loopback'); var PushConnector = require('./lib/push-connector'); exports = module.exports = PushConnector; -var SG = require('strong-globalize'); -SG.SetRootDir(__dirname); /** * Export two model classes as properties diff --git a/lib/payload.js b/lib/payload.js index 2bbb976..8b75c35 100644 --- a/lib/payload.js +++ b/lib/payload.js @@ -3,11 +3,12 @@ // This file is licensed under the Artistic License 2.0. // License text available at https://opensource.org/licenses/Artistic-2.0 +var SG = require('strong-globalize'); +var g = SG(); + // this file has no tests so avoid refactor and ignore jshint for now /*jshint ignore: start */ var serial,__hasProp = {}.hasOwnProperty; -var SG = require('strong-globalize'); -var g = SG(); serial = 0; @@ -16,7 +17,7 @@ Payload.prototype.locale_format = /^[a-z]{2}_[A-Z]{2}$/; function Payload(data) { var key, prefix, subkey, sum, type, value, _i, _len, _ref, _ref1; if (typeof data !== 'object') { - throw new Error(g.t('Invalid payload')); + throw new Error(g.f('Invalid payload')); } this.id = serial++; this.compiled = false; @@ -28,7 +29,7 @@ function Payload(data) { if (!__hasProp.call(data, key)) continue; value = data[key]; if (typeof key !== 'string' || key.length === 0) { - throw new Error(g.t("Invalid field (empty)")); + throw new Error(g.f("Invalid field (empty)")); } if (typeof value !== 'string') { throw new Error(g.f("Invalid value for `%s`", key)); @@ -68,7 +69,7 @@ function Payload(data) { }).call(this)).length; } if (sum === 0) { - throw new Error(g.t('Empty payload')); + throw new Error(g.f('Empty payload')); } } diff --git a/lib/providers/apns.js b/lib/providers/apns.js index 4ef1a37..5322954 100644 --- a/lib/providers/apns.js +++ b/lib/providers/apns.js @@ -3,12 +3,13 @@ // This file is licensed under the Artistic License 2.0. // License text available at https://opensource.org/licenses/Artistic-2.0 +var SG = require('strong-globalize'); +var g = SG(); + var inherits = require('util').inherits; var EventEmitter = require('events').EventEmitter; var debug = require('debug')('loopback:component:push:provider:apns'); var apn = require('apn'); -var SG = require('strong-globalize'); -var g = SG(); function ApnsProvider(pushSettings) { pushSettings = pushSettings || {}; diff --git a/lib/providers/gcm.js b/lib/providers/gcm.js index b96cc4a..1bb1c52 100644 --- a/lib/providers/gcm.js +++ b/lib/providers/gcm.js @@ -3,13 +3,14 @@ // This file is licensed under the Artistic License 2.0. // License text available at https://opensource.org/licenses/Artistic-2.0 +var SG = require('strong-globalize'); +var g = SG(); + var inherits = require('util').inherits; var extend = require('util')._extend; var EventEmitter = require('events').EventEmitter; var gcm = require('node-gcm'); var debug = require('debug')('loopback:component:push:provider:gcm'); -var SG = require('strong-globalize'); -var g = SG(); function GcmProvider(pushSettings) { var settings = pushSettings.gcm || {}; diff --git a/lib/push-manager.js b/lib/push-manager.js index 5c9aa2c..1e3504a 100644 --- a/lib/push-manager.js +++ b/lib/push-manager.js @@ -3,6 +3,9 @@ // This file is licensed under the Artistic License 2.0. // License text available at https://opensource.org/licenses/Artistic-2.0 +var SG = require('strong-globalize'); +var g = SG(); + var assert = require('assert'); var inherits = require('util').inherits; var EventEmitter = require('events').EventEmitter; @@ -12,8 +15,6 @@ var providers = require('./providers'); var loopback = require('loopback'); var NodeCache = require('node-cache'); var debug = require('debug')('loopback:component:push:push-manager'); -var SG = require('strong-globalize'); -var g = SG(); var Installation = require('../models').Installation; var Notification = require('../models').Notification; @@ -279,7 +280,7 @@ PushManager.prototype.notify = function(installation, notification, cb) { assert(cb, 'callback should be defined'); if(!(typeof notification === 'object' && notification)) { - return cb(new Error(g.t('notification must be an object'))); + return cb(new Error(g.f('notification must be an object'))); } var appId = installation.appId; @@ -329,11 +330,11 @@ PushManager.prototype.notifyMany = function(appId, deviceType, deviceTokens, not assert(cb, 'callback should be defined'); if(!(typeof notification === 'object' && notification)) { - return cb(new Error(g.t('notification must be an object'))); + return cb(new Error(g.f('notification must be an object'))); } if(!(Array.isArray(deviceTokens) && deviceTokens.length > 0)) { - return cb(new Error(g.t('deviceTokens must be an array'))); + return cb(new Error(g.f('deviceTokens must be an array'))); } // Normalize the notification from a plain object diff --git a/package.json b/package.json index 3dea31f..51431a8 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "mpns": "^2.1.0", "node-cache": "^3.2.1", "node-gcm": "^0.14.0", - "strong-globalize": "^2.5.6" + "strong-globalize": "^2.5.8" }, "devDependencies": { "chai": "^2.3.0",