i18next-xhr-backend
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -0,1 +1,4 @@ | ||
### 1.4.0 | ||
- add `queryStringParams` option [PR255](https://github.com/i18next/i18next-xhr-backend/pull/255) | ||
### 1.3.0 | ||
@@ -2,0 +5,0 @@ - add support for custom headers [PR250](https://github.com/i18next/i18next-xhr-backend/pull/250) |
@@ -9,14 +9,36 @@ 'use strict'; | ||
function addQueryString(url, params) { | ||
if (params && (typeof params === 'undefined' ? 'undefined' : _typeof(params)) === 'object') { | ||
var queryString = '', | ||
e = encodeURIComponent; | ||
// Must encode data | ||
for (var paramName in params) { | ||
queryString += '&' + e(paramName) + '=' + e(params[paramName]); | ||
} | ||
if (!queryString) { | ||
return url; | ||
} | ||
url = url + (url.includes('?') ? '&' : '?') + queryString.slice(1); | ||
} | ||
return url; | ||
} | ||
// https://gist.github.com/Xeoncross/7663273 | ||
function ajax(url, options, callback, data, cache) { | ||
// Must encode data | ||
if (data && (typeof data === 'undefined' ? 'undefined' : _typeof(data)) === 'object') { | ||
var y = '', | ||
e = encodeURIComponent; | ||
for (var m in data) { | ||
y += '&' + e(m) + '=' + e(data[m]); | ||
if (!cache) { | ||
data['_t'] = new Date(); | ||
} | ||
data = y.slice(1) + (!cache ? '&_t=' + new Date() : ''); | ||
data = addQueryString(data, data); | ||
} | ||
if (options.queryStringParams) { | ||
url = addQueryString(url, options.queryStringParams); | ||
} | ||
try { | ||
@@ -23,0 +45,0 @@ var x = new (XMLHttpRequest || ActiveXObject)('MSXML2.XMLHTTP.3.0'); |
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 addQueryString(url, params) { | ||
if (params && (typeof params === 'undefined' ? 'undefined' : _typeof(params)) === 'object') { | ||
var queryString = '', | ||
e = encodeURIComponent; | ||
// Must encode data | ||
for (var paramName in params) { | ||
queryString += '&' + e(paramName) + '=' + e(params[paramName]); | ||
} | ||
if (!queryString) { | ||
return url; | ||
} | ||
url = url + (url.includes('?') ? '&' : '?') + queryString.slice(1); | ||
} | ||
return url; | ||
} | ||
// https://gist.github.com/Xeoncross/7663273 | ||
function ajax(url, options, callback, data, cache) { | ||
// Must encode data | ||
if (data && (typeof data === 'undefined' ? 'undefined' : _typeof(data)) === 'object') { | ||
var y = '', | ||
e = encodeURIComponent; | ||
for (var m in data) { | ||
y += '&' + e(m) + '=' + e(data[m]); | ||
if (!cache) { | ||
data['_t'] = new Date(); | ||
} | ||
data = y.slice(1) + (!cache ? '&_t=' + new Date() : ''); | ||
data = addQueryString(data, data); | ||
} | ||
if (options.queryStringParams) { | ||
url = addQueryString(url, options.queryStringParams); | ||
} | ||
try { | ||
@@ -16,0 +38,0 @@ var x = new (XMLHttpRequest || ActiveXObject)('MSXML2.XMLHTTP.3.0'); |
@@ -24,14 +24,36 @@ (function (global, factory) { | ||
function addQueryString(url, params) { | ||
if (params && (typeof params === 'undefined' ? 'undefined' : _typeof(params)) === 'object') { | ||
var queryString = '', | ||
e = encodeURIComponent; | ||
// Must encode data | ||
for (var paramName in params) { | ||
queryString += '&' + e(paramName) + '=' + e(params[paramName]); | ||
} | ||
if (!queryString) { | ||
return url; | ||
} | ||
url = url + (url.includes('?') ? '&' : '?') + queryString.slice(1); | ||
} | ||
return url; | ||
} | ||
// https://gist.github.com/Xeoncross/7663273 | ||
function ajax(url, options, callback, data, cache) { | ||
// Must encode data | ||
if (data && (typeof data === 'undefined' ? 'undefined' : _typeof(data)) === 'object') { | ||
var y = '', | ||
e = encodeURIComponent; | ||
for (var m in data) { | ||
y += '&' + e(m) + '=' + e(data[m]); | ||
if (!cache) { | ||
data['_t'] = new Date(); | ||
} | ||
data = y.slice(1) + (!cache ? '&_t=' + new Date() : ''); | ||
data = addQueryString(data, data); | ||
} | ||
if (options.queryStringParams) { | ||
url = addQueryString(url, options.queryStringParams); | ||
} | ||
try { | ||
@@ -38,0 +60,0 @@ var x = new (XMLHttpRequest || ActiveXObject)('MSXML2.XMLHTTP.3.0'); |
@@ -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 a.call(r.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,n,o,i){if(o&&"object"===("undefined"==typeof o?"undefined":s(o))){var a="",r=encodeURIComponent;for(var l in o)a+="&"+r(l)+"="+r(o[l]);o=a.slice(1)+(i?"":"&_t="+new Date)}try{var u=new(XMLHttpRequest||ActiveXObject)("MSXML2.XMLHTTP.3.0");u.open(o?"POST":"GET",t,1),e.crossDomain||u.setRequestHeader("X-Requested-With","XMLHttpRequest"),u.withCredentials=!!e.withCredentials,o&&u.setRequestHeader("Content-type","application/x-www-form-urlencoded");var c=e.customHeaders;if(c)for(var f in c)u.setRequestHeader(f,c[f]);u.onreadystatechange=function(){u.readyState>3&&n&&n(u.responseText,u)},u.send(o)}catch(t){console&&console.log(t)}}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(){return{loadPath:"/locales/{{lng}}/{{ns}}.json",addPath:"locales/add/{{lng}}/{{ns}}",allowMultiLoading:!1,parse:JSON.parse,crossDomain:!1,ajax:e}}var i=[],a=i.forEach,r=i.slice,s="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},l=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}}(),u=function(){function e(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};n(this,e),this.init(t,o),this.type="backend"}return l(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||{},o())}},{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"}return r?e(r,!1):void 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 u.type="backend",u}); | ||
!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+(t.includes("?")?"&":"?")+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,i)),n.queryStringParams&&(t=e(t,n.queryStringParams));try{var r=new(XMLHttpRequest||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");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}); |
@@ -24,14 +24,36 @@ (function (global, factory) { | ||
function addQueryString(url, params) { | ||
if (params && (typeof params === 'undefined' ? 'undefined' : _typeof(params)) === 'object') { | ||
var queryString = '', | ||
e = encodeURIComponent; | ||
// Must encode data | ||
for (var paramName in params) { | ||
queryString += '&' + e(paramName) + '=' + e(params[paramName]); | ||
} | ||
if (!queryString) { | ||
return url; | ||
} | ||
url = url + (url.includes('?') ? '&' : '?') + queryString.slice(1); | ||
} | ||
return url; | ||
} | ||
// https://gist.github.com/Xeoncross/7663273 | ||
function ajax(url, options, callback, data, cache) { | ||
// Must encode data | ||
if (data && (typeof data === 'undefined' ? 'undefined' : _typeof(data)) === 'object') { | ||
var y = '', | ||
e = encodeURIComponent; | ||
for (var m in data) { | ||
y += '&' + e(m) + '=' + e(data[m]); | ||
if (!cache) { | ||
data['_t'] = new Date(); | ||
} | ||
data = y.slice(1) + (!cache ? '&_t=' + new Date() : ''); | ||
data = addQueryString(data, data); | ||
} | ||
if (options.queryStringParams) { | ||
url = addQueryString(url, options.queryStringParams); | ||
} | ||
try { | ||
@@ -38,0 +60,0 @@ var x = new (XMLHttpRequest || ActiveXObject)('MSXML2.XMLHTTP.3.0'); |
@@ -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 a.call(r.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,n,o,i){if(o&&"object"===("undefined"==typeof o?"undefined":s(o))){var a="",r=encodeURIComponent;for(var l in o)a+="&"+r(l)+"="+r(o[l]);o=a.slice(1)+(i?"":"&_t="+new Date)}try{var u=new(XMLHttpRequest||ActiveXObject)("MSXML2.XMLHTTP.3.0");u.open(o?"POST":"GET",t,1),e.crossDomain||u.setRequestHeader("X-Requested-With","XMLHttpRequest"),u.withCredentials=!!e.withCredentials,o&&u.setRequestHeader("Content-type","application/x-www-form-urlencoded");var c=e.customHeaders;if(c)for(var f in c)u.setRequestHeader(f,c[f]);u.onreadystatechange=function(){u.readyState>3&&n&&n(u.responseText,u)},u.send(o)}catch(t){console&&console.log(t)}}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(){return{loadPath:"/locales/{{lng}}/{{ns}}.json",addPath:"locales/add/{{lng}}/{{ns}}",allowMultiLoading:!1,parse:JSON.parse,crossDomain:!1,ajax:e}}var i=[],a=i.forEach,r=i.slice,s="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},l=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}}(),u=function(){function e(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};n(this,e),this.init(t,o),this.type="backend"}return l(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||{},o())}},{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"}return r?e(r,!1):void 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 u.type="backend",u}); | ||
!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+(t.includes("?")?"&":"?")+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,i)),n.queryStringParams&&(t=e(t,n.queryStringParams));try{var r=new(XMLHttpRequest||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");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}); |
{ | ||
"name": "i18next-xhr-backend", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "backend layer for i18next using browsers xhr", | ||
@@ -63,3 +63,5 @@ "main": "./index.js", | ||
"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", | ||
@@ -70,2 +72,3 @@ "build:umd": "rollup -c rollup.config.js --format umd && rollup -c rollup.config.js --format umd --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", | ||
"preversion": "npm run test && npm run build && git push", | ||
@@ -72,0 +75,0 @@ "postversion": "git push && git push --tags" |
@@ -52,3 +52,3 @@ # Introduction | ||
// /locales/resources.json?lng=de+en&ns=ns1+ns2 | ||
allowMultiLoading: false, | ||
allowMultiLoading: false, // set loadPath: '/locales/resources.json?lng={{lng}}&ns={{ns}}' to adapt to multiLoading | ||
@@ -68,3 +68,6 @@ // parse data after it has been fetched | ||
// can be used to support XDomainRequest in IE 8 and 9 | ||
ajax: function (url, options, callback, data) {} | ||
ajax: function (url, options, callback, data) {}, | ||
// adds parameters to resource URL. 'example.com' -> 'example.com?v=1.3.5' | ||
queryStringParams: { v: '1.3.5' } | ||
} | ||
@@ -71,0 +74,0 @@ ``` |
41651
700
142