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 1.4.2 to 1.4.3

49

cjs/request.js

@@ -25,2 +25,4 @@ "use strict";

fetchApi = window.fetch;
} else {
fetchApi = fetch;
}

@@ -67,14 +69,4 @@ }

var requestWithFetch = function requestWithFetch(options, url, payload, callback) {
if (options.queryStringParams) {
url = addQueryString(url, options.queryStringParams);
}
var headers = (0, _utils.defaults)({}, typeof options.customHeaders === 'function' ? options.customHeaders() : options.customHeaders);
if (payload) headers['Content-Type'] = 'application/json';
fetchApi(url, (0, _utils.defaults)({
method: payload ? 'POST' : 'GET',
body: payload ? options.stringify(payload) : undefined,
headers: headers
}, typeof options.requestOptions === 'function' ? options.requestOptions(payload) : options.requestOptions)).then(function (response) {
var fetchIt = function fetchIt(url, fetchOptions, callback) {
fetchApi(url, fetchOptions).then(function (response) {
if (!response.ok) return callback(response.statusText || 'Error', {

@@ -92,2 +84,35 @@ status: response.status

var omitFetchMode = false;
var requestWithFetch = function requestWithFetch(options, url, payload, callback) {
if (options.queryStringParams) {
url = addQueryString(url, options.queryStringParams);
}
var headers = (0, _utils.defaults)({}, typeof options.customHeaders === 'function' ? options.customHeaders() : options.customHeaders);
if (payload) headers['Content-Type'] = 'application/json';
var fetchOptions = (0, _utils.defaults)({
method: payload ? 'POST' : 'GET',
body: payload ? options.stringify(payload) : undefined,
headers: headers
}, typeof options.requestOptions === 'function' ? options.requestOptions(payload) : options.requestOptions);
if (omitFetchMode) delete fetchOptions.mode;
try {
fetchIt(url, fetchOptions, callback);
} catch (e) {
if (!fetchOptions.mode || !e.message || e.message.indexOf('mode') < 0 || e.message.indexOf('not implemented') < 0) {
return callback(e);
}
try {
delete fetchOptions.mode;
fetchIt(url, fetchOptions, callback);
omitFetchMode = true;
} catch (err) {
callback(err);
}
}
};
var requestWithXmlHttpRequest = function requestWithXmlHttpRequest(options, url, payload, callback) {

@@ -94,0 +119,0 @@ if (payload && _typeof(payload) === 'object') {

@@ -12,2 +12,4 @@ 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); }

fetchApi = window.fetch;
} else {
fetchApi = fetch;
}

@@ -54,14 +56,4 @@ }

var requestWithFetch = function requestWithFetch(options, url, payload, callback) {
if (options.queryStringParams) {
url = addQueryString(url, options.queryStringParams);
}
var headers = defaults({}, typeof options.customHeaders === 'function' ? options.customHeaders() : options.customHeaders);
if (payload) headers['Content-Type'] = 'application/json';
fetchApi(url, defaults({
method: payload ? 'POST' : 'GET',
body: payload ? options.stringify(payload) : undefined,
headers: headers
}, typeof options.requestOptions === 'function' ? options.requestOptions(payload) : options.requestOptions)).then(function (response) {
var fetchIt = function fetchIt(url, fetchOptions, callback) {
fetchApi(url, fetchOptions).then(function (response) {
if (!response.ok) return callback(response.statusText || 'Error', {

@@ -79,2 +71,35 @@ status: response.status

var omitFetchMode = false;
var requestWithFetch = function requestWithFetch(options, url, payload, callback) {
if (options.queryStringParams) {
url = addQueryString(url, options.queryStringParams);
}
var headers = defaults({}, typeof options.customHeaders === 'function' ? options.customHeaders() : options.customHeaders);
if (payload) headers['Content-Type'] = 'application/json';
var fetchOptions = defaults({
method: payload ? 'POST' : 'GET',
body: payload ? options.stringify(payload) : undefined,
headers: headers
}, typeof options.requestOptions === 'function' ? options.requestOptions(payload) : options.requestOptions);
if (omitFetchMode) delete fetchOptions.mode;
try {
fetchIt(url, fetchOptions, callback);
} catch (e) {
if (!fetchOptions.mode || !e.message || e.message.indexOf('mode') < 0 || e.message.indexOf('not implemented') < 0) {
return callback(e);
}
try {
delete fetchOptions.mode;
fetchIt(url, fetchOptions, callback);
omitFetchMode = true;
} catch (err) {
callback(err);
}
}
};
var requestWithXmlHttpRequest = function requestWithXmlHttpRequest(options, url, payload, callback) {

@@ -81,0 +106,0 @@ if (payload && _typeof(payload) === 'object') {

@@ -264,2 +264,4 @@ (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){

fetchApi = window.fetch;
} else {
fetchApi = fetch;
}

@@ -306,14 +308,4 @@ }

var requestWithFetch = function requestWithFetch(options, url, payload, callback) {
if (options.queryStringParams) {
url = addQueryString(url, options.queryStringParams);
}
var headers = (0, _utils.defaults)({}, typeof options.customHeaders === 'function' ? options.customHeaders() : options.customHeaders);
if (payload) headers['Content-Type'] = 'application/json';
fetchApi(url, (0, _utils.defaults)({
method: payload ? 'POST' : 'GET',
body: payload ? options.stringify(payload) : undefined,
headers: headers
}, typeof options.requestOptions === 'function' ? options.requestOptions(payload) : options.requestOptions)).then(function (response) {
var fetchIt = function fetchIt(url, fetchOptions, callback) {
fetchApi(url, fetchOptions).then(function (response) {
if (!response.ok) return callback(response.statusText || 'Error', {

@@ -331,2 +323,35 @@ status: response.status

var omitFetchMode = false;
var requestWithFetch = function requestWithFetch(options, url, payload, callback) {
if (options.queryStringParams) {
url = addQueryString(url, options.queryStringParams);
}
var headers = (0, _utils.defaults)({}, typeof options.customHeaders === 'function' ? options.customHeaders() : options.customHeaders);
if (payload) headers['Content-Type'] = 'application/json';
var fetchOptions = (0, _utils.defaults)({
method: payload ? 'POST' : 'GET',
body: payload ? options.stringify(payload) : undefined,
headers: headers
}, typeof options.requestOptions === 'function' ? options.requestOptions(payload) : options.requestOptions);
if (omitFetchMode) delete fetchOptions.mode;
try {
fetchIt(url, fetchOptions, callback);
} catch (e) {
if (!fetchOptions.mode || !e.message || e.message.indexOf('mode') < 0 || e.message.indexOf('not implemented') < 0) {
return callback(e);
}
try {
delete fetchOptions.mode;
fetchIt(url, fetchOptions, callback);
omitFetchMode = true;
} catch (err) {
callback(err);
}
}
};
var requestWithXmlHttpRequest = function requestWithXmlHttpRequest(options, url, payload, callback) {

@@ -333,0 +358,0 @@ if (payload && _typeof(payload) === 'object') {

@@ -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,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,o.key,o)}}function r(){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 n=n||"",(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=f,(u=[{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||{},r()),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&&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)})})}))}}])&&i(e.prototype,u),a&&i(e,a),Object.defineProperty(e,"prototype",{writable:!1});var a,u=f;function f(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=f;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)}u.type="backend",n.default=u,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 p,y,h,v=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&&(void 0!==t&&t.fetch?p=t.fetch:"undefined"!=typeof window&&window.fetch&&(p=window.fetch)),(0,v.hasXMLHttpRequest)()&&(void 0!==t&&t.XMLHttpRequest?y=t.XMLHttpRequest:"undefined"!=typeof window&&window.XMLHttpRequest&&(y=window.XMLHttpRequest)),"function"==typeof ActiveXObject&&(void 0!==t&&t.ActiveXObject?h=t.ActiveXObject:"undefined"!=typeof window&&window.ActiveXObject&&(h=window.ActiveXObject)),"function"!=typeof(p=p||!e||y||h?p:e.default||e)&&(p=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};i.default=function(e,t,n,o){if("function"==typeof n&&(o=n,n=void 0),o=o||function(){},p)return a=t,u=n,r=o,(i=e).queryStringParams&&(a=g(a,i.queryStringParams)),s=(0,v.defaults)({},"function"==typeof i.customHeaders?i.customHeaders():i.customHeaders),u&&(s["Content-Type"]="application/json"),void p(a,(0,v.defaults)({method:u?"POST":"GET",body:u?i.stringify(u):void 0,headers:s},"function"==typeof i.requestOptions?i.requestOptions(u):i.requestOptions)).then(function(t){if(!t.ok)return r(t.statusText||"Error",{status:t.status});t.text().then(function(e){r(null,{status:t.status,data:e})}).catch(r)}).catch(r);var i,r;if((0,v.hasXMLHttpRequest)()||"function"==typeof ActiveXObject){var a=e,s=t,u=n,f=o;u&&"object"===w(u)&&(u=g("",u).slice(1)),a.queryStringParams&&(s=g(s,a.queryStringParams));try{var c=y?new y:new h("MSXML2.XMLHTTP.3.0"),l=(c.open(u?"POST":"GET",s,1),a.crossDomain||c.setRequestHeader("X-Requested-With","XMLHttpRequest"),c.withCredentials=!!a.withCredentials,u&&c.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),c.overrideMimeType&&c.overrideMimeType("application/json"),a.customHeaders);if(l="function"==typeof l?l():l)for(var d in l)c.setRequestHeader(d,l[d]);c.onreadystatechange=function(){3<c.readyState&&f(400<=c.status?c.statusText:null,{status:c.status,data:c.responseText})},c.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(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,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,o.key,o)}}function r(){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 n=n||"",(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=f,(u=[{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||{},r()),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&&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)})})}))}}])&&i(e.prototype,u),a&&i(e,a),Object.defineProperty(e,"prototype",{writable:!1});var a,u=f;function f(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=f;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)}u.type="backend",n.default=u,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 p,y,h,v=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&&(p=void 0!==t&&t.fetch?t.fetch:"undefined"!=typeof window&&window.fetch?window.fetch:fetch),(0,v.hasXMLHttpRequest)()&&(void 0!==t&&t.XMLHttpRequest?y=t.XMLHttpRequest:"undefined"!=typeof window&&window.XMLHttpRequest&&(y=window.XMLHttpRequest)),"function"==typeof ActiveXObject&&(void 0!==t&&t.ActiveXObject?h=t.ActiveXObject:"undefined"!=typeof window&&window.ActiveXObject&&(h=window.ActiveXObject)),"function"!=typeof(p=p||!e||y||h?p:e.default||e)&&(p=void 0);var m=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},g=function(e,t,n){p(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)},b=!1;i.default=function(e,t,n,o){if("function"==typeof n&&(o=n,n=void 0),o=o||function(){},p){var i=e,r=t,a=n,s=o,u=(i.queryStringParams&&(r=m(r,i.queryStringParams)),(0,v.defaults)({},"function"==typeof i.customHeaders?i.customHeaders():i.customHeaders)),u=(a&&(u["Content-Type"]="application/json"),(0,v.defaults)({method:a?"POST":"GET",body:a?i.stringify(a):void 0,headers:u},"function"==typeof i.requestOptions?i.requestOptions(a):i.requestOptions));b&&delete u.mode;try{g(r,u,s)}catch(e){if(!u.mode||!e.message||e.message.indexOf("mode")<0||e.message.indexOf("not implemented")<0)return s(e);try{delete u.mode,g(r,u,s),b=!0}catch(e){s(e)}}}else if((0,v.hasXMLHttpRequest)()||"function"==typeof ActiveXObject){var a=e,i=t,r=n,f=o;r&&"object"===w(r)&&(r=m("",r).slice(1)),a.queryStringParams&&(i=m(i,a.queryStringParams));try{var c=y?new y:new h("MSXML2.XMLHTTP.3.0"),d=(c.open(r?"POST":"GET",i,1),a.crossDomain||c.setRequestHeader("X-Requested-With","XMLHttpRequest"),c.withCredentials=!!a.withCredentials,r&&c.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),c.overrideMimeType&&c.overrideMimeType("application/json"),a.customHeaders);if(d="function"==typeof d?d():d)for(var l in d)c.setRequestHeader(l,d[l]);c.onreadystatechange=function(){3<c.readyState&&f(400<=c.status?c.statusText:null,{status:c.status,data:c.responseText})},c.send(r)}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)});

@@ -10,2 +10,4 @@ import { defaults, hasXMLHttpRequest } from './utils.js'

fetchApi = window.fetch
} else {
fetchApi = fetch
}

@@ -45,2 +47,13 @@ }

const fetchIt = (url, fetchOptions, callback) => {
fetchApi(url, fetchOptions).then((response) => {
if (!response.ok) return callback(response.statusText || 'Error', { status: response.status })
response.text().then((data) => {
callback(null, { status: response.status, data })
}).catch(callback)
}).catch(callback)
}
let omitFetchMode = false
// fetch api stuff

@@ -53,12 +66,22 @@ const requestWithFetch = (options, url, payload, callback) => {

if (payload) headers['Content-Type'] = 'application/json'
fetchApi(url, defaults({
const fetchOptions = defaults({
method: payload ? 'POST' : 'GET',
body: payload ? options.stringify(payload) : undefined,
headers
}, typeof options.requestOptions === 'function' ? options.requestOptions(payload) : options.requestOptions)).then((response) => {
if (!response.ok) return callback(response.statusText || 'Error', { status: response.status })
response.text().then((data) => {
callback(null, { status: response.status, data })
}).catch(callback)
}).catch(callback)
}, typeof options.requestOptions === 'function' ? options.requestOptions(payload) : options.requestOptions)
if (omitFetchMode) delete fetchOptions.mode
try {
fetchIt(url, fetchOptions, callback)
} catch (e) {
if (!fetchOptions.mode || !e.message || e.message.indexOf('mode') < 0 || e.message.indexOf('not implemented') < 0) {
return callback(e)
}
try {
delete fetchOptions.mode
fetchIt(url, fetchOptions, callback)
omitFetchMode = true
} catch (err) {
callback(err)
}
}
}

@@ -65,0 +88,0 @@

{
"name": "i18next-http-backend",
"version": "1.4.2",
"version": "1.4.3",
"private": false,

@@ -5,0 +5,0 @@ "type": "module",

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