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 CHANGED
@@ -1,6 +1,6 @@
1
1
  [![NPM version][npm-image]][npm-url]
2
- [![Build Status][travis-image]][travis-url]
3
- [![Dependency Status][gemnasium-image]][gemnasium-url]
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.svg
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
- [travis-url]: https://travis-ci.org/pirxpilot/parse-accept-language
31
- [travis-image]: https://img.shields.io/travis/pirxpilot/parse-accept-language.svg
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
- [gemnasium-image]: https://img.shields.io/gemnasium/pirxpilot/parse-accept-language.svg
34
- [gemnasium-url]: https://gemnasium.com/pirxpilot/parse-accept-language
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 (acceptLanguage || '').split(',')
29
+ function str2array(acceptLanguage = '') {
30
+ return acceptLanguage.split(',')
32
31
  .map(parseTag)
33
- .filter(function(el) { return el; }) // filter empty
34
- .sort(function(a, b) {
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
- var acceptLanguage = req.get('accept-language');
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.2",
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": "pirxpilot/parse-accept-language",
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": "^2.7.0",
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
@@ -1,12 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- indent_style = space
5
- indent_size = 2
6
- end_of_line = lf
7
- charset = utf-8
8
- trim_trailing_whitespace = true
9
- insert_final_newline = true
10
-
11
- [*.md]
12
- trim_trailing_whitespace = false
package/.npmignore DELETED
@@ -1,6 +0,0 @@
1
- test
2
- Makefile
3
- History.md
4
- License
5
- .travis.yml
6
- .jshintrc
package/.project DELETED
@@ -1,11 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <projectDescription>
3
- <name>pirxpilot-parse-accept-language</name>
4
- <comment></comment>
5
- <projects>
6
- </projects>
7
- <buildSpec>
8
- </buildSpec>
9
- <natures>
10
- </natures>
11
- </projectDescription>
package/History.md DELETED
@@ -1,15 +0,0 @@
1
-
2
- 1.0.2 / 2017-02-20
3
- ==================
4
-
5
- * transfer repo to pirxpilot
6
-
7
- 1.0.1 / 2015-08-01
8
- ==================
9
-
10
- * convert parsed region to upper case
11
-
12
- 1.0.0 / 2015-05-08
13
- ==================
14
-
15
- * initial implementation