Socket
Socket
Sign inDemoInstall

i18next-http-backend

Package Overview
Dependencies
Maintainers
2
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18next-http-backend - npm Package Compare versions

Comparing version 2.1.1 to 2.2.0

CHANGELOG.md

8

cjs/index.js

@@ -29,2 +29,5 @@ "use strict";

},
parseLoadPayload: function parseLoadPayload(languages, namespaces) {
return undefined;
},
request: _request.default,

@@ -102,3 +105,6 @@ reloadInterval: typeof window !== 'undefined' ? false : 60 * 60 * 1000,

var _this3 = this;
this.options.request(this.options, url, undefined, function (err, res) {
var lng = typeof languages === 'string' ? [languages] : languages;
var ns = typeof namespaces === 'string' ? [namespaces] : namespaces;
var payload = this.options.parseLoadPayload(lng, ns);
this.options.request(this.options, url, payload, function (err, res) {
if (res && (res.status >= 500 && res.status < 600 || !res.status)) return callback('failed loading ' + url + '; status code: ' + res.status, true);

@@ -105,0 +111,0 @@ if (res && res.status >= 400 && res.status < 500) return callback('failed loading ' + url + '; status code: ' + res.status, false);

@@ -22,2 +22,5 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

},
parseLoadPayload: function parseLoadPayload(languages, namespaces) {
return undefined;
},
request: request,

@@ -95,3 +98,6 @@ reloadInterval: typeof window !== 'undefined' ? false : 60 * 60 * 1000,

var _this3 = this;
this.options.request(this.options, url, undefined, function (err, res) {
var lng = typeof languages === 'string' ? [languages] : languages;
var ns = typeof namespaces === 'string' ? [namespaces] : namespaces;
var payload = this.options.parseLoadPayload(lng, ns);
this.options.request(this.options, url, payload, function (err, res) {
if (res && (res.status >= 500 && res.status < 600 || !res.status)) return callback('failed loading ' + url + '; status code: ' + res.status, true);

@@ -98,0 +104,0 @@ if (res && res.status >= 400 && res.status < 500) return callback('failed loading ' + url + '; status code: ' + res.status, false);

@@ -51,2 +51,5 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.i18nextHttpBackend = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){

},
parseLoadPayload: function parseLoadPayload(languages, namespaces) {
return undefined;
},
request: _request.default,

@@ -124,3 +127,6 @@ reloadInterval: typeof window !== 'undefined' ? false : 60 * 60 * 1000,

var _this3 = this;
this.options.request(this.options, url, undefined, function (err, res) {
var lng = typeof languages === 'string' ? [languages] : languages;
var ns = typeof namespaces === 'string' ? [namespaces] : namespaces;
var payload = this.options.parseLoadPayload(lng, ns);
this.options.request(this.options, url, payload, function (err, res) {
if (res && (res.status >= 500 && res.status < 600 || !res.status)) return callback('failed loading ' + url + '; status code: ' + res.status, true);

@@ -127,0 +133,0 @@ if (res && res.status >= 400 && res.status < 500) return callback('failed loading ' + url + '; status code: ' + res.status, false);

2

i18nextHttpBackend.min.js

@@ -1,1 +0,1 @@

!function(e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).i18nextHttpBackend=e()}(function(){return function o(i,r,a){function s(t,e){if(!r[t]){if(!i[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(u)return u(t,!0);throw(e=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",e}n=r[t]={exports:{}},i[t][0].call(n.exports,function(e){return s(i[t][1][e]||e)},n,n.exports,o,i,r,a)}return r[t].exports}for(var u="function"==typeof require&&require,e=0;e<a.length;e++)s(a[e]);return s}({1:[function(n,o,i){!function(t){!function(){var e;"function"==typeof fetch&&(e=void 0!==t&&t.fetch?t.fetch:"undefined"!=typeof window&&window.fetch?window.fetch:fetch),void 0===n||"undefined"!=typeof window&&void 0!==window.document||((e=e||n("cross-fetch")).default&&(e=e.default),i.default=e,o.exports=i.default)}.call(this)}.call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"cross-fetch":5}],2:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var s=e("./utils.js"),o=(e=e("./request.js"))&&e.__esModule?e:{default:e};function i(e){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function r(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,a(o.key),o)}}function a(e){e=function(e,t){if("object"!==i(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0===n)return("string"===t?String:Number)(e);n=n.call(e,t||"default");if("object"!==i(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}(e,"string");return"symbol"===i(e)?e:String(e)}function u(){return{loadPath:"/locales/{{lng}}/{{ns}}.json",addPath:"/locales/add/{{lng}}/{{ns}}",allowMultiLoading:!1,parse:function(e){return JSON.parse(e)},stringify:JSON.stringify,parsePayload:function(e,t,n){return o={},n=n||"",(t=a(t=t))in o?Object.defineProperty(o,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):o[t]=n,o;var o},request:o.default,reloadInterval:"undefined"==typeof window&&36e5,customHeaders:{},queryStringParams:{},crossDomain:!1,withCredentials:!1,overrideMimeType:!1,requestOptions:{mode:"cors",credentials:"same-origin",cache:"default"}}}e=l,(c=[{key:"init",value:function(e){var t=this,n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},o=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.services=e,this.options=(0,s.defaults)(n,this.options||{},u()),this.allOptions=o,this.services&&this.options.reloadInterval&&setInterval(function(){return t.reload()},this.options.reloadInterval)}},{key:"readMulti",value:function(e,t,n){this._readAny(e,e,t,t,n)}},{key:"read",value:function(e,t,n){this._readAny([e],e,[t],t,n)}},{key:"_readAny",value:function(t,n,o,i,r){var a=this,e=this.options.loadPath;"function"==typeof this.options.loadPath&&(e=this.options.loadPath(t,o)),(e=(0,s.makePromise)(e)).then(function(e){if(!e)return r(null,{});e=a.services.interpolator.interpolate(e,{lng:t.join("+"),ns:o.join("+")});a.loadUrl(e,r,n,i)})}},{key:"loadUrl",value:function(i,r,a,s){var u=this;this.options.request(this.options,i,void 0,function(e,t){if(t&&(500<=t.status&&t.status<600||!t.status))return r("failed loading "+i+"; status code: "+t.status,!0);if(t&&400<=t.status&&t.status<500)return r("failed loading "+i+"; status code: "+t.status,!1);if(!t&&e&&e.message&&-1<e.message.indexOf("Failed to fetch"))return r("failed loading "+i+": "+e.message,!0);if(e)return r(e,!1);var n,o;try{n="string"==typeof t.data?u.options.parse(t.data,a,s):t.data}catch(e){o="failed parsing "+i+" to json"}if(o)return r(o,!1);r(null,n)})}},{key:"create",value:function(n,o,e,t,i){var r,a,s,u,f=this;this.options.addPath&&("string"==typeof n&&(n=[n]),r=this.options.parsePayload(o,e,t),a=0,s=[],u=[],n.forEach(function(e){var t=f.options.addPath,t=("function"==typeof f.options.addPath&&(t=f.options.addPath(e,o)),f.services.interpolator.interpolate(t,{lng:e,ns:o}));f.options.request(f.options,t,r,function(e,t){a+=1,s.push(e),u.push(t),a===n.length&&"function"==typeof i&&i(s,u)})}))}},{key:"reload",value:function(){var t,e,n=this,o=this.services,i=o.backendConnector,r=o.languageUtils,a=o.logger,o=i.language;o&&"cimode"===o.toLowerCase()||(t=[],(e=function(e){r.toResolveHierarchy(e).forEach(function(e){t.indexOf(e)<0&&t.push(e)})})(o),this.allOptions.preload&&this.allOptions.preload.forEach(e),t.forEach(function(o){n.allOptions.ns.forEach(function(n){i.read(o,n,"read",null,null,function(e,t){e&&a.warn("loading namespace ".concat(n," for language ").concat(o," failed"),e),!e&&t&&a.log("loaded namespace ".concat(n," for language ").concat(o),t),i.loaded("".concat(o,"|").concat(n),e,t)})})}))}}])&&r(e.prototype,c),f&&r(e,f),Object.defineProperty(e,"prototype",{writable:!1});var f,c=l;function l(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},o=this,i=l;if(!(o instanceof i))throw new TypeError("Cannot call a class as a function");this.services=e,this.options=t,this.allOptions=n,this.type="backend",this.init(e,t,n)}c.type="backend",n.default=c,t.exports=n.default},{"./request.js":3,"./utils.js":4}],3:[function(n,o,i){!function(t){!function(){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var h,v,m,b=n("./utils.js"),e=function(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!==w(e)&&"function"!=typeof e)return{default:e};t=a(t);if(t&&t.has(e))return t.get(e);var n,o={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(n in e){var r;"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&((r=i?Object.getOwnPropertyDescriptor(e,n):null)&&(r.get||r.set)?Object.defineProperty(o,n,r):o[n]=e[n])}o.default=e,t&&t.set(e,o);return o}(n("./getFetch.js"));function a(e){var t,n;return"function"!=typeof WeakMap?null:(t=new WeakMap,n=new WeakMap,(a=function(e){return e?n:t})(e))}function w(e){return(w="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}"function"==typeof fetch&&(h=void 0!==t&&t.fetch?t.fetch:"undefined"!=typeof window&&window.fetch?window.fetch:fetch),(0,b.hasXMLHttpRequest)()&&(void 0!==t&&t.XMLHttpRequest?v=t.XMLHttpRequest:"undefined"!=typeof window&&window.XMLHttpRequest&&(v=window.XMLHttpRequest)),"function"==typeof ActiveXObject&&(void 0!==t&&t.ActiveXObject?m=t.ActiveXObject:"undefined"!=typeof window&&window.ActiveXObject&&(m=window.ActiveXObject)),"function"!=typeof(h=h||!e||v||m?h:e.default||e)&&(h=void 0);var g=function(e,t){if(t&&"object"===w(t)){var n,o="";for(n in t)o+="&"+encodeURIComponent(n)+"="+encodeURIComponent(t[n]);if(!o)return e;e=e+(-1!==e.indexOf("?")?"&":"?")+o.slice(1)}return e},O=function(e,t,n){h(e,t).then(function(t){if(!t.ok)return n(t.statusText||"Error",{status:t.status});t.text().then(function(e){n(null,{status:t.status,data:e})}).catch(n)}).catch(n)},j=!1;i.default=function(e,t,n,o){if("function"==typeof n&&(o=n,n=void 0),o=o||function(){},h&&0!==t.indexOf("file:")){var i=e,r=t,a=n,s=o,u=(i.queryStringParams&&(r=g(r,i.queryStringParams)),(0,b.defaults)({},"function"==typeof i.customHeaders?i.customHeaders():i.customHeaders)),f=(a&&(u["Content-Type"]="application/json"),"function"==typeof i.requestOptions?i.requestOptions(a):i.requestOptions),c=(0,b.defaults)({method:a?"POST":"GET",body:a?i.stringify(a):void 0,headers:u},j?{}:f);try{O(r,c,s)}catch(e){if(!f||0===Object.keys(f).length||!e.message||e.message.indexOf("not implemented")<0)return s(e);try{Object.keys(f).forEach(function(e){delete c[e]}),O(r,c,s),j=!0}catch(e){s(e)}}}else if((0,b.hasXMLHttpRequest)()||"function"==typeof ActiveXObject){var i=e,a=t,u=n,l=o;u&&"object"===w(u)&&(u=g("",u).slice(1)),i.queryStringParams&&(a=g(a,i.queryStringParams));try{var d=v?new v:new m("MSXML2.XMLHTTP.3.0"),p=(d.open(u?"POST":"GET",a,1),i.crossDomain||d.setRequestHeader("X-Requested-With","XMLHttpRequest"),d.withCredentials=!!i.withCredentials,u&&d.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),d.overrideMimeType&&d.overrideMimeType("application/json"),i.customHeaders);if(p="function"==typeof p?p():p)for(var y in p)d.setRequestHeader(y,p[y]);d.onreadystatechange=function(){3<d.readyState&&l(400<=d.status?d.statusText:null,{status:d.status,data:d.responseText})},d.send(u)}catch(e){console&&console.log(e)}}else o(new Error("No fetch and no xhr implementation found!"))},o.exports=i.default}.call(this)}.call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./getFetch.js":1,"./utils.js":4}],4:[function(e,t,n){"use strict";function o(e){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}Object.defineProperty(n,"__esModule",{value:!0}),n.defaults=function(n){return i.call(r.call(arguments,1),function(e){if(e)for(var t in e)void 0===n[t]&&(n[t]=e[t])}),n},n.hasXMLHttpRequest=function(){return"function"==typeof XMLHttpRequest||"object"===("undefined"==typeof XMLHttpRequest?"undefined":o(XMLHttpRequest))},n.makePromise=function(e){if(function(e){return e&&"function"==typeof e.then}(e))return e;return Promise.resolve(e)};var n=[],i=n.forEach,r=n.slice},{}],5:[function(e,t,n){},{}]},{},[2])(2)});
!function(t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).i18nextHttpBackend=t()}(function(){return function o(i,r,a){function s(e,t){if(!r[e]){if(!i[e]){var n="function"==typeof require&&require;if(!t&&n)return n(e,!0);if(u)return u(e,!0);throw(t=new Error("Cannot find module '"+e+"'")).code="MODULE_NOT_FOUND",t}n=r[e]={exports:{}},i[e][0].call(n.exports,function(t){return s(i[e][1][t]||t)},n,n.exports,o,i,r,a)}return r[e].exports}for(var u="function"==typeof require&&require,t=0;t<a.length;t++)s(a[t]);return s}({1:[function(n,o,i){!function(e){!function(){var t;"function"==typeof fetch&&(t=void 0!==e&&e.fetch?e.fetch:"undefined"!=typeof window&&window.fetch?window.fetch:fetch),void 0===n||"undefined"!=typeof window&&void 0!==window.document||((t=t||n("cross-fetch")).default&&(t=t.default),i.default=t,o.exports=i.default)}.call(this)}.call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"cross-fetch":5}],2:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var s=t("./utils.js"),o=(t=t("./request.js"))&&t.__esModule?t:{default:t};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,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,a(o.key),o)}}function a(t){t=function(t,e){if("object"!==i(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0===n)return("string"===e?String:Number)(t);n=n.call(t,e||"default");if("object"!==i(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}(t,"string");return"symbol"===i(t)?t:String(t)}function u(){return{loadPath:"/locales/{{lng}}/{{ns}}.json",addPath:"/locales/add/{{lng}}/{{ns}}",allowMultiLoading:!1,parse:function(t){return JSON.parse(t)},stringify:JSON.stringify,parsePayload:function(t,e,n){return o={},n=n||"",(e=a(e=e))in o?Object.defineProperty(o,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):o[e]=n,o;var o},parseLoadPayload:function(t,e){},request:o.default,reloadInterval:"undefined"==typeof window&&36e5,customHeaders:{},queryStringParams:{},crossDomain:!1,withCredentials:!1,overrideMimeType:!1,requestOptions:{mode:"cors",credentials:"same-origin",cache:"default"}}}t=l,(c=[{key:"init",value:function(t){var e=this,n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},o=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.services=t,this.options=(0,s.defaults)(n,this.options||{},u()),this.allOptions=o,this.services&&this.options.reloadInterval&&setInterval(function(){return e.reload()},this.options.reloadInterval)}},{key:"readMulti",value:function(t,e,n){this._readAny(t,t,e,e,n)}},{key:"read",value:function(t,e,n){this._readAny([t],t,[e],e,n)}},{key:"_readAny",value:function(e,n,o,i,r){var a=this,t=this.options.loadPath;"function"==typeof this.options.loadPath&&(t=this.options.loadPath(e,o)),(t=(0,s.makePromise)(t)).then(function(t){if(!t)return r(null,{});t=a.services.interpolator.interpolate(t,{lng:e.join("+"),ns:o.join("+")});a.loadUrl(t,r,n,i)})}},{key:"loadUrl",value:function(i,r,a,s){var u=this,t=this.options.parseLoadPayload("string"==typeof a?[a]:a,"string"==typeof s?[s]:s);this.options.request(this.options,i,t,function(t,e){if(e&&(500<=e.status&&e.status<600||!e.status))return r("failed loading "+i+"; status code: "+e.status,!0);if(e&&400<=e.status&&e.status<500)return r("failed loading "+i+"; status code: "+e.status,!1);if(!e&&t&&t.message&&-1<t.message.indexOf("Failed to fetch"))return r("failed loading "+i+": "+t.message,!0);if(t)return r(t,!1);var n,o;try{n="string"==typeof e.data?u.options.parse(e.data,a,s):e.data}catch(t){o="failed parsing "+i+" to json"}if(o)return r(o,!1);r(null,n)})}},{key:"create",value:function(n,o,t,e,i){var r,a,s,u,f=this;this.options.addPath&&("string"==typeof n&&(n=[n]),r=this.options.parsePayload(o,t,e),a=0,s=[],u=[],n.forEach(function(t){var e=f.options.addPath,e=("function"==typeof f.options.addPath&&(e=f.options.addPath(t,o)),f.services.interpolator.interpolate(e,{lng:t,ns:o}));f.options.request(f.options,e,r,function(t,e){a+=1,s.push(t),u.push(e),a===n.length&&"function"==typeof i&&i(s,u)})}))}},{key:"reload",value:function(){var e,t,n=this,o=this.services,i=o.backendConnector,r=o.languageUtils,a=o.logger,o=i.language;o&&"cimode"===o.toLowerCase()||(e=[],(t=function(t){r.toResolveHierarchy(t).forEach(function(t){e.indexOf(t)<0&&e.push(t)})})(o),this.allOptions.preload&&this.allOptions.preload.forEach(t),e.forEach(function(o){n.allOptions.ns.forEach(function(n){i.read(o,n,"read",null,null,function(t,e){t&&a.warn("loading namespace ".concat(n," for language ").concat(o," failed"),t),!t&&e&&a.log("loaded namespace ".concat(n," for language ").concat(o),e),i.loaded("".concat(o,"|").concat(n),t,e)})})}))}}])&&r(t.prototype,c),f&&r(t,f),Object.defineProperty(t,"prototype",{writable:!1});var f,c=l;function l(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},o=this,i=l;if(!(o instanceof i))throw new TypeError("Cannot call a class as a function");this.services=t,this.options=e,this.allOptions=n,this.type="backend",this.init(t,e,n)}c.type="backend",n.default=c,e.exports=n.default},{"./request.js":3,"./utils.js":4}],3:[function(n,o,i){!function(e){!function(){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var h,v,m,b=n("./utils.js"),t=function(t,e){if(!e&&t&&t.__esModule)return t;if(null===t||"object"!==w(t)&&"function"!=typeof t)return{default:t};e=a(e);if(e&&e.has(t))return e.get(t);var n,o={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(n in t){var r;"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&((r=i?Object.getOwnPropertyDescriptor(t,n):null)&&(r.get||r.set)?Object.defineProperty(o,n,r):o[n]=t[n])}o.default=t,e&&e.set(t,o);return o}(n("./getFetch.js"));function a(t){var e,n;return"function"!=typeof WeakMap?null:(e=new WeakMap,n=new WeakMap,(a=function(t){return t?n:e})(t))}function w(t){return(w="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"==typeof fetch&&(h=void 0!==e&&e.fetch?e.fetch:"undefined"!=typeof window&&window.fetch?window.fetch:fetch),(0,b.hasXMLHttpRequest)()&&(void 0!==e&&e.XMLHttpRequest?v=e.XMLHttpRequest:"undefined"!=typeof window&&window.XMLHttpRequest&&(v=window.XMLHttpRequest)),"function"==typeof ActiveXObject&&(void 0!==e&&e.ActiveXObject?m=e.ActiveXObject:"undefined"!=typeof window&&window.ActiveXObject&&(m=window.ActiveXObject)),"function"!=typeof(h=h||!t||v||m?h:t.default||t)&&(h=void 0);var g=function(t,e){if(e&&"object"===w(e)){var n,o="";for(n in e)o+="&"+encodeURIComponent(n)+"="+encodeURIComponent(e[n]);if(!o)return t;t=t+(-1!==t.indexOf("?")?"&":"?")+o.slice(1)}return t},O=function(t,e,n){h(t,e).then(function(e){if(!e.ok)return n(e.statusText||"Error",{status:e.status});e.text().then(function(t){n(null,{status:e.status,data:t})}).catch(n)}).catch(n)},j=!1;i.default=function(t,e,n,o){if("function"==typeof n&&(o=n,n=void 0),o=o||function(){},h&&0!==e.indexOf("file:")){var i=t,r=e,a=n,s=o,u=(i.queryStringParams&&(r=g(r,i.queryStringParams)),(0,b.defaults)({},"function"==typeof i.customHeaders?i.customHeaders():i.customHeaders)),f=(a&&(u["Content-Type"]="application/json"),"function"==typeof i.requestOptions?i.requestOptions(a):i.requestOptions),c=(0,b.defaults)({method:a?"POST":"GET",body:a?i.stringify(a):void 0,headers:u},j?{}:f);try{O(r,c,s)}catch(t){if(!f||0===Object.keys(f).length||!t.message||t.message.indexOf("not implemented")<0)return s(t);try{Object.keys(f).forEach(function(t){delete c[t]}),O(r,c,s),j=!0}catch(t){s(t)}}}else if((0,b.hasXMLHttpRequest)()||"function"==typeof ActiveXObject){var i=t,a=e,u=n,l=o;u&&"object"===w(u)&&(u=g("",u).slice(1)),i.queryStringParams&&(a=g(a,i.queryStringParams));try{var d=v?new v:new m("MSXML2.XMLHTTP.3.0"),p=(d.open(u?"POST":"GET",a,1),i.crossDomain||d.setRequestHeader("X-Requested-With","XMLHttpRequest"),d.withCredentials=!!i.withCredentials,u&&d.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),d.overrideMimeType&&d.overrideMimeType("application/json"),i.customHeaders);if(p="function"==typeof p?p():p)for(var y in p)d.setRequestHeader(y,p[y]);d.onreadystatechange=function(){3<d.readyState&&l(400<=d.status?d.statusText:null,{status:d.status,data:d.responseText})},d.send(u)}catch(t){console&&console.log(t)}}else o(new Error("No fetch and no xhr implementation found!"))},o.exports=i.default}.call(this)}.call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./getFetch.js":1,"./utils.js":4}],4:[function(t,e,n){"use strict";function o(t){return(o="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)}Object.defineProperty(n,"__esModule",{value:!0}),n.defaults=function(n){return i.call(r.call(arguments,1),function(t){if(t)for(var e in t)void 0===n[e]&&(n[e]=t[e])}),n},n.hasXMLHttpRequest=function(){return"function"==typeof XMLHttpRequest||"object"===("undefined"==typeof XMLHttpRequest?"undefined":o(XMLHttpRequest))},n.makePromise=function(t){if(function(t){return t&&"function"==typeof t.then}(t))return t;return Promise.resolve(t)};var n=[],i=n.forEach,r=n.slice},{}],5:[function(t,e,n){},{}]},{},[2])(2)});

@@ -1,2 +0,2 @@

import { BackendModule, MultiReadCallback, ReadCallback } from "i18next";
import { BackendModule, MultiReadCallback, ReadCallback, ResourceKey } from "i18next";

@@ -50,2 +50,10 @@ type LoadPathOption =

/**
* parse data before it has been sent by loadPath
* if value returned it will send a POST request
*/
parseLoadPayload?(
languages: string[],
namespaces: string[]
): { [key: string]: any } | undefined;
/**
* allow cross domain requests

@@ -95,3 +103,3 @@ */

status: number;
data: string;
data: ResourceKey;
}

@@ -98,0 +106,0 @@

@@ -12,2 +12,3 @@ import { defaults, makePromise } from './utils.js'

parsePayload: (namespace, key, fallbackValue) => ({ [key]: fallbackValue || '' }),
parseLoadPayload: (languages, namespaces) => undefined,
request,

@@ -70,3 +71,7 @@ reloadInterval: typeof window !== 'undefined' ? false : 60 * 60 * 1000,

loadUrl (url, callback, languages, namespaces) {
this.options.request(this.options, url, undefined, (err, res) => {
const lng = (typeof languages === 'string') ? [languages] : languages
const ns = (typeof namespaces === 'string') ? [namespaces] : namespaces
// parseLoadPayload — default undefined
const payload = this.options.parseLoadPayload(lng, ns)
this.options.request(this.options, url, payload, (err, res) => {
if (res && ((res.status >= 500 && res.status < 600) || !res.status)) return callback('failed loading ' + url + '; status code: ' + res.status, true /* retry */)

@@ -73,0 +78,0 @@ if (res && res.status >= 400 && res.status < 500) return callback('failed loading ' + url + '; status code: ' + res.status, false /* no retry */)

{
"name": "i18next-http-backend",
"version": "2.1.1",
"version": "2.2.0",
"private": false,

@@ -29,4 +29,4 @@ "type": "module",

"devDependencies": {
"@babel/cli": "7.19.3",
"@babel/core": "7.20.5",
"@babel/cli": "7.21.0",
"@babel/core": "7.21.0",
"@babel/preset-env": "7.20.2",

@@ -36,6 +36,6 @@ "babel-plugin-add-module-exports": "1.0.4",

"dtslint": "4.2.1",
"eslint": "8.30.0",
"eslint": "8.36.0",
"eslint-config-standard": "17.0.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-n": "15.6.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-n": "15.6.1",
"eslint-plugin-promise": "6.1.1",

@@ -45,9 +45,9 @@ "eslint-plugin-require-path-exists": "1.1.9",

"expect.js": "0.3.1",
"i18next": "22.4.6",
"json-server": "0.17.1",
"json5": "2.2.2",
"i18next": "22.4.11",
"json-server": "0.17.2",
"json5": "2.2.3",
"mocha": "10.2.0",
"tslint": "5.20.1",
"tsd": "0.25.0",
"typescript": "4.9.4",
"tsd": "0.27.0",
"typescript": "4.9.5",
"uglify-js": "3.17.4",

@@ -54,0 +54,0 @@ "xmlhttprequest": "1.8.0"

@@ -123,5 +123,9 @@ # Introduction

//parse data before it has been sent by addPath
parsePayload: function(namespace, key, fallbackValue) { return { key } },
// parse data before it has been sent by addPath
parsePayload: function(namespace, key, fallbackValue) { return { key: fallbackValue || "" } },
// parse data before it has been sent by loadPath
// if value returned it will send a POST request
parseLoadPayload: function(languages, namespaces) { return undefined },
// allow cross domain requests

@@ -128,0 +132,0 @@ crossDomain: false,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc