Skip to content

Commit

Permalink
error if no fetch and no xhr implementation found #96
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Sep 19, 2022
1 parent 84c188d commit 4032a97
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
},
"rules": {
"array-bracket-spacing": 0,
"node/no-callback-literal": 0
"n/no-callback-literal": 0
}
}
4 changes: 4 additions & 0 deletions i18nextHttpBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ if (typeof fetch === 'function') {
fetchApi = global.fetch
} else if (typeof window !== 'undefined' && window.fetch) {
fetchApi = window.fetch
} else {
fetchApi = fetch
}
}

Expand Down Expand Up @@ -395,6 +397,8 @@ var request = function request(options, url, payload, callback) {
if ((0, _utils.hasXMLHttpRequest)() || typeof ActiveXObject === 'function') {
return requestWithXmlHttpRequest(options, url, payload, callback);
}

callback(new Error('No fetch and no xhr implementation found!'));
};

var _default = request;
Expand Down
2 changes: 1 addition & 1 deletion i18nextHttpBackend.min.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion lib/getFetch.cjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* eslint-disable no-var */
/* eslint-disable no-var, no-undef */
var fetchApi
if (typeof fetch === 'function') {
if (typeof global !== 'undefined' && global.fetch) {
fetchApi = global.fetch
} else if (typeof window !== 'undefined' && window.fetch) {
fetchApi = window.fetch
} else {
fetchApi = fetch
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Backend {
if (typeof this.options.addPath === 'function') {
addPath = this.options.addPath(lng, namespace)
}
const url = this.services.interpolator.interpolate(addPath, { lng: lng, ns: namespace })
const url = this.services.interpolator.interpolate(addPath, { lng, ns: namespace })

this.options.request(this.options, url, payload, (data, res) => {
// TODO: if res.status === 4xx do log
Expand Down
2 changes: 2 additions & 0 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ const request = (options, url, payload, callback) => {
// use xml http request
return requestWithXmlHttpRequest(options, url, payload, callback)
}

callback(new Error('No fetch and no xhr implementation found!'))
}

export default request
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@
},
"types": "./index.d.ts",
"devDependencies": {
"@babel/cli": "7.16.8",
"@babel/core": "7.16.10",
"@babel/preset-env": "7.16.11",
"@babel/cli": "7.18.10",
"@babel/core": "7.19.1",
"@babel/preset-env": "7.19.1",
"babel-plugin-add-module-exports": "1.0.4",
"browserify": "17.0.0",
"eslint": "7.32.0",
"eslint-config-standard": "16.0.3",
"eslint-plugin-import": "2.25.4",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "5.2.0",
"eslint": "8.23.1",
"eslint-config-standard": "17.0.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-n": "15.2.5",
"eslint-plugin-promise": "6.0.1",
"eslint-plugin-require-path-exists": "1.1.9",
"eslint-plugin-standard": "5.0.0",
"expect.js": "0.3.1",
"i18next": "21.6.6",
"i18next": "21.9.2",
"json-server": "0.17.0",
"json5": "2.2.0",
"mocha": "9.1.4",
"uglify-js": "3.14.5",
"json5": "2.2.1",
"mocha": "10.0.0",
"uglify-js": "3.17.0",
"xmlhttprequest": "1.8.0"
},
"description": "i18next-http-backend is a backend layer for i18next using in Node.js, in the browser and for Deno.",
Expand All @@ -60,8 +60,8 @@
"license": "MIT",
"scripts": {
"lint": "eslint .",
"compile:esm": "rm -rf esm && mkdir esm && BABEL_ENV=esm babel lib -d esm && cp lib/getFetch.cjs esm/getFetch.cjs && rm -f esm/getFetch.js && node -e \"fs.writeFileSync('esm/getFetch.cjs', fs.readFileSync('esm/getFetch.cjs').toString().replace('/* eslint-disable no-var */\\n', ''))\"",
"compile:cjs": "rm -rf cjs && mkdir cjs && BABEL_ENV=cjs babel lib -d cjs && echo '{\"type\":\"commonjs\"}' > cjs/package.json && cp lib/getFetch.cjs cjs/getFetch.js && node -e \"fs.writeFileSync('cjs/getFetch.js', fs.readFileSync('cjs/getFetch.js').toString().replace('/* eslint-disable no-var */\\n', ''))\" && node -e \"fs.writeFileSync('cjs/request.js', fs.readFileSync('cjs/request.js').toString().replace('getFetch.cjs', 'getFetch.js'))\"",
"compile:esm": "rm -rf esm && mkdir esm && BABEL_ENV=esm babel lib -d esm && cp lib/getFetch.cjs esm/getFetch.cjs && rm -f esm/getFetch.js && node -e \"fs.writeFileSync('esm/getFetch.cjs', fs.readFileSync('esm/getFetch.cjs').toString().replace('/* eslint-disable no-var, no-undef */\\n', ''))\"",
"compile:cjs": "rm -rf cjs && mkdir cjs && BABEL_ENV=cjs babel lib -d cjs && echo '{\"type\":\"commonjs\"}' > cjs/package.json && cp lib/getFetch.cjs cjs/getFetch.js && node -e \"fs.writeFileSync('cjs/getFetch.js', fs.readFileSync('cjs/getFetch.js').toString().replace('/* eslint-disable no-var, no-undef */\\n', ''))\" && node -e \"fs.writeFileSync('cjs/request.js', fs.readFileSync('cjs/request.js').toString().replace('getFetch.cjs', 'getFetch.js'))\"",
"compile": "npm run compile:esm && npm run compile:cjs",
"browser": "browserify --ignore cross-fetch --standalone i18nextHttpBackend cjs/index.js -o i18nextHttpBackend.js && uglifyjs i18nextHttpBackend.js --compress --mangle -o i18nextHttpBackend.min.js",
"build": "npm run compile && npm run browser",
Expand Down

0 comments on commit 4032a97

Please sign in to comment.