parse-accept-language 1.0.2 → 2.1.0
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/README.md +7 -7
- package/lib/parse-accept-language.js +7 -10
- package/package.json +12 -7
- package/.editorconfig +0 -12
- package/.npmignore +0 -6
- package/.project +0 -11
- package/History.md +0 -15
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[![NPM version][npm-image]][npm-url]
|
|
2
|
-
[![Build Status][
|
|
3
|
-
[![Dependency Status][
|
|
2
|
+
[![Build Status][build-image]][build-url]
|
|
3
|
+
[![Dependency Status][deps-image]][deps-url]
|
|
4
4
|
|
|
5
5
|
# parse-accept-language
|
|
6
6
|
|
|
@@ -24,11 +24,11 @@ var pal = parseAcceptLanguage(req);
|
|
|
24
24
|
|
|
25
25
|
MIT © [Damian Krzeminski](https://pirxpilot.me)
|
|
26
26
|
|
|
27
|
-
[npm-image]: https://img.shields.io/npm/v/parse-accept-language
|
|
27
|
+
[npm-image]: https://img.shields.io/npm/v/parse-accept-language
|
|
28
28
|
[npm-url]: https://npmjs.org/package/parse-accept-language
|
|
29
29
|
|
|
30
|
-
[
|
|
31
|
-
[
|
|
30
|
+
[build-url]: https://github.com/pirxpilot/parse-accept-language/actions/workflows/check.yaml
|
|
31
|
+
[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/parse-accept-language/check.yaml?branch=main
|
|
32
32
|
|
|
33
|
-
[
|
|
34
|
-
[
|
|
33
|
+
[deps-image]: https://img.shields.io/librariesio/release/npm/parse-accept-language
|
|
34
|
+
[deps-url]: https://libraries.io/npm/parse-accept-language
|
|
@@ -2,9 +2,8 @@ module.exports = parse;
|
|
|
2
2
|
module.exports.toArray = str2array;
|
|
3
3
|
|
|
4
4
|
function parseTag(tag) {
|
|
5
|
-
var el, lang;
|
|
6
5
|
tag = tag.split(';');
|
|
7
|
-
el = {
|
|
6
|
+
const el = {
|
|
8
7
|
value: tag[0].trim(),
|
|
9
8
|
q: tag[1]
|
|
10
9
|
};
|
|
@@ -12,7 +11,7 @@ function parseTag(tag) {
|
|
|
12
11
|
return;
|
|
13
12
|
}
|
|
14
13
|
|
|
15
|
-
lang = el.value.split('-');
|
|
14
|
+
const lang = el.value.split('-');
|
|
16
15
|
|
|
17
16
|
el.language = lang[0];
|
|
18
17
|
el.region = (lang[1] || '').toUpperCase();
|
|
@@ -27,13 +26,11 @@ function parseTag(tag) {
|
|
|
27
26
|
return el;
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
function str2array(acceptLanguage) {
|
|
31
|
-
return
|
|
29
|
+
function str2array(acceptLanguage = '') {
|
|
30
|
+
return acceptLanguage.split(',')
|
|
32
31
|
.map(parseTag)
|
|
33
|
-
.filter(
|
|
34
|
-
.sort(
|
|
35
|
-
return b.q - a.q;
|
|
36
|
-
});
|
|
32
|
+
.filter(Boolean) // filter empty
|
|
33
|
+
.sort((a, b) => b.q - a.q);
|
|
37
34
|
}
|
|
38
35
|
|
|
39
36
|
// parse Accept-Language header with memoization
|
|
@@ -41,7 +38,7 @@ function parse(req) {
|
|
|
41
38
|
if(req._parsedAcceptLanguage) {
|
|
42
39
|
return req._parsedAcceptLanguage;
|
|
43
40
|
}
|
|
44
|
-
|
|
41
|
+
const acceptLanguage = req.headers['accept-language'];
|
|
45
42
|
req._parsedAcceptLanguage = str2array(acceptLanguage);
|
|
46
43
|
req._parsedAcceptLanguage._raw = acceptLanguage;
|
|
47
44
|
return req._parsedAcceptLanguage;
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "parse-accept-language",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Parse 'Accept-Language' header and cache the result in request.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Damian Krzeminski",
|
|
7
7
|
"email": "pirxpilot@furkot.com",
|
|
8
8
|
"url": "https://pirxpilot.me"
|
|
9
9
|
},
|
|
10
|
-
"repository":
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/pirxpilot/parse-accept-language.git"
|
|
13
|
+
},
|
|
11
14
|
"license": "MIT",
|
|
12
15
|
"keywords": [
|
|
13
16
|
"parse-accept-language",
|
|
@@ -18,11 +21,13 @@
|
|
|
18
21
|
],
|
|
19
22
|
"dependencies": {},
|
|
20
23
|
"devDependencies": {
|
|
21
|
-
"jshint": "
|
|
22
|
-
"mocha": "^2.2.4",
|
|
23
|
-
"should": "^6.0.1"
|
|
24
|
+
"@pirxpilot/jshint": "~3"
|
|
24
25
|
},
|
|
25
26
|
"scripts": {
|
|
26
27
|
"test": "make check"
|
|
27
|
-
}
|
|
28
|
-
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"index.js",
|
|
31
|
+
"lib"
|
|
32
|
+
]
|
|
33
|
+
}
|
package/.editorconfig
DELETED
package/.npmignore
DELETED
package/.project
DELETED
package/History.md
DELETED