i18next-fetch-backend
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -59,2 +59,117 @@ 'use strict'; | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _construct(Parent, args, Class) { | ||
if (isNativeReflectConstruct()) { | ||
_construct = Reflect.construct; | ||
} else { | ||
_construct = function _construct(Parent, args, Class) { | ||
var a = [null]; | ||
a.push.apply(a, args); | ||
var Constructor = Function.bind.apply(Parent, a); | ||
var instance = new Constructor(); | ||
if (Class) _setPrototypeOf(instance, Class.prototype); | ||
return instance; | ||
}; | ||
} | ||
return _construct.apply(null, arguments); | ||
} | ||
function _isNativeFunction(fn) { | ||
return Function.toString.call(fn).indexOf("[native code]") !== -1; | ||
} | ||
function _wrapNativeSuper(Class) { | ||
var _cache = typeof Map === "function" ? new Map() : undefined; | ||
_wrapNativeSuper = function _wrapNativeSuper(Class) { | ||
if (Class === null || !_isNativeFunction(Class)) return Class; | ||
if (typeof Class !== "function") { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
if (typeof _cache !== "undefined") { | ||
if (_cache.has(Class)) return _cache.get(Class); | ||
_cache.set(Class, Wrapper); | ||
} | ||
function Wrapper() { | ||
return _construct(Class, arguments, _getPrototypeOf(this).constructor); | ||
} | ||
Wrapper.prototype = Object.create(Class.prototype, { | ||
constructor: { | ||
value: Wrapper, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
return _setPrototypeOf(Wrapper, Class); | ||
}; | ||
return _wrapNativeSuper(Class); | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
var defaults = { | ||
@@ -83,2 +198,25 @@ loadPath: '/locales/{{lng}}/{{ns}}.json', | ||
var BackendError = | ||
/*#__PURE__*/ | ||
function (_Error) { | ||
_inherits(BackendError, _Error); | ||
function BackendError(message) { | ||
var _this; | ||
var retry = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
_classCallCheck(this, BackendError); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(BackendError).call(this, message)); | ||
_defineProperty(_assertThisInitialized(_this), "retry", null); | ||
_this.retry = retry; | ||
return _this; | ||
} | ||
return BackendError; | ||
}(_wrapNativeSuper(Error)); | ||
var Backend = | ||
@@ -140,9 +278,10 @@ /*#__PURE__*/ | ||
if (!ok) { | ||
var retry = false; // status codes 4xx | ||
var retry = status >= 500 && status < 600; // don't retry for 4xx codes | ||
if (status >= 500 && status < 600) retry = true; | ||
return callback("failed loading ".concat(url), retry); | ||
throw new BackendError("failed loading ".concat(url), retry); | ||
} | ||
return response.text(); | ||
}, function () { | ||
throw new BackendError("failed loading ".concat(url)); | ||
}).then(function (data) { | ||
@@ -152,6 +291,8 @@ try { | ||
} catch (e) { | ||
return callback("failed parsing ".concat(url, " to json"), false); | ||
throw new BackendError("failed parsing ".concat(url, " to json"), false); | ||
} | ||
}).catch(function () { | ||
return callback("failed loading ".concat(url), false); | ||
}).catch(function (e) { | ||
if (e instanceof BackendError) { | ||
callback(e.message, e.retry); | ||
} | ||
}); | ||
@@ -162,3 +303,3 @@ } | ||
value: function create(languages, namespace, key, fallbackValue) { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -168,9 +309,9 @@ var payload = _defineProperty({}, key, fallbackValue || ''); | ||
arrify(languages).forEach(function (lng) { | ||
var _this$options2 = _this.options, | ||
addPath = _this$options2.addPath, | ||
requestOptions = _this$options2.requestOptions, | ||
fetch = _this$options2.fetch, | ||
stringify = _this$options2.stringify; | ||
var _this2$options = _this2.options, | ||
addPath = _this2$options.addPath, | ||
requestOptions = _this2$options.requestOptions, | ||
fetch = _this2$options.fetch, | ||
stringify = _this2$options.stringify; | ||
var url = _this.services.interpolator.interpolate(addPath, { | ||
var url = _this2.services.interpolator.interpolate(addPath, { | ||
lng: lng, | ||
@@ -177,0 +318,0 @@ ns: namespace |
@@ -57,2 +57,117 @@ function _classCallCheck(instance, Constructor) { | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _construct(Parent, args, Class) { | ||
if (isNativeReflectConstruct()) { | ||
_construct = Reflect.construct; | ||
} else { | ||
_construct = function _construct(Parent, args, Class) { | ||
var a = [null]; | ||
a.push.apply(a, args); | ||
var Constructor = Function.bind.apply(Parent, a); | ||
var instance = new Constructor(); | ||
if (Class) _setPrototypeOf(instance, Class.prototype); | ||
return instance; | ||
}; | ||
} | ||
return _construct.apply(null, arguments); | ||
} | ||
function _isNativeFunction(fn) { | ||
return Function.toString.call(fn).indexOf("[native code]") !== -1; | ||
} | ||
function _wrapNativeSuper(Class) { | ||
var _cache = typeof Map === "function" ? new Map() : undefined; | ||
_wrapNativeSuper = function _wrapNativeSuper(Class) { | ||
if (Class === null || !_isNativeFunction(Class)) return Class; | ||
if (typeof Class !== "function") { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
if (typeof _cache !== "undefined") { | ||
if (_cache.has(Class)) return _cache.get(Class); | ||
_cache.set(Class, Wrapper); | ||
} | ||
function Wrapper() { | ||
return _construct(Class, arguments, _getPrototypeOf(this).constructor); | ||
} | ||
Wrapper.prototype = Object.create(Class.prototype, { | ||
constructor: { | ||
value: Wrapper, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
return _setPrototypeOf(Wrapper, Class); | ||
}; | ||
return _wrapNativeSuper(Class); | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
var defaults = { | ||
@@ -81,2 +196,25 @@ loadPath: '/locales/{{lng}}/{{ns}}.json', | ||
var BackendError = | ||
/*#__PURE__*/ | ||
function (_Error) { | ||
_inherits(BackendError, _Error); | ||
function BackendError(message) { | ||
var _this; | ||
var retry = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
_classCallCheck(this, BackendError); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(BackendError).call(this, message)); | ||
_defineProperty(_assertThisInitialized(_this), "retry", null); | ||
_this.retry = retry; | ||
return _this; | ||
} | ||
return BackendError; | ||
}(_wrapNativeSuper(Error)); | ||
var Backend = | ||
@@ -138,9 +276,10 @@ /*#__PURE__*/ | ||
if (!ok) { | ||
var retry = false; // status codes 4xx | ||
var retry = status >= 500 && status < 600; // don't retry for 4xx codes | ||
if (status >= 500 && status < 600) retry = true; | ||
return callback("failed loading ".concat(url), retry); | ||
throw new BackendError("failed loading ".concat(url), retry); | ||
} | ||
return response.text(); | ||
}, function () { | ||
throw new BackendError("failed loading ".concat(url)); | ||
}).then(function (data) { | ||
@@ -150,6 +289,8 @@ try { | ||
} catch (e) { | ||
return callback("failed parsing ".concat(url, " to json"), false); | ||
throw new BackendError("failed parsing ".concat(url, " to json"), false); | ||
} | ||
}).catch(function () { | ||
return callback("failed loading ".concat(url), false); | ||
}).catch(function (e) { | ||
if (e instanceof BackendError) { | ||
callback(e.message, e.retry); | ||
} | ||
}); | ||
@@ -160,3 +301,3 @@ } | ||
value: function create(languages, namespace, key, fallbackValue) { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -166,9 +307,9 @@ var payload = _defineProperty({}, key, fallbackValue || ''); | ||
arrify(languages).forEach(function (lng) { | ||
var _this$options2 = _this.options, | ||
addPath = _this$options2.addPath, | ||
requestOptions = _this$options2.requestOptions, | ||
fetch = _this$options2.fetch, | ||
stringify = _this$options2.stringify; | ||
var _this2$options = _this2.options, | ||
addPath = _this2$options.addPath, | ||
requestOptions = _this2$options.requestOptions, | ||
fetch = _this2$options.fetch, | ||
stringify = _this2$options.stringify; | ||
var url = _this.services.interpolator.interpolate(addPath, { | ||
var url = _this2.services.interpolator.interpolate(addPath, { | ||
lng: lng, | ||
@@ -175,0 +316,0 @@ ns: namespace |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.I18nextFetchBackend = factory()); | ||
}(this, (function () { 'use strict'; | ||
(global = global || self, global.I18nextFetchBackend = factory()); | ||
}(this, function () { 'use strict'; | ||
@@ -63,2 +63,117 @@ function _classCallCheck(instance, Constructor) { | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _construct(Parent, args, Class) { | ||
if (isNativeReflectConstruct()) { | ||
_construct = Reflect.construct; | ||
} else { | ||
_construct = function _construct(Parent, args, Class) { | ||
var a = [null]; | ||
a.push.apply(a, args); | ||
var Constructor = Function.bind.apply(Parent, a); | ||
var instance = new Constructor(); | ||
if (Class) _setPrototypeOf(instance, Class.prototype); | ||
return instance; | ||
}; | ||
} | ||
return _construct.apply(null, arguments); | ||
} | ||
function _isNativeFunction(fn) { | ||
return Function.toString.call(fn).indexOf("[native code]") !== -1; | ||
} | ||
function _wrapNativeSuper(Class) { | ||
var _cache = typeof Map === "function" ? new Map() : undefined; | ||
_wrapNativeSuper = function _wrapNativeSuper(Class) { | ||
if (Class === null || !_isNativeFunction(Class)) return Class; | ||
if (typeof Class !== "function") { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
if (typeof _cache !== "undefined") { | ||
if (_cache.has(Class)) return _cache.get(Class); | ||
_cache.set(Class, Wrapper); | ||
} | ||
function Wrapper() { | ||
return _construct(Class, arguments, _getPrototypeOf(this).constructor); | ||
} | ||
Wrapper.prototype = Object.create(Class.prototype, { | ||
constructor: { | ||
value: Wrapper, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
return _setPrototypeOf(Wrapper, Class); | ||
}; | ||
return _wrapNativeSuper(Class); | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
var defaults = { | ||
@@ -87,2 +202,25 @@ loadPath: '/locales/{{lng}}/{{ns}}.json', | ||
var BackendError = | ||
/*#__PURE__*/ | ||
function (_Error) { | ||
_inherits(BackendError, _Error); | ||
function BackendError(message) { | ||
var _this; | ||
var retry = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
_classCallCheck(this, BackendError); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(BackendError).call(this, message)); | ||
_defineProperty(_assertThisInitialized(_this), "retry", null); | ||
_this.retry = retry; | ||
return _this; | ||
} | ||
return BackendError; | ||
}(_wrapNativeSuper(Error)); | ||
var Backend = | ||
@@ -144,9 +282,10 @@ /*#__PURE__*/ | ||
if (!ok) { | ||
var retry = false; // status codes 4xx | ||
var retry = status >= 500 && status < 600; // don't retry for 4xx codes | ||
if (status >= 500 && status < 600) retry = true; | ||
return callback("failed loading ".concat(url), retry); | ||
throw new BackendError("failed loading ".concat(url), retry); | ||
} | ||
return response.text(); | ||
}, function () { | ||
throw new BackendError("failed loading ".concat(url)); | ||
}).then(function (data) { | ||
@@ -156,6 +295,8 @@ try { | ||
} catch (e) { | ||
return callback("failed parsing ".concat(url, " to json"), false); | ||
throw new BackendError("failed parsing ".concat(url, " to json"), false); | ||
} | ||
}).catch(function () { | ||
return callback("failed loading ".concat(url), false); | ||
}).catch(function (e) { | ||
if (e instanceof BackendError) { | ||
callback(e.message, e.retry); | ||
} | ||
}); | ||
@@ -166,3 +307,3 @@ } | ||
value: function create(languages, namespace, key, fallbackValue) { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -172,9 +313,9 @@ var payload = _defineProperty({}, key, fallbackValue || ''); | ||
arrify(languages).forEach(function (lng) { | ||
var _this$options2 = _this.options, | ||
addPath = _this$options2.addPath, | ||
requestOptions = _this$options2.requestOptions, | ||
fetch = _this$options2.fetch, | ||
stringify = _this$options2.stringify; | ||
var _this2$options = _this2.options, | ||
addPath = _this2$options.addPath, | ||
requestOptions = _this2$options.requestOptions, | ||
fetch = _this2$options.fetch, | ||
stringify = _this2$options.stringify; | ||
var url = _this.services.interpolator.interpolate(addPath, { | ||
var url = _this2.services.interpolator.interpolate(addPath, { | ||
lng: lng, | ||
@@ -203,2 +344,2 @@ ns: namespace | ||
}))); | ||
})); |
{ | ||
"name": "i18next-fetch-backend", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "backend layer for i18next using browsers fetch", | ||
@@ -34,24 +34,24 @@ "main": "dist/i18next-fetch-backend.cjs.js", | ||
"devDependencies": { | ||
"@babel/cli": "^7.1.2", | ||
"@babel/core": "^7.1.2", | ||
"@babel/plugin-proposal-class-properties": "^7.1.0", | ||
"@babel/preset-env": "^7.1.0", | ||
"@babel/cli": "^7.2.3", | ||
"@babel/core": "^7.3.3", | ||
"@babel/plugin-proposal-class-properties": "^7.3.3", | ||
"@babel/preset-env": "^7.3.1", | ||
"@babel/register": "^7.0.0", | ||
"babel-eslint": "^10.0.1", | ||
"babel-plugin-istanbul": "^5.1.0", | ||
"babel-plugin-istanbul": "^5.1.1", | ||
"chai": "^4.2.0", | ||
"coveralls": "^3.0.2", | ||
"env-test": "^1.0.0", | ||
"eslint": "^5.7.0", | ||
"eslint": "^5.14.1", | ||
"eslint-config-airbnb-base": "^13.1.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-import": "^2.16.0", | ||
"finalhandler": "^1.1.1", | ||
"i18next": "^12.0.0", | ||
"i18next": "^15.0.4", | ||
"isomorphic-fetch": "^2.2.1", | ||
"mocha": "^5.2.0", | ||
"nyc": "^13.1.0", | ||
"rollup": "^0.66.6", | ||
"rollup-plugin-babel": "^4.0.3", | ||
"mocha": "^6.0.0", | ||
"nyc": "^13.3.0", | ||
"rollup": "^1.2.2", | ||
"rollup-plugin-babel": "^4.3.2", | ||
"serve-static": "^1.13.2" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35046
829