i18next-xhr-backend
Advanced tools
Comparing version 2.0.1 to 3.0.0
@@ -0,1 +1,8 @@ | ||
### 3.0.0 | ||
- removes deprecated jsnext:main from package.json | ||
- Bundle all entry points with rollup [314](https://github.com/i18next/i18next-xhr-backend/pull/314) | ||
- **note:** dist/es -> dist/esm, dist/commonjs -> dist/cjs (individual files -> one bundled file) | ||
- removes bower finally | ||
### 2.0.1 | ||
@@ -2,0 +9,0 @@ |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.i18nextXHRBackend = factory()); | ||
}(this, (function () { 'use strict'; | ||
(global = global || self, global.i18nextXHRBackend = factory()); | ||
}(this, function () { 'use strict'; | ||
var arr = []; | ||
var each = arr.forEach; | ||
var slice = arr.slice; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function defaults(obj) { | ||
each.call(slice.call(arguments, 1), function (source) { | ||
if (source) { | ||
for (var prop in source) { | ||
if (obj[prop] === undefined) obj[prop] = source[prop]; | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
}); | ||
return obj; | ||
} | ||
} | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function addQueryString(url, params) { | ||
if (params && (typeof params === 'undefined' ? 'undefined' : _typeof(params)) === 'object') { | ||
var queryString = '', | ||
e = encodeURIComponent; | ||
var arr = []; | ||
var each = arr.forEach; | ||
var slice = arr.slice; | ||
function defaults(obj) { | ||
each.call(slice.call(arguments, 1), function (source) { | ||
if (source) { | ||
for (var prop in source) { | ||
if (obj[prop] === undefined) obj[prop] = source[prop]; | ||
} | ||
} | ||
}); | ||
return obj; | ||
} | ||
// Must encode data | ||
for (var paramName in params) { | ||
queryString += '&' + e(paramName) + '=' + e(params[paramName]); | ||
} | ||
function _typeof2(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof2(obj); } | ||
if (!queryString) { | ||
return url; | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") { | ||
_typeof = function _typeof(obj) { | ||
return _typeof2(obj); | ||
}; | ||
} else { | ||
_typeof = function _typeof(obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj); | ||
}; | ||
} | ||
url = url + (url.indexOf('?') !== -1 ? '&' : '?') + queryString.slice(1); | ||
return _typeof(obj); | ||
} | ||
return url; | ||
} | ||
function addQueryString(url, params) { | ||
if (params && _typeof(params) === 'object') { | ||
var queryString = '', | ||
e = encodeURIComponent; // Must encode data | ||
// https://gist.github.com/Xeoncross/7663273 | ||
function ajax(url, options, callback, data, cache) { | ||
for (var paramName in params) { | ||
queryString += '&' + e(paramName) + '=' + e(params[paramName]); | ||
} | ||
if (data && (typeof data === 'undefined' ? 'undefined' : _typeof(data)) === 'object') { | ||
if (!cache) { | ||
data['_t'] = new Date(); | ||
if (!queryString) { | ||
return url; | ||
} | ||
url = url + (url.indexOf('?') !== -1 ? '&' : '?') + queryString.slice(1); | ||
} | ||
// URL encoded form data must be in querystring format | ||
data = addQueryString('', data).slice(1); | ||
} | ||
if (options.queryStringParams) { | ||
url = addQueryString(url, options.queryStringParams); | ||
} | ||
return url; | ||
} // https://gist.github.com/Xeoncross/7663273 | ||
try { | ||
var x; | ||
if (XMLHttpRequest) { | ||
x = new XMLHttpRequest(); | ||
} else { | ||
x = new ActiveXObject('MSXML2.XMLHTTP.3.0'); | ||
function ajax(url, options, callback, data, cache) { | ||
if (data && _typeof(data) === 'object') { | ||
if (!cache) { | ||
data['_t'] = new Date(); | ||
} // URL encoded form data must be in querystring format | ||
data = addQueryString('', data).slice(1); | ||
} | ||
x.open(data ? 'POST' : 'GET', url, 1); | ||
if (!options.crossDomain) { | ||
x.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); | ||
if (options.queryStringParams) { | ||
url = addQueryString(url, options.queryStringParams); | ||
} | ||
x.withCredentials = !!options.withCredentials; | ||
if (data) { | ||
x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | ||
} | ||
if (x.overrideMimeType) { | ||
x.overrideMimeType("application/json"); | ||
} | ||
var h = options.customHeaders; | ||
if (h) { | ||
for (var i in h) { | ||
x.setRequestHeader(i, h[i]); | ||
try { | ||
var x; | ||
if (XMLHttpRequest) { | ||
x = new XMLHttpRequest(); | ||
} else { | ||
x = new ActiveXObject('MSXML2.XMLHTTP.3.0'); | ||
} | ||
} | ||
x.onreadystatechange = function () { | ||
x.readyState > 3 && callback && callback(x.responseText, x); | ||
}; | ||
x.send(data); | ||
} catch (e) { | ||
console && console.log(e); | ||
} | ||
} | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
x.open(data ? 'POST' : 'GET', url, 1); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
if (!options.crossDomain) { | ||
x.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); | ||
} | ||
function getDefaults() { | ||
return { | ||
loadPath: '/locales/{{lng}}/{{ns}}.json', | ||
addPath: '/locales/add/{{lng}}/{{ns}}', | ||
allowMultiLoading: false, | ||
parse: JSON.parse, | ||
crossDomain: false, | ||
ajax: ajax | ||
}; | ||
} | ||
x.withCredentials = !!options.withCredentials; | ||
var Backend = function () { | ||
function Backend(services) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (data) { | ||
x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | ||
} | ||
_classCallCheck(this, Backend); | ||
if (x.overrideMimeType) { | ||
x.overrideMimeType("application/json"); | ||
} | ||
this.init(services, options); | ||
var h = options.customHeaders; | ||
this.type = 'backend'; | ||
if (h) { | ||
for (var i in h) { | ||
x.setRequestHeader(i, h[i]); | ||
} | ||
} | ||
x.onreadystatechange = function () { | ||
x.readyState > 3 && callback && callback(x.responseText, x); | ||
}; | ||
x.send(data); | ||
} catch (e) { | ||
console && console.log(e); | ||
} | ||
} | ||
_createClass(Backend, [{ | ||
key: 'init', | ||
value: function init(services) { | ||
function getDefaults() { | ||
return { | ||
loadPath: '/locales/{{lng}}/{{ns}}.json', | ||
addPath: '/locales/add/{{lng}}/{{ns}}', | ||
allowMultiLoading: false, | ||
parse: JSON.parse, | ||
crossDomain: false, | ||
ajax: ajax | ||
}; | ||
} | ||
var Backend = | ||
/*#__PURE__*/ | ||
function () { | ||
function Backend(services) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
this.services = services; | ||
this.options = defaults(options, this.options || {}, getDefaults()); | ||
_classCallCheck(this, Backend); | ||
this.init(services, options); | ||
this.type = 'backend'; | ||
} | ||
}, { | ||
key: 'readMulti', | ||
value: function readMulti(languages, namespaces, callback) { | ||
var loadPath = this.options.loadPath; | ||
if (typeof this.options.loadPath === 'function') { | ||
loadPath = this.options.loadPath(languages, namespaces); | ||
_createClass(Backend, [{ | ||
key: "init", | ||
value: function init(services) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
this.services = services; | ||
this.options = defaults(options, this.options || {}, getDefaults()); | ||
} | ||
}, { | ||
key: "readMulti", | ||
value: function readMulti(languages, namespaces, callback) { | ||
var loadPath = this.options.loadPath; | ||
var url = this.services.interpolator.interpolate(loadPath, { lng: languages.join('+'), ns: namespaces.join('+') }); | ||
if (typeof this.options.loadPath === 'function') { | ||
loadPath = this.options.loadPath(languages, namespaces); | ||
} | ||
this.loadUrl(url, callback); | ||
} | ||
}, { | ||
key: 'read', | ||
value: function read(language, namespace, callback) { | ||
var loadPath = this.options.loadPath; | ||
if (typeof this.options.loadPath === 'function') { | ||
loadPath = this.options.loadPath([language], [namespace]); | ||
var url = this.services.interpolator.interpolate(loadPath, { | ||
lng: languages.join('+'), | ||
ns: namespaces.join('+') | ||
}); | ||
this.loadUrl(url, callback); | ||
} | ||
}, { | ||
key: "read", | ||
value: function read(language, namespace, callback) { | ||
var loadPath = this.options.loadPath; | ||
var url = this.services.interpolator.interpolate(loadPath, { lng: language, ns: namespace }); | ||
if (typeof this.options.loadPath === 'function') { | ||
loadPath = this.options.loadPath([language], [namespace]); | ||
} | ||
this.loadUrl(url, callback); | ||
} | ||
}, { | ||
key: 'loadUrl', | ||
value: function loadUrl(url, callback) { | ||
var _this = this; | ||
var url = this.services.interpolator.interpolate(loadPath, { | ||
lng: language, | ||
ns: namespace | ||
}); | ||
this.loadUrl(url, callback); | ||
} | ||
}, { | ||
key: "loadUrl", | ||
value: function loadUrl(url, callback) { | ||
var _this = this; | ||
this.options.ajax(url, this.options, function (data, xhr) { | ||
if (xhr.status >= 500 && xhr.status < 600) return callback('failed loading ' + url, true /* retry */); | ||
if (xhr.status >= 400 && xhr.status < 500) return callback('failed loading ' + url, false /* no retry */); | ||
this.options.ajax(url, this.options, function (data, xhr) { | ||
if (xhr.status >= 500 && xhr.status < 600) return callback('failed loading ' + url, true | ||
/* retry */ | ||
); | ||
if (xhr.status >= 400 && xhr.status < 500) return callback('failed loading ' + url, false | ||
/* no retry */ | ||
); | ||
var ret, err; | ||
var ret = void 0, | ||
err = void 0; | ||
try { | ||
ret = _this.options.parse(data, url); | ||
} catch (e) { | ||
err = 'failed parsing ' + url + ' to json'; | ||
} | ||
if (err) return callback(err, false); | ||
callback(null, ret); | ||
}); | ||
} | ||
}, { | ||
key: 'create', | ||
value: function create(languages, namespace, key, fallbackValue) { | ||
var _this2 = this; | ||
try { | ||
ret = _this.options.parse(data, url); | ||
} catch (e) { | ||
err = 'failed parsing ' + url + ' to json'; | ||
} | ||
if (typeof languages === 'string') languages = [languages]; | ||
if (err) return callback(err, false); | ||
callback(null, ret); | ||
}); | ||
} | ||
}, { | ||
key: "create", | ||
value: function create(languages, namespace, key, fallbackValue) { | ||
var _this2 = this; | ||
var payload = {}; | ||
payload[key] = fallbackValue || ''; | ||
if (typeof languages === 'string') languages = [languages]; | ||
var payload = {}; | ||
payload[key] = fallbackValue || ''; | ||
languages.forEach(function (lng) { | ||
var url = _this2.services.interpolator.interpolate(_this2.options.addPath, { | ||
lng: lng, | ||
ns: namespace | ||
}); | ||
languages.forEach(function (lng) { | ||
var url = _this2.services.interpolator.interpolate(_this2.options.addPath, { lng: lng, ns: namespace }); | ||
_this2.options.ajax(url, _this2.options, function (data, xhr) {//const statusCode = xhr.status.toString(); | ||
// TODO: if statusCode === 4xx do log | ||
}, payload); | ||
}); | ||
} | ||
}]); | ||
_this2.options.ajax(url, _this2.options, function (data, xhr) { | ||
//const statusCode = xhr.status.toString(); | ||
// TODO: if statusCode === 4xx do log | ||
}, payload); | ||
}); | ||
} | ||
}]); | ||
return Backend; | ||
}(); | ||
Backend.type = 'backend'; | ||
return Backend; | ||
}(); | ||
Backend.type = 'backend'; | ||
return Backend; | ||
}))); | ||
})); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.i18nextXHRBackend=e()}(this,function(){"use strict";function t(t){return r.call(s.call(arguments,1),function(e){if(e)for(var n in e)void 0===t[n]&&(t[n]=e[n])}),t}function e(t,e){if(e&&"object"===(void 0===e?"undefined":l(e))){var n="",o=encodeURIComponent;for(var i in e)n+="&"+o(i)+"="+o(e[i]);if(!n)return t;t=t+(-1!==t.indexOf("?")?"&":"?")+n.slice(1)}return t}function n(t,n,o,i,a){i&&"object"===(void 0===i?"undefined":l(i))&&(a||(i._t=new Date),i=e("",i).slice(1)),n.queryStringParams&&(t=e(t,n.queryStringParams));try{var r;r=XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("MSXML2.XMLHTTP.3.0"),r.open(i?"POST":"GET",t,1),n.crossDomain||r.setRequestHeader("X-Requested-With","XMLHttpRequest"),r.withCredentials=!!n.withCredentials,i&&r.setRequestHeader("Content-type","application/x-www-form-urlencoded"),r.overrideMimeType&&r.overrideMimeType("application/json");var s=n.customHeaders;if(s)for(var u in s)r.setRequestHeader(u,s[u]);r.onreadystatechange=function(){r.readyState>3&&o&&o(r.responseText,r)},r.send(i)}catch(t){console&&console.log(t)}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(){return{loadPath:"/locales/{{lng}}/{{ns}}.json",addPath:"/locales/add/{{lng}}/{{ns}}",allowMultiLoading:!1,parse:JSON.parse,crossDomain:!1,ajax:n}}var a=[],r=a.forEach,s=a.slice,l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),c=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};o(this,e),this.init(t,n),this.type="backend"}return u(e,[{key:"init",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.services=e,this.options=t(n,this.options||{},i())}},{key:"readMulti",value:function(t,e,n){var o=this.options.loadPath;"function"==typeof this.options.loadPath&&(o=this.options.loadPath(t,e));var i=this.services.interpolator.interpolate(o,{lng:t.join("+"),ns:e.join("+")});this.loadUrl(i,n)}},{key:"read",value:function(t,e,n){var o=this.options.loadPath;"function"==typeof this.options.loadPath&&(o=this.options.loadPath([t],[e]));var i=this.services.interpolator.interpolate(o,{lng:t,ns:e});this.loadUrl(i,n)}},{key:"loadUrl",value:function(t,e){var n=this;this.options.ajax(t,this.options,function(o,i){if(i.status>=500&&i.status<600)return e("failed loading "+t,!0);if(i.status>=400&&i.status<500)return e("failed loading "+t,!1);var a=void 0,r=void 0;try{a=n.options.parse(o,t)}catch(e){r="failed parsing "+t+" to json"}if(r)return e(r,!1);e(null,a)})}},{key:"create",value:function(t,e,n,o){var i=this;"string"==typeof t&&(t=[t]);var a={};a[n]=o||"",t.forEach(function(t){var n=i.services.interpolator.interpolate(i.options.addPath,{lng:t,ns:e});i.options.ajax(n,i.options,function(t,e){},a)})}}]),e}();return c.type="backend",c}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).i18nextXHRBackend=e()}(this,function(){"use strict";function t(t,e){for(var o=0;o<e.length;o++){var n=e[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var e=[],o=e.forEach,n=e.slice;function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(t){return(r="function"==typeof Symbol&&"symbol"===i(Symbol.iterator)?function(t){return i(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":i(t)})(t)}function a(t,e){if(e&&"object"===r(e)){var o="",n=encodeURIComponent;for(var i in e)o+="&"+n(i)+"="+n(e[i]);if(!o)return t;t=t+(-1!==t.indexOf("?")?"&":"?")+o.slice(1)}return t}function s(t,e,o,n,i){n&&"object"===r(n)&&(i||(n._t=new Date),n=a("",n).slice(1)),e.queryStringParams&&(t=a(t,e.queryStringParams));try{var s;(s=XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("MSXML2.XMLHTTP.3.0")).open(n?"POST":"GET",t,1),e.crossDomain||s.setRequestHeader("X-Requested-With","XMLHttpRequest"),s.withCredentials=!!e.withCredentials,n&&s.setRequestHeader("Content-type","application/x-www-form-urlencoded"),s.overrideMimeType&&s.overrideMimeType("application/json");var l=e.customHeaders;if(l)for(var u in l)s.setRequestHeader(u,l[u]);s.onreadystatechange=function(){s.readyState>3&&o&&o(s.responseText,s)},s.send(n)}catch(t){console&&console.log(t)}}var l=function(){function e(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),this.init(t,o),this.type="backend"}var i,r,a;return i=e,(r=[{key:"init",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.services=t,this.options=function(t){return o.call(n.call(arguments,1),function(e){if(e)for(var o in e)void 0===t[o]&&(t[o]=e[o])}),t}(e,this.options||{},{loadPath:"/locales/{{lng}}/{{ns}}.json",addPath:"/locales/add/{{lng}}/{{ns}}",allowMultiLoading:!1,parse:JSON.parse,crossDomain:!1,ajax:s})}},{key:"readMulti",value:function(t,e,o){var n=this.options.loadPath;"function"==typeof this.options.loadPath&&(n=this.options.loadPath(t,e));var i=this.services.interpolator.interpolate(n,{lng:t.join("+"),ns:e.join("+")});this.loadUrl(i,o)}},{key:"read",value:function(t,e,o){var n=this.options.loadPath;"function"==typeof this.options.loadPath&&(n=this.options.loadPath([t],[e]));var i=this.services.interpolator.interpolate(n,{lng:t,ns:e});this.loadUrl(i,o)}},{key:"loadUrl",value:function(t,e){var o=this;this.options.ajax(t,this.options,function(n,i){if(i.status>=500&&i.status<600)return e("failed loading "+t,!0);if(i.status>=400&&i.status<500)return e("failed loading "+t,!1);var r,a;try{r=o.options.parse(n,t)}catch(e){a="failed parsing "+t+" to json"}if(a)return e(a,!1);e(null,r)})}},{key:"create",value:function(t,e,o,n){var i=this;"string"==typeof t&&(t=[t]);var r={};r[o]=n||"",t.forEach(function(t){var o=i.services.interpolator.interpolate(i.options.addPath,{lng:t,ns:e});i.options.ajax(o,i.options,function(t,e){},r)})}}])&&t(i.prototype,r),a&&t(i,a),e}();return l.type="backend",l}); |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.i18nextXHRBackend = factory()); | ||
}(this, (function () { 'use strict'; | ||
(global = global || self, global.i18nextXHRBackend = factory()); | ||
}(this, function () { 'use strict'; | ||
var arr = []; | ||
var each = arr.forEach; | ||
var slice = arr.slice; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function defaults(obj) { | ||
each.call(slice.call(arguments, 1), function (source) { | ||
if (source) { | ||
for (var prop in source) { | ||
if (obj[prop] === undefined) obj[prop] = source[prop]; | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
}); | ||
return obj; | ||
} | ||
} | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function addQueryString(url, params) { | ||
if (params && (typeof params === 'undefined' ? 'undefined' : _typeof(params)) === 'object') { | ||
var queryString = '', | ||
e = encodeURIComponent; | ||
var arr = []; | ||
var each = arr.forEach; | ||
var slice = arr.slice; | ||
function defaults(obj) { | ||
each.call(slice.call(arguments, 1), function (source) { | ||
if (source) { | ||
for (var prop in source) { | ||
if (obj[prop] === undefined) obj[prop] = source[prop]; | ||
} | ||
} | ||
}); | ||
return obj; | ||
} | ||
// Must encode data | ||
for (var paramName in params) { | ||
queryString += '&' + e(paramName) + '=' + e(params[paramName]); | ||
} | ||
function _typeof2(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof2(obj); } | ||
if (!queryString) { | ||
return url; | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") { | ||
_typeof = function _typeof(obj) { | ||
return _typeof2(obj); | ||
}; | ||
} else { | ||
_typeof = function _typeof(obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj); | ||
}; | ||
} | ||
url = url + (url.indexOf('?') !== -1 ? '&' : '?') + queryString.slice(1); | ||
return _typeof(obj); | ||
} | ||
return url; | ||
} | ||
function addQueryString(url, params) { | ||
if (params && _typeof(params) === 'object') { | ||
var queryString = '', | ||
e = encodeURIComponent; // Must encode data | ||
// https://gist.github.com/Xeoncross/7663273 | ||
function ajax(url, options, callback, data, cache) { | ||
for (var paramName in params) { | ||
queryString += '&' + e(paramName) + '=' + e(params[paramName]); | ||
} | ||
if (data && (typeof data === 'undefined' ? 'undefined' : _typeof(data)) === 'object') { | ||
if (!cache) { | ||
data['_t'] = new Date(); | ||
if (!queryString) { | ||
return url; | ||
} | ||
url = url + (url.indexOf('?') !== -1 ? '&' : '?') + queryString.slice(1); | ||
} | ||
// URL encoded form data must be in querystring format | ||
data = addQueryString('', data).slice(1); | ||
} | ||
if (options.queryStringParams) { | ||
url = addQueryString(url, options.queryStringParams); | ||
} | ||
return url; | ||
} // https://gist.github.com/Xeoncross/7663273 | ||
try { | ||
var x; | ||
if (XMLHttpRequest) { | ||
x = new XMLHttpRequest(); | ||
} else { | ||
x = new ActiveXObject('MSXML2.XMLHTTP.3.0'); | ||
function ajax(url, options, callback, data, cache) { | ||
if (data && _typeof(data) === 'object') { | ||
if (!cache) { | ||
data['_t'] = new Date(); | ||
} // URL encoded form data must be in querystring format | ||
data = addQueryString('', data).slice(1); | ||
} | ||
x.open(data ? 'POST' : 'GET', url, 1); | ||
if (!options.crossDomain) { | ||
x.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); | ||
if (options.queryStringParams) { | ||
url = addQueryString(url, options.queryStringParams); | ||
} | ||
x.withCredentials = !!options.withCredentials; | ||
if (data) { | ||
x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | ||
} | ||
if (x.overrideMimeType) { | ||
x.overrideMimeType("application/json"); | ||
} | ||
var h = options.customHeaders; | ||
if (h) { | ||
for (var i in h) { | ||
x.setRequestHeader(i, h[i]); | ||
try { | ||
var x; | ||
if (XMLHttpRequest) { | ||
x = new XMLHttpRequest(); | ||
} else { | ||
x = new ActiveXObject('MSXML2.XMLHTTP.3.0'); | ||
} | ||
} | ||
x.onreadystatechange = function () { | ||
x.readyState > 3 && callback && callback(x.responseText, x); | ||
}; | ||
x.send(data); | ||
} catch (e) { | ||
console && console.log(e); | ||
} | ||
} | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
x.open(data ? 'POST' : 'GET', url, 1); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
if (!options.crossDomain) { | ||
x.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); | ||
} | ||
function getDefaults() { | ||
return { | ||
loadPath: '/locales/{{lng}}/{{ns}}.json', | ||
addPath: '/locales/add/{{lng}}/{{ns}}', | ||
allowMultiLoading: false, | ||
parse: JSON.parse, | ||
crossDomain: false, | ||
ajax: ajax | ||
}; | ||
} | ||
x.withCredentials = !!options.withCredentials; | ||
var Backend = function () { | ||
function Backend(services) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (data) { | ||
x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | ||
} | ||
_classCallCheck(this, Backend); | ||
if (x.overrideMimeType) { | ||
x.overrideMimeType("application/json"); | ||
} | ||
this.init(services, options); | ||
var h = options.customHeaders; | ||
this.type = 'backend'; | ||
if (h) { | ||
for (var i in h) { | ||
x.setRequestHeader(i, h[i]); | ||
} | ||
} | ||
x.onreadystatechange = function () { | ||
x.readyState > 3 && callback && callback(x.responseText, x); | ||
}; | ||
x.send(data); | ||
} catch (e) { | ||
console && console.log(e); | ||
} | ||
} | ||
_createClass(Backend, [{ | ||
key: 'init', | ||
value: function init(services) { | ||
function getDefaults() { | ||
return { | ||
loadPath: '/locales/{{lng}}/{{ns}}.json', | ||
addPath: '/locales/add/{{lng}}/{{ns}}', | ||
allowMultiLoading: false, | ||
parse: JSON.parse, | ||
crossDomain: false, | ||
ajax: ajax | ||
}; | ||
} | ||
var Backend = | ||
/*#__PURE__*/ | ||
function () { | ||
function Backend(services) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
this.services = services; | ||
this.options = defaults(options, this.options || {}, getDefaults()); | ||
_classCallCheck(this, Backend); | ||
this.init(services, options); | ||
this.type = 'backend'; | ||
} | ||
}, { | ||
key: 'readMulti', | ||
value: function readMulti(languages, namespaces, callback) { | ||
var loadPath = this.options.loadPath; | ||
if (typeof this.options.loadPath === 'function') { | ||
loadPath = this.options.loadPath(languages, namespaces); | ||
_createClass(Backend, [{ | ||
key: "init", | ||
value: function init(services) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
this.services = services; | ||
this.options = defaults(options, this.options || {}, getDefaults()); | ||
} | ||
}, { | ||
key: "readMulti", | ||
value: function readMulti(languages, namespaces, callback) { | ||
var loadPath = this.options.loadPath; | ||
var url = this.services.interpolator.interpolate(loadPath, { lng: languages.join('+'), ns: namespaces.join('+') }); | ||
if (typeof this.options.loadPath === 'function') { | ||
loadPath = this.options.loadPath(languages, namespaces); | ||
} | ||
this.loadUrl(url, callback); | ||
} | ||
}, { | ||
key: 'read', | ||
value: function read(language, namespace, callback) { | ||
var loadPath = this.options.loadPath; | ||
if (typeof this.options.loadPath === 'function') { | ||
loadPath = this.options.loadPath([language], [namespace]); | ||
var url = this.services.interpolator.interpolate(loadPath, { | ||
lng: languages.join('+'), | ||
ns: namespaces.join('+') | ||
}); | ||
this.loadUrl(url, callback); | ||
} | ||
}, { | ||
key: "read", | ||
value: function read(language, namespace, callback) { | ||
var loadPath = this.options.loadPath; | ||
var url = this.services.interpolator.interpolate(loadPath, { lng: language, ns: namespace }); | ||
if (typeof this.options.loadPath === 'function') { | ||
loadPath = this.options.loadPath([language], [namespace]); | ||
} | ||
this.loadUrl(url, callback); | ||
} | ||
}, { | ||
key: 'loadUrl', | ||
value: function loadUrl(url, callback) { | ||
var _this = this; | ||
var url = this.services.interpolator.interpolate(loadPath, { | ||
lng: language, | ||
ns: namespace | ||
}); | ||
this.loadUrl(url, callback); | ||
} | ||
}, { | ||
key: "loadUrl", | ||
value: function loadUrl(url, callback) { | ||
var _this = this; | ||
this.options.ajax(url, this.options, function (data, xhr) { | ||
if (xhr.status >= 500 && xhr.status < 600) return callback('failed loading ' + url, true /* retry */); | ||
if (xhr.status >= 400 && xhr.status < 500) return callback('failed loading ' + url, false /* no retry */); | ||
this.options.ajax(url, this.options, function (data, xhr) { | ||
if (xhr.status >= 500 && xhr.status < 600) return callback('failed loading ' + url, true | ||
/* retry */ | ||
); | ||
if (xhr.status >= 400 && xhr.status < 500) return callback('failed loading ' + url, false | ||
/* no retry */ | ||
); | ||
var ret, err; | ||
var ret = void 0, | ||
err = void 0; | ||
try { | ||
ret = _this.options.parse(data, url); | ||
} catch (e) { | ||
err = 'failed parsing ' + url + ' to json'; | ||
} | ||
if (err) return callback(err, false); | ||
callback(null, ret); | ||
}); | ||
} | ||
}, { | ||
key: 'create', | ||
value: function create(languages, namespace, key, fallbackValue) { | ||
var _this2 = this; | ||
try { | ||
ret = _this.options.parse(data, url); | ||
} catch (e) { | ||
err = 'failed parsing ' + url + ' to json'; | ||
} | ||
if (typeof languages === 'string') languages = [languages]; | ||
if (err) return callback(err, false); | ||
callback(null, ret); | ||
}); | ||
} | ||
}, { | ||
key: "create", | ||
value: function create(languages, namespace, key, fallbackValue) { | ||
var _this2 = this; | ||
var payload = {}; | ||
payload[key] = fallbackValue || ''; | ||
if (typeof languages === 'string') languages = [languages]; | ||
var payload = {}; | ||
payload[key] = fallbackValue || ''; | ||
languages.forEach(function (lng) { | ||
var url = _this2.services.interpolator.interpolate(_this2.options.addPath, { | ||
lng: lng, | ||
ns: namespace | ||
}); | ||
languages.forEach(function (lng) { | ||
var url = _this2.services.interpolator.interpolate(_this2.options.addPath, { lng: lng, ns: namespace }); | ||
_this2.options.ajax(url, _this2.options, function (data, xhr) {//const statusCode = xhr.status.toString(); | ||
// TODO: if statusCode === 4xx do log | ||
}, payload); | ||
}); | ||
} | ||
}]); | ||
_this2.options.ajax(url, _this2.options, function (data, xhr) { | ||
//const statusCode = xhr.status.toString(); | ||
// TODO: if statusCode === 4xx do log | ||
}, payload); | ||
}); | ||
} | ||
}]); | ||
return Backend; | ||
}(); | ||
Backend.type = 'backend'; | ||
return Backend; | ||
}(); | ||
Backend.type = 'backend'; | ||
return Backend; | ||
}))); | ||
})); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.i18nextXHRBackend=e()}(this,function(){"use strict";function t(t){return r.call(s.call(arguments,1),function(e){if(e)for(var n in e)void 0===t[n]&&(t[n]=e[n])}),t}function e(t,e){if(e&&"object"===(void 0===e?"undefined":l(e))){var n="",o=encodeURIComponent;for(var i in e)n+="&"+o(i)+"="+o(e[i]);if(!n)return t;t=t+(-1!==t.indexOf("?")?"&":"?")+n.slice(1)}return t}function n(t,n,o,i,a){i&&"object"===(void 0===i?"undefined":l(i))&&(a||(i._t=new Date),i=e("",i).slice(1)),n.queryStringParams&&(t=e(t,n.queryStringParams));try{var r;r=XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("MSXML2.XMLHTTP.3.0"),r.open(i?"POST":"GET",t,1),n.crossDomain||r.setRequestHeader("X-Requested-With","XMLHttpRequest"),r.withCredentials=!!n.withCredentials,i&&r.setRequestHeader("Content-type","application/x-www-form-urlencoded"),r.overrideMimeType&&r.overrideMimeType("application/json");var s=n.customHeaders;if(s)for(var u in s)r.setRequestHeader(u,s[u]);r.onreadystatechange=function(){r.readyState>3&&o&&o(r.responseText,r)},r.send(i)}catch(t){console&&console.log(t)}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(){return{loadPath:"/locales/{{lng}}/{{ns}}.json",addPath:"/locales/add/{{lng}}/{{ns}}",allowMultiLoading:!1,parse:JSON.parse,crossDomain:!1,ajax:n}}var a=[],r=a.forEach,s=a.slice,l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),c=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};o(this,e),this.init(t,n),this.type="backend"}return u(e,[{key:"init",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.services=e,this.options=t(n,this.options||{},i())}},{key:"readMulti",value:function(t,e,n){var o=this.options.loadPath;"function"==typeof this.options.loadPath&&(o=this.options.loadPath(t,e));var i=this.services.interpolator.interpolate(o,{lng:t.join("+"),ns:e.join("+")});this.loadUrl(i,n)}},{key:"read",value:function(t,e,n){var o=this.options.loadPath;"function"==typeof this.options.loadPath&&(o=this.options.loadPath([t],[e]));var i=this.services.interpolator.interpolate(o,{lng:t,ns:e});this.loadUrl(i,n)}},{key:"loadUrl",value:function(t,e){var n=this;this.options.ajax(t,this.options,function(o,i){if(i.status>=500&&i.status<600)return e("failed loading "+t,!0);if(i.status>=400&&i.status<500)return e("failed loading "+t,!1);var a=void 0,r=void 0;try{a=n.options.parse(o,t)}catch(e){r="failed parsing "+t+" to json"}if(r)return e(r,!1);e(null,a)})}},{key:"create",value:function(t,e,n,o){var i=this;"string"==typeof t&&(t=[t]);var a={};a[n]=o||"",t.forEach(function(t){var n=i.services.interpolator.interpolate(i.options.addPath,{lng:t,ns:e});i.options.ajax(n,i.options,function(t,e){},a)})}}]),e}();return c.type="backend",c}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).i18nextXHRBackend=e()}(this,function(){"use strict";function t(t,e){for(var o=0;o<e.length;o++){var n=e[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var e=[],o=e.forEach,n=e.slice;function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(t){return(r="function"==typeof Symbol&&"symbol"===i(Symbol.iterator)?function(t){return i(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":i(t)})(t)}function a(t,e){if(e&&"object"===r(e)){var o="",n=encodeURIComponent;for(var i in e)o+="&"+n(i)+"="+n(e[i]);if(!o)return t;t=t+(-1!==t.indexOf("?")?"&":"?")+o.slice(1)}return t}function s(t,e,o,n,i){n&&"object"===r(n)&&(i||(n._t=new Date),n=a("",n).slice(1)),e.queryStringParams&&(t=a(t,e.queryStringParams));try{var s;(s=XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("MSXML2.XMLHTTP.3.0")).open(n?"POST":"GET",t,1),e.crossDomain||s.setRequestHeader("X-Requested-With","XMLHttpRequest"),s.withCredentials=!!e.withCredentials,n&&s.setRequestHeader("Content-type","application/x-www-form-urlencoded"),s.overrideMimeType&&s.overrideMimeType("application/json");var l=e.customHeaders;if(l)for(var u in l)s.setRequestHeader(u,l[u]);s.onreadystatechange=function(){s.readyState>3&&o&&o(s.responseText,s)},s.send(n)}catch(t){console&&console.log(t)}}var l=function(){function e(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),this.init(t,o),this.type="backend"}var i,r,a;return i=e,(r=[{key:"init",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.services=t,this.options=function(t){return o.call(n.call(arguments,1),function(e){if(e)for(var o in e)void 0===t[o]&&(t[o]=e[o])}),t}(e,this.options||{},{loadPath:"/locales/{{lng}}/{{ns}}.json",addPath:"/locales/add/{{lng}}/{{ns}}",allowMultiLoading:!1,parse:JSON.parse,crossDomain:!1,ajax:s})}},{key:"readMulti",value:function(t,e,o){var n=this.options.loadPath;"function"==typeof this.options.loadPath&&(n=this.options.loadPath(t,e));var i=this.services.interpolator.interpolate(n,{lng:t.join("+"),ns:e.join("+")});this.loadUrl(i,o)}},{key:"read",value:function(t,e,o){var n=this.options.loadPath;"function"==typeof this.options.loadPath&&(n=this.options.loadPath([t],[e]));var i=this.services.interpolator.interpolate(n,{lng:t,ns:e});this.loadUrl(i,o)}},{key:"loadUrl",value:function(t,e){var o=this;this.options.ajax(t,this.options,function(n,i){if(i.status>=500&&i.status<600)return e("failed loading "+t,!0);if(i.status>=400&&i.status<500)return e("failed loading "+t,!1);var r,a;try{r=o.options.parse(n,t)}catch(e){a="failed parsing "+t+" to json"}if(a)return e(a,!1);e(null,r)})}},{key:"create",value:function(t,e,o,n){var i=this;"string"==typeof t&&(t=[t]);var r={};r[o]=n||"",t.forEach(function(t){var o=i.services.interpolator.interpolate(i.options.addPath,{lng:t,ns:e});i.options.ajax(o,i.options,function(t,e){},r)})}}])&&t(i.prototype,r),a&&t(i,a),e}();return l.type="backend",l}); |
/* eslint no-var: 0 */ | ||
var main = require('./dist/commonjs/index.js').default; | ||
var main = require('./dist/cjs/i18nextXHRBackend.js').default; | ||
module.exports = main; | ||
module.exports.default = main; |
{ | ||
"name": "i18next-xhr-backend", | ||
"version": "2.0.1", | ||
"version": "3.0.0", | ||
"description": "backend layer for i18next using browsers xhr", | ||
"main": "./index.js", | ||
"main": "./dist/cjs/i18nextXHRBackend.js", | ||
"module": "./dist/esm/i18nextXHRBackend.js", | ||
"types": "./index.d.ts", | ||
"jsnext:main": "dist/es/index.js", | ||
"keywords": [ | ||
@@ -18,10 +18,11 @@ "i18next", | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.4.5" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "6.18.0", | ||
"babel-core": "6.21.0", | ||
"babel-eslint": "7.1.1", | ||
"babel-preset-es2015": "6.18.0", | ||
"babel-preset-stage-0": "6.16.0", | ||
"babelify": "7.3.0", | ||
"@babel/core": "^7.4.5", | ||
"@babel/plugin-transform-runtime": "^7.4.4", | ||
"@babel/preset-env": "^7.4.5", | ||
"babel-eslint": "^10.0.1", | ||
"babelify": "^10.0.0", | ||
"browserify": "13.3.0", | ||
@@ -31,2 +32,3 @@ "browserify-istanbul": "2.0.0", | ||
"coveralls": "2.11.15", | ||
"cpy-cli": "^2.0.0", | ||
"dtslint": "^0.4.2", | ||
@@ -48,17 +50,14 @@ "eslint": "3.13.0", | ||
"karma-phantomjs-launcher": "1.0.2", | ||
"karma-rollup-preprocessor": "3.0.3", | ||
"karma-sinon": "1.0.5", | ||
"karma-spec-reporter": "0.0.26", | ||
"mkdirp": "0.5.1", | ||
"mocha": "3.2.0", | ||
"phantomjs-prebuilt": "2.1.14", | ||
"rimraf": "2.5.4", | ||
"rollup": "0.41.1", | ||
"rollup-plugin-babel": "2.7.1", | ||
"rollup-plugin-node-resolve": "2.0.0", | ||
"rollup-plugin-uglify": "1.0.1", | ||
"rollup": "^1.13.1", | ||
"rollup-plugin-babel": "^4.3.2", | ||
"rollup-plugin-node-resolve": "^5.0.1", | ||
"rollup-plugin-terser": "^5.0.0", | ||
"sinon": "1.17.7", | ||
"tslint": "^5.12.1", | ||
"typescript": "^3.3.1", | ||
"yargs": "6.6.0" | ||
"typescript": "^3.3.1" | ||
}, | ||
@@ -70,13 +69,3 @@ "scripts": { | ||
"tdd": "karma start karma.conf.js", | ||
"clean": "rimraf dist && mkdirp dist", | ||
"copy": "cp ./dist/umd/i18nextXHRBackend.min.js ./i18nextXHRBackend.min.js && cp ./dist/umd/i18nextXHRBackend.js ./i18nextXHRBackend.js", | ||
"copy-win": "xcopy .\\dist\\umd\\i18nextXHRBackend.min.js .\\i18nextXHRBackend.min.js /y && xcopy .\\dist\\umd\\i18nextXHRBackend.js .\\i18nextXHRBackend.js /y", | ||
"build:es": "BABEL_ENV=jsnext babel src --out-dir dist/es", | ||
"build:es-win": "SET BABEL_ENV=jsnext babel src --out-dir dist/es", | ||
"build:cjs": "babel src --out-dir dist/commonjs", | ||
"build:umd": "rollup -c rollup.config.js --format umd && rollup -c rollup.config.js --format umd --uglify", | ||
"build:amd": "rollup -c rollup.config.js --format amd && rollup -c rollup.config.js --format umd --uglify", | ||
"build:iife": "rollup -c rollup.config.js --format iife && rollup -c rollup.config.js --format iife --uglify", | ||
"build": "npm run clean && npm run build:cjs && npm run build:es && npm run build:umd && npm run copy", | ||
"build-win": "npm run clean && npm run build:cjs && npm run build:es-win && npm run build:umd && npm run copy-win", | ||
"build": "rimraf dist && rollup -c && cpy \"./dist/umd/*.js\" ./", | ||
"preversion": "npm run test && npm run build && git push", | ||
@@ -83,0 +72,0 @@ "postversion": "git push && git push --tags" |
@@ -73,2 +73,11 @@ # Introduction | ||
withCredentials: false, | ||
// overrideMimeType sets request.overrideMimeType("application/json") | ||
overrideMimeType: false, | ||
// custom request headers sets request.setRequestHeader(key, value) | ||
customHeaders: { | ||
authorization: 'foo', | ||
// ... | ||
}, | ||
@@ -124,33 +133,2 @@ // define a custom xhr function | ||
#### Usage with webpack's bundle loader instead of using xhr requests | ||
To use with webpack, install [bundle-loader](https://github.com/webpack/bundle-loader) and [json-loader](https://github.com/webpack/json-loader). | ||
Define a custom xhr function, webpack's bundle loader will load the translations for you. | ||
```js | ||
function loadLocales(url, options, callback, data) { | ||
try { | ||
let waitForLocale = require('bundle!./locales/'+url+'.json'); | ||
waitForLocale((locale) => { | ||
callback(locale, {status: '200'}); | ||
}) | ||
} catch (e) { | ||
callback(null, {status: '404'}); | ||
} | ||
} | ||
i18next | ||
.use(XHR) | ||
.init({ | ||
backend: { | ||
loadPath: '{{lng}}', | ||
parse: (data) => data, | ||
ajax: loadLocales | ||
} | ||
}, (err, t) => { | ||
// ... | ||
}); | ||
``` | ||
#### TypeScript definitions | ||
@@ -157,0 +135,0 @@ |
import babel from 'rollup-plugin-babel'; | ||
import uglify from 'rollup-plugin-uglify'; | ||
import nodeResolve from 'rollup-plugin-node-resolve'; | ||
import { argv } from 'yargs'; | ||
import { terser } from 'rollup-plugin-terser'; | ||
import pkg from './package.json'; | ||
const format = argv.format || argv.f || 'iife'; | ||
const compress = argv.uglify; | ||
const getBabelOptions = ({ useESModules }) => ({ | ||
exclude: /node_modules/, | ||
runtimeHelpers: true, | ||
plugins: [ | ||
['@babel/transform-runtime', { useESModules }] | ||
] | ||
}); | ||
const babelOptions = { | ||
exclude: 'node_modules/**', | ||
presets: [['es2015', { modules: false }], 'stage-0'], | ||
babelrc: false | ||
}; | ||
const input = './src/index.js'; | ||
const name = 'i18nextXHRBackend' | ||
// check relative and absolute paths for windows and unix | ||
const external = id => !id.startsWith('.') && !id.startsWith('/') && !id.includes(':'); | ||
const dest = { | ||
amd: `dist/amd/i18nextXHRBackend${compress ? '.min' : ''}.js`, | ||
umd: `dist/umd/i18nextXHRBackend${compress ? '.min' : ''}.js`, | ||
iife: `dist/iife/i18nextXHRBackend${compress ? '.min' : ''}.js` | ||
}[format]; | ||
export default [ | ||
{ | ||
input, | ||
output: { format: 'cjs', file: pkg.main }, | ||
external, | ||
plugins: [ | ||
babel(getBabelOptions({ useESModules: false })) | ||
] | ||
}, | ||
export default { | ||
entry: 'src/index.js', | ||
format, | ||
plugins: [ | ||
babel(babelOptions), | ||
nodeResolve({ jsnext: true }) | ||
].concat(compress ? uglify() : []), | ||
moduleName: 'i18nextXHRBackend', | ||
//moduleId: 'i18nextXHRBackend', | ||
dest | ||
}; | ||
{ | ||
input, | ||
output: { format: 'esm', file: pkg.module }, | ||
external, | ||
plugins: [ | ||
babel(getBabelOptions({ useESModules: true })) | ||
] | ||
}, | ||
{ | ||
input, | ||
output: { format: 'umd', name, file: `dist/umd/${name}.js` }, | ||
plugins: [ | ||
babel(getBabelOptions({ useESModules: true })), | ||
nodeResolve() | ||
], | ||
}, | ||
{ | ||
input, | ||
output: { format: 'umd', name, file: `dist/umd/${name}.min.js` }, | ||
plugins: [ | ||
babel(getBabelOptions({ useESModules: true })), | ||
nodeResolve(), | ||
terser() | ||
], | ||
} | ||
] |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
38
908
45927
1
17
151
1
+ Added@babel/runtime@^7.4.5
+ Added@babel/runtime@7.26.7(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)