resolve-accept-language 1.1.40 → 1.1.42
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/lib/lookup-list.d.ts +8 -4
- package/lib/lookup-list.js +12 -6
- package/package.json +29 -27
package/lib/lookup-list.d.ts
CHANGED
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
export default class LookupList {
|
|
3
3
|
/** The list of locales used to get the match during the lookup. */
|
|
4
4
|
private localeList;
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
5
|
+
/**
|
|
6
|
+
* Data object where the properties are quality (in string format) and their values a set containing locale
|
|
7
|
+
* identifiers using the `language`-`country` format and ISO 639-1 alpha-2 language code.
|
|
8
|
+
*/
|
|
7
9
|
private localesAndLanguagesByQuality;
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
+
/**
|
|
11
|
+
* Data object where the properties are quality (in string format) and their value a set of ISO 639-1 alpha-2
|
|
12
|
+
* language code.
|
|
13
|
+
*/
|
|
10
14
|
private relatedLocaleLanguagesByQuality;
|
|
11
15
|
/**
|
|
12
16
|
* Create a new `LookupList` object.
|
package/lib/lookup-list.js
CHANGED
|
@@ -11,11 +11,15 @@ var LookupList = /** @class */ (function () {
|
|
|
11
11
|
* likely to be matched than the last identifier.
|
|
12
12
|
*/
|
|
13
13
|
function LookupList(acceptLanguageHeader, locales) {
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
14
|
+
/**
|
|
15
|
+
* Data object where the properties are quality (in string format) and their values a set containing locale
|
|
16
|
+
* identifiers using the `language`-`country` format and ISO 639-1 alpha-2 language code.
|
|
17
|
+
*/
|
|
16
18
|
this.localesAndLanguagesByQuality = {};
|
|
17
|
-
/**
|
|
18
|
-
*
|
|
19
|
+
/**
|
|
20
|
+
* Data object where the properties are quality (in string format) and their value a set of ISO 639-1 alpha-2
|
|
21
|
+
* language code.
|
|
22
|
+
*/
|
|
19
23
|
this.relatedLocaleLanguagesByQuality = {};
|
|
20
24
|
this.localeList = new locale_list_1.default(locales);
|
|
21
25
|
var directiveStrings = acceptLanguageHeader
|
|
@@ -24,8 +28,9 @@ var LookupList = /** @class */ (function () {
|
|
|
24
28
|
for (var _i = 0, directiveStrings_1 = directiveStrings; _i < directiveStrings_1.length; _i++) {
|
|
25
29
|
var directiveString = directiveStrings_1[_i];
|
|
26
30
|
var directive = this.getDirective(directiveString);
|
|
27
|
-
if (directive === undefined)
|
|
31
|
+
if (directive === undefined) {
|
|
28
32
|
continue; // No match for this directive.
|
|
33
|
+
}
|
|
29
34
|
var locale = directive.locale, languageCode = directive.languageCode, quality = directive.quality;
|
|
30
35
|
// If the language is not supported, skip to the next match.
|
|
31
36
|
if (!this.localeList.languages.has(languageCode)) {
|
|
@@ -134,8 +139,9 @@ var LookupList = /** @class */ (function () {
|
|
|
134
139
|
* - A quality value equivalent to "0", as per RFC 2616 (section 3.9), should be considered as "not acceptable".
|
|
135
140
|
*/
|
|
136
141
|
var directiveMatch = directiveString.match(/^((?<matchedLanguageCode>([a-z]{2}))(-(?<matchedCountryCode>[a-z]{2}))?)(;q=(?<matchedQuality>(1(\.0{0,3})?)|(0(\.\d{0,3})?)))?$/i);
|
|
137
|
-
if (!(directiveMatch === null || directiveMatch === void 0 ? void 0 : directiveMatch.groups))
|
|
142
|
+
if (!(directiveMatch === null || directiveMatch === void 0 ? void 0 : directiveMatch.groups)) {
|
|
138
143
|
return undefined; // No regular expression match.
|
|
144
|
+
}
|
|
139
145
|
var _a = directiveMatch.groups, matchedLanguageCode = _a.matchedLanguageCode, matchedCountryCode = _a.matchedCountryCode, matchedQuality = _a.matchedQuality;
|
|
140
146
|
var languageCode = matchedLanguageCode.toLowerCase();
|
|
141
147
|
var countryCode = matchedCountryCode ? matchedCountryCode.toUpperCase() : undefined;
|
package/package.json
CHANGED
|
@@ -1,27 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "resolve-accept-language",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.42",
|
|
4
4
|
"description": "Resolve the preferred locale based on the value of an `Accept-Language` HTTP header.",
|
|
5
|
-
"author": "Avansai (https://avansai.com)",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/Avansai/resolve-accept-language.git"
|
|
9
|
-
},
|
|
10
|
-
"main": "lib/resolve-accept-language.js",
|
|
11
|
-
"types": "lib/resolve-accept-language.d.ts",
|
|
12
|
-
"scripts": {
|
|
13
|
-
"build": "npm run prettier && npm run lint-fix && rm -Rf ./lib && tsc && npm run test",
|
|
14
|
-
"lint-fix": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx --fix .",
|
|
15
|
-
"lint-check": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx .",
|
|
16
|
-
"lint-print-config": "eslint --print-config ./eslintrc.yaml",
|
|
17
|
-
"prettier": "prettier --write .",
|
|
18
|
-
"test": "jest --coverage",
|
|
19
|
-
"release": "dotenv -- release-it --only-version"
|
|
20
|
-
},
|
|
21
|
-
"license": "MIT",
|
|
22
|
-
"files": [
|
|
23
|
-
"lib"
|
|
24
|
-
],
|
|
25
5
|
"keywords": [
|
|
26
6
|
"accept-language",
|
|
27
7
|
"RFC 4647",
|
|
@@ -36,29 +16,51 @@
|
|
|
36
16
|
"i18n",
|
|
37
17
|
"internationalization"
|
|
38
18
|
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/Avansai/resolve-accept-language.git"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"author": "Avansai (https://avansai.com)",
|
|
25
|
+
"main": "lib/resolve-accept-language.js",
|
|
26
|
+
"types": "lib/resolve-accept-language.d.ts",
|
|
27
|
+
"files": [
|
|
28
|
+
"lib"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "npm run prettier && npm run lint-fix && rm -Rf ./lib && tsc && npm run test",
|
|
32
|
+
"lint-check": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx --ext .json .",
|
|
33
|
+
"lint-fix": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx --ext .json --fix .",
|
|
34
|
+
"lint-print-config": "eslint --print-config ./eslintrc.yaml",
|
|
35
|
+
"prettier": "prettier --write .",
|
|
36
|
+
"release": "dotenv -- release-it --only-version",
|
|
37
|
+
"test": "jest --coverage"
|
|
38
|
+
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@release-it/conventional-changelog": "^5.1.1",
|
|
41
41
|
"@types/jest": "^29.4.0",
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
43
|
-
"@typescript-eslint/parser": "^5.
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^5.51.0",
|
|
43
|
+
"@typescript-eslint/parser": "^5.51.0",
|
|
44
44
|
"dotenv-cli": "^7.0.0",
|
|
45
|
-
"eslint": "^8.
|
|
45
|
+
"eslint": "^8.34.0",
|
|
46
46
|
"eslint-config-prettier": "^8.6.0",
|
|
47
47
|
"eslint-import-resolver-node": "^0.3.7",
|
|
48
48
|
"eslint-import-resolver-typescript": "^3.5.3",
|
|
49
49
|
"eslint-plugin-import": "^2.27.5",
|
|
50
50
|
"eslint-plugin-jest": "^27.2.1",
|
|
51
|
+
"eslint-plugin-json-files": "^2.1.0",
|
|
51
52
|
"eslint-plugin-prefer-arrow-functions": "^3.1.4",
|
|
52
53
|
"eslint-plugin-prettier": "^4.2.1",
|
|
54
|
+
"eslint-plugin-tsdoc": "^0.2.17",
|
|
53
55
|
"eslint-plugin-unicorn": "^45.0.2",
|
|
54
|
-
"jest": "^29.4.
|
|
55
|
-
"prettier": "^2.8.
|
|
56
|
+
"jest": "^29.4.2",
|
|
57
|
+
"prettier": "^2.8.4",
|
|
56
58
|
"prettier-plugin-organize-imports": "^3.2.2",
|
|
57
59
|
"prettier-plugin-sh": "^0.12.8",
|
|
58
60
|
"release-it": "^15.6.0",
|
|
59
61
|
"ts-jest": "^29.0.5",
|
|
60
62
|
"ts-node": "^10.9.1",
|
|
61
|
-
"typescript": "^4.9.
|
|
63
|
+
"typescript": "^4.9.5"
|
|
62
64
|
},
|
|
63
65
|
"engines": {
|
|
64
66
|
"node": "^14.18.1 || >=16.0.0"
|