Skip to content

Commit 4032a97

Browse files
committed
error if no fetch and no xhr implementation found #96
1 parent 84c188d commit 4032a97

File tree

7 files changed

+26
-18
lines changed

7 files changed

+26
-18
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
},
1717
"rules": {
1818
"array-bracket-spacing": 0,
19-
"node/no-callback-literal": 0
19+
"n/no-callback-literal": 0
2020
}
2121
}

i18nextHttpBackend.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ if (typeof fetch === 'function') {
66
fetchApi = global.fetch
77
} else if (typeof window !== 'undefined' && window.fetch) {
88
fetchApi = window.fetch
9+
} else {
10+
fetchApi = fetch
911
}
1012
}
1113

@@ -395,6 +397,8 @@ var request = function request(options, url, payload, callback) {
395397
if ((0, _utils.hasXMLHttpRequest)() || typeof ActiveXObject === 'function') {
396398
return requestWithXmlHttpRequest(options, url, payload, callback);
397399
}
400+
401+
callback(new Error('No fetch and no xhr implementation found!'));
398402
};
399403

400404
var _default = request;

i18nextHttpBackend.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/getFetch.cjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
/* eslint-disable no-var */
1+
/* eslint-disable no-var, no-undef */
22
var fetchApi
33
if (typeof fetch === 'function') {
44
if (typeof global !== 'undefined' && global.fetch) {
55
fetchApi = global.fetch
66
} else if (typeof window !== 'undefined' && window.fetch) {
77
fetchApi = window.fetch
8+
} else {
9+
fetchApi = fetch
810
}
911
}
1012

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class Backend {
100100
if (typeof this.options.addPath === 'function') {
101101
addPath = this.options.addPath(lng, namespace)
102102
}
103-
const url = this.services.interpolator.interpolate(addPath, { lng: lng, ns: namespace })
103+
const url = this.services.interpolator.interpolate(addPath, { lng, ns: namespace })
104104

105105
this.options.request(this.options, url, payload, (data, res) => {
106106
// TODO: if res.status === 4xx do log

lib/request.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ const request = (options, url, payload, callback) => {
122122
// use xml http request
123123
return requestWithXmlHttpRequest(options, url, payload, callback)
124124
}
125+
126+
callback(new Error('No fetch and no xhr implementation found!'))
125127
}
126128

127129
export default request

package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,24 @@
2323
},
2424
"types": "./index.d.ts",
2525
"devDependencies": {
26-
"@babel/cli": "7.16.8",
27-
"@babel/core": "7.16.10",
28-
"@babel/preset-env": "7.16.11",
26+
"@babel/cli": "7.18.10",
27+
"@babel/core": "7.19.1",
28+
"@babel/preset-env": "7.19.1",
2929
"babel-plugin-add-module-exports": "1.0.4",
3030
"browserify": "17.0.0",
31-
"eslint": "7.32.0",
32-
"eslint-config-standard": "16.0.3",
33-
"eslint-plugin-import": "2.25.4",
34-
"eslint-plugin-node": "11.1.0",
35-
"eslint-plugin-promise": "5.2.0",
31+
"eslint": "8.23.1",
32+
"eslint-config-standard": "17.0.0",
33+
"eslint-plugin-import": "2.26.0",
34+
"eslint-plugin-n": "15.2.5",
35+
"eslint-plugin-promise": "6.0.1",
3636
"eslint-plugin-require-path-exists": "1.1.9",
3737
"eslint-plugin-standard": "5.0.0",
3838
"expect.js": "0.3.1",
39-
"i18next": "21.6.6",
39+
"i18next": "21.9.2",
4040
"json-server": "0.17.0",
41-
"json5": "2.2.0",
42-
"mocha": "9.1.4",
43-
"uglify-js": "3.14.5",
41+
"json5": "2.2.1",
42+
"mocha": "10.0.0",
43+
"uglify-js": "3.17.0",
4444
"xmlhttprequest": "1.8.0"
4545
},
4646
"description": "i18next-http-backend is a backend layer for i18next using in Node.js, in the browser and for Deno.",
@@ -60,8 +60,8 @@
6060
"license": "MIT",
6161
"scripts": {
6262
"lint": "eslint .",
63-
"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', ''))\"",
64-
"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'))\"",
63+
"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', ''))\"",
64+
"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'))\"",
6565
"compile": "npm run compile:esm && npm run compile:cjs",
6666
"browser": "browserify --ignore cross-fetch --standalone i18nextHttpBackend cjs/index.js -o i18nextHttpBackend.js && uglifyjs i18nextHttpBackend.js --compress --mangle -o i18nextHttpBackend.min.js",
6767
"build": "npm run compile && npm run browser",

0 commit comments

Comments
 (0)