i18next-http-middleware 3.1.0 → 3.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## [v3.1.4](https://github.com/i18next/i18next-http-middleware/compare/v3.1.3...v3.1.4)
2
+ - fix for [point-of-view](https://github.com/fastify/point-of-view)
3
+ - update all dependencies
4
+
5
+ ## [v3.1.3](https://github.com/i18next/i18next-http-middleware/compare/v3.1.2...v3.1.3)
6
+ - optimize getQuery() function to check if req.query is iterable
7
+
8
+ ## [v3.1.2](https://github.com/i18next/i18next-http-middleware/compare/v3.1.1...v3.1.2)
9
+ - fix the type of the lookup method [#37](https://github.com/i18next/i18next-http-middleware/pull/37)
10
+
11
+ ## [v3.1.1](https://github.com/i18next/i18next-http-middleware/compare/v3.1.0...v3.1.1)
12
+ - make sure no undefined language is detected
13
+
1
14
  ## [v3.1.0](https://github.com/i18next/i18next-http-middleware/compare/v3.0.6...v3.1.0)
2
15
  - added types
3
16
 
@@ -23,9 +23,9 @@ var _httpFunctions = require("./httpFunctions.js");
23
23
 
24
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
25
 
26
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
26
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
27
 
28
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
28
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
29
 
30
30
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
31
31
 
@@ -92,6 +92,9 @@ var LanguageDetector = function () {
92
92
 
93
93
  if (!detections) return;
94
94
  if (!Array.isArray(detections)) detections = [detections];
95
+ detections = detections.filter(function (d) {
96
+ return d !== undefined && d !== null;
97
+ });
95
98
 
96
99
  if (_this.services.languageUtils.getBestMatchFromCodes) {
97
100
  found = _this.services.languageUtils.getBestMatchFromCodes(detections);
@@ -42,7 +42,7 @@ var getOriginalUrl = function getOriginalUrl(req) {
42
42
  exports.getOriginalUrl = getOriginalUrl;
43
43
 
44
44
  var getQuery = function getQuery(req) {
45
- if (req.query && typeof req.query.entries === 'function' && typeof Object.fromEntries === 'function') return Object.fromEntries(req.query);
45
+ if (req.query && typeof req.query.entries === 'function' && typeof Object.fromEntries === 'function' && typeof req.query[Symbol.iterator] === 'function') return Object.fromEntries(req.query);
46
46
  if (req.query) return req.query;
47
47
  if (req.raw && req.raw.query) return req.raw.query;
48
48
  if (req.ctx && req.ctx.queryParams) return req.ctx.queryParams;
package/cjs/index.js CHANGED
@@ -20,9 +20,9 @@ var _httpFunctions = require("./httpFunctions.js");
20
20
 
21
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
22
 
23
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
23
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
24
24
 
25
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
26
26
 
27
27
  var LanguageDetector = _LanguageDetector.default;
28
28
  exports.LanguageDetector = LanguageDetector;
@@ -73,6 +73,7 @@ function handle(i18next) {
73
73
  });
74
74
  i18n.on('languageChanged', function (lng) {
75
75
  req.language = req.locale = req.lng = lng;
76
+ if (options.attachLocals) res.locals = res.locals || {};
76
77
 
77
78
  if (res.locals) {
78
79
  res.locals.language = lng;
@@ -108,6 +109,7 @@ function handle(i18next) {
108
109
  var exists = i18n.exists.bind(i18n);
109
110
  req.i18n = i18n;
110
111
  req.t = t;
112
+ if (options.attachLocals) res.locals = res.locals || {};
111
113
 
112
114
  if (res.locals) {
113
115
  res.locals.t = t;
@@ -126,6 +128,7 @@ function handle(i18next) {
126
128
  }
127
129
 
128
130
  function plugin(instance, options, next) {
131
+ options.attachLocals = true;
129
132
  var middleware = handle(options.i18next, options);
130
133
  instance.addHook('preHandler', function (request, reply, next) {
131
134
  return middleware(request, reply, next);
@@ -71,6 +71,9 @@ var LanguageDetector = function () {
71
71
 
72
72
  if (!detections) return;
73
73
  if (!Array.isArray(detections)) detections = [detections];
74
+ detections = detections.filter(function (d) {
75
+ return d !== undefined && d !== null;
76
+ });
74
77
 
75
78
  if (_this.services.languageUtils.getBestMatchFromCodes) {
76
79
  found = _this.services.languageUtils.getBestMatchFromCodes(detections);
@@ -23,7 +23,7 @@ export var getOriginalUrl = function getOriginalUrl(req) {
23
23
  return getUrl(req);
24
24
  };
25
25
  export var getQuery = function getQuery(req) {
26
- if (req.query && typeof req.query.entries === 'function' && typeof Object.fromEntries === 'function') return Object.fromEntries(req.query);
26
+ if (req.query && typeof req.query.entries === 'function' && typeof Object.fromEntries === 'function' && typeof req.query[Symbol.iterator] === 'function') return Object.fromEntries(req.query);
27
27
  if (req.query) return req.query;
28
28
  if (req.raw && req.raw.query) return req.raw.query;
29
29
  if (req.ctx && req.ctx.queryParams) return req.ctx.queryParams;
package/esm/index.js CHANGED
@@ -49,6 +49,7 @@ export function handle(i18next) {
49
49
  });
50
50
  i18n.on('languageChanged', function (lng) {
51
51
  req.language = req.locale = req.lng = lng;
52
+ if (options.attachLocals) res.locals = res.locals || {};
52
53
 
53
54
  if (res.locals) {
54
55
  res.locals.language = lng;
@@ -84,6 +85,7 @@ export function handle(i18next) {
84
85
  var exists = i18n.exists.bind(i18n);
85
86
  req.i18n = i18n;
86
87
  req.t = t;
88
+ if (options.attachLocals) res.locals = res.locals || {};
87
89
 
88
90
  if (res.locals) {
89
91
  res.locals.t = t;
@@ -101,6 +103,7 @@ export function handle(i18next) {
101
103
  };
102
104
  }
103
105
  export function plugin(instance, options, next) {
106
+ options.attachLocals = true;
104
107
  var middleware = handle(options.i18next, options);
105
108
  instance.addHook('preHandler', function (request, reply, next) {
106
109
  return middleware(request, reply, next);
package/index.d.ts CHANGED
@@ -123,7 +123,7 @@ interface LanguageDetectorInterface {
123
123
  req: Request,
124
124
  res: Response,
125
125
  options?: LanguageDetectorInterfaceOptions
126
- ) => string | string[];
126
+ ) => string | string[] | undefined;
127
127
 
128
128
  cacheUserLanguage?: (
129
129
  req: Request,
@@ -60,6 +60,8 @@ class LanguageDetector {
60
60
  if (!detections) return
61
61
  if (!Array.isArray(detections)) detections = [detections]
62
62
 
63
+ detections = detections.filter((d) => d !== undefined && d !== null)
64
+
63
65
  if (this.services.languageUtils.getBestMatchFromCodes) { // new i18next v19.5.0
64
66
  found = this.services.languageUtils.getBestMatchFromCodes(detections)
65
67
  if (found) {
@@ -22,7 +22,7 @@ export const getOriginalUrl = (req) => {
22
22
  return getUrl(req)
23
23
  }
24
24
  export const getQuery = (req) => {
25
- if (req.query && typeof req.query.entries === 'function' && typeof Object.fromEntries === 'function') return Object.fromEntries(req.query)
25
+ if (req.query && typeof req.query.entries === 'function' && typeof Object.fromEntries === 'function' && typeof req.query[Symbol.iterator] === 'function') return Object.fromEntries(req.query)
26
26
  if (req.query) return req.query
27
27
  if (req.raw && req.raw.query) return req.raw.query
28
28
  if (req.ctx && req.ctx.queryParams) return req.ctx.queryParams
package/lib/index.js CHANGED
@@ -40,6 +40,7 @@ export function handle (i18next, options = {}) {
40
40
  i18n.on('languageChanged', (lng) => { // Keep language in sync
41
41
  req.language = req.locale = req.lng = lng
42
42
 
43
+ if (options.attachLocals) res.locals = res.locals || {}
43
44
  if (res.locals) {
44
45
  res.locals.language = lng
45
46
  res.locals.languageDir = i18next.dir(lng)
@@ -81,6 +82,7 @@ export function handle (i18next, options = {}) {
81
82
  req.t = t
82
83
 
83
84
  // assert for res -> template
85
+ if (options.attachLocals) res.locals = res.locals || {}
84
86
  if (res.locals) {
85
87
  res.locals.t = t
86
88
  res.locals.exists = exists
@@ -97,6 +99,7 @@ export function handle (i18next, options = {}) {
97
99
  }
98
100
 
99
101
  export function plugin (instance, options, next) {
102
+ options.attachLocals = true
100
103
  const middleware = handle(options.i18next, options)
101
104
  instance.addHook('preHandler', (request, reply, next) => middleware(request, reply, next))
102
105
  return next()
package/licence CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2020 i18next
1
+ Copyright (c) 2021 i18next
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next-http-middleware",
3
- "version": "3.1.0",
3
+ "version": "3.1.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./cjs/index.js",
@@ -21,26 +21,26 @@
21
21
  "module": "./esm/index.js",
22
22
  "dependencies": {},
23
23
  "devDependencies": {
24
- "@babel/cli": "7.12.10",
25
- "@babel/core": "7.12.10",
26
- "@babel/preset-env": "7.12.11",
27
- "@types/express-serve-static-core": "^4.17.18",
24
+ "@babel/cli": "7.14.5",
25
+ "@babel/core": "7.14.6",
26
+ "@babel/preset-env": "7.14.7",
27
+ "@types/express-serve-static-core": "^4.17.21",
28
28
  "babel-plugin-add-module-exports": "1.0.4",
29
- "eslint": "7.17.0",
30
- "eslint-config-standard": "16.0.2",
31
- "eslint-plugin-import": "2.22.1",
29
+ "eslint": "7.29.0",
30
+ "eslint-config-standard": "16.0.3",
31
+ "eslint-plugin-import": "2.23.4",
32
32
  "eslint-plugin-node": "11.1.0",
33
- "eslint-plugin-promise": "4.2.1",
33
+ "eslint-plugin-promise": "5.1.0",
34
34
  "eslint-plugin-require-path-exists": "1.1.9",
35
35
  "eslint-plugin-standard": "5.0.0",
36
36
  "expect.js": "0.3.1",
37
37
  "express": "4.17.1",
38
- "fastify": "3.9.2",
39
- "i18next": "19.8.4",
40
- "mocha": "8.2.1",
41
- "supertest": "6.0.1",
42
- "tsd": "0.14.0",
43
- "uglify-js": "3.12.4"
38
+ "fastify": "3.18.0",
39
+ "i18next": "20.3.2",
40
+ "mocha": "9.0.1",
41
+ "supertest": "6.1.3",
42
+ "tsd": "0.17.0",
43
+ "uglify-js": "3.13.9"
44
44
  },
45
45
  "description": "i18next-http-middleware is a middleware to be used with Node.js web frameworks like express or Fastify and also for Deno.",
46
46
  "keywords": [
@@ -57,12 +57,7 @@
57
57
  "bugs": {
58
58
  "url": "https://github.com/i18next/i18next-http-middleware/issues"
59
59
  },
60
- "licenses": [
61
- {
62
- "type": "MIT",
63
- "url": "https://raw.github.com/i18next/i18next-http-middleware/master/licence"
64
- }
65
- ],
60
+ "license": "MIT",
66
61
  "scripts": {
67
62
  "lint": "eslint .",
68
63
  "compile:esm": "rm -rf esm && mkdir esm && BABEL_ENV=esm babel lib -d esm",