resolve-accept-language 2.0.19 → 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/lib/lookup-list.js +33 -1
- package/package.json +5 -5
package/lib/lookup-list.js
CHANGED
|
@@ -40,6 +40,33 @@ var LookupList = /** @class */ (function () {
|
|
|
40
40
|
.split(',')
|
|
41
41
|
.map(function (directiveString) { return _this.getDirective(directiveString.trim()); })
|
|
42
42
|
.filter(function (directive) { return directive !== undefined; });
|
|
43
|
+
// Check if 'es-419' exists in the directives
|
|
44
|
+
var es419DirectiveIndex = directives.findIndex(function (directive) { return directive.locale === 'es-419'; });
|
|
45
|
+
if (es419DirectiveIndex >= 0) {
|
|
46
|
+
// Remove 'es-419' from the directive.
|
|
47
|
+
var es419Directive_1 = directives[es419DirectiveIndex];
|
|
48
|
+
directives.splice(es419DirectiveIndex, 1);
|
|
49
|
+
// Replace `es-419` by the common Latin American spanish variants supported by browsers.
|
|
50
|
+
var latinAmericanLocales = [
|
|
51
|
+
'es-AR',
|
|
52
|
+
'es-CL',
|
|
53
|
+
'es-CO',
|
|
54
|
+
'es-CR',
|
|
55
|
+
'es-HN',
|
|
56
|
+
'es-MX',
|
|
57
|
+
'es-PE',
|
|
58
|
+
'es-US',
|
|
59
|
+
'es-UY',
|
|
60
|
+
'es-VE', // Spanish Venezuela
|
|
61
|
+
];
|
|
62
|
+
latinAmericanLocales.forEach(function (locale) {
|
|
63
|
+
directives.push({
|
|
64
|
+
languageCode: 'es',
|
|
65
|
+
locale: locale,
|
|
66
|
+
quality: es419Directive_1.quality,
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
43
70
|
for (var _i = 0, directives_1 = directives; _i < directives_1.length; _i++) {
|
|
44
71
|
var directive = directives_1[_i];
|
|
45
72
|
var locale = directive.locale, languageCode = directive.languageCode, quality = directive.quality;
|
|
@@ -147,14 +174,19 @@ var LookupList = /** @class */ (function () {
|
|
|
147
174
|
* - The wildcard character "*", as per RFC 2616 (section 14.4), should match any unmatched language tag.
|
|
148
175
|
* - Language tags that starts with a wildcard (e.g., "*-CA") should match the first supported locale of a country.
|
|
149
176
|
* - A quality value equivalent to "0", as per RFC 2616 (section 3.9), should be considered as "not acceptable".
|
|
177
|
+
* - We hardcode the support for the `419` UN M49 code (as country code) representing Latin America to support `es-419`.
|
|
150
178
|
*/
|
|
151
|
-
var directiveMatch = directiveString.match(/^((?<matchedLanguageCode>([a-z]{2}))(-(?<matchedCountryCode>[a-z]{2}))?)(;q=(?<matchedQuality>(1(\.0{0,3})?)|(0(\.\d{0,3})?)))?$/i);
|
|
179
|
+
var directiveMatch = directiveString.match(/^((?<matchedLanguageCode>([a-z]{2}))(-(?<matchedCountryCode>[a-z]{2}|419))?)(;q=(?<matchedQuality>(1(\.0{0,3})?)|(0(\.\d{0,3})?)))?$/i);
|
|
152
180
|
if (!(directiveMatch === null || directiveMatch === void 0 ? void 0 : directiveMatch.groups)) {
|
|
153
181
|
return undefined; // No regular expression match.
|
|
154
182
|
}
|
|
155
183
|
var _a = directiveMatch.groups, matchedLanguageCode = _a.matchedLanguageCode, matchedCountryCode = _a.matchedCountryCode, matchedQuality = _a.matchedQuality;
|
|
156
184
|
var languageCode = matchedLanguageCode.toLowerCase();
|
|
157
185
|
var countryCode = matchedCountryCode ? matchedCountryCode.toUpperCase() : undefined;
|
|
186
|
+
// Only `es-419` is supported in browsers - if any other languages are using `419` we filter them out.
|
|
187
|
+
if (countryCode === '419' && languageCode !== 'es') {
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
158
190
|
var quality = matchedQuality === undefined ? '1' : Number.parseFloat(matchedQuality).toString(); // Remove trailing zeros.
|
|
159
191
|
var locale = countryCode ? "".concat(languageCode, "-").concat(countryCode) : undefined;
|
|
160
192
|
return { languageCode: languageCode, locale: locale, quality: quality };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "resolve-accept-language",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Resolve the preferred locale based on the value of an `Accept-Language` HTTP header.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"accept-language",
|
|
@@ -39,15 +39,15 @@
|
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@release-it/conventional-changelog": "7.0.2",
|
|
41
41
|
"@types/jest": "29.5.5",
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "6.7.
|
|
43
|
-
"@typescript-eslint/parser": "6.7.
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "6.7.3",
|
|
43
|
+
"@typescript-eslint/parser": "6.7.3",
|
|
44
44
|
"dotenv-cli": "7.3.0",
|
|
45
45
|
"eslint": "8.50.0",
|
|
46
46
|
"eslint-config-prettier": "9.0.0",
|
|
47
47
|
"eslint-import-resolver-node": "0.3.9",
|
|
48
48
|
"eslint-import-resolver-typescript": "3.6.1",
|
|
49
49
|
"eslint-plugin-import": "2.28.1",
|
|
50
|
-
"eslint-plugin-jest": "27.4.
|
|
50
|
+
"eslint-plugin-jest": "27.4.2",
|
|
51
51
|
"eslint-plugin-json-files": "3.0.0",
|
|
52
52
|
"eslint-plugin-prefer-arrow-functions": "3.1.4",
|
|
53
53
|
"eslint-plugin-prettier": "5.0.0",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"prettier": "3.0.3",
|
|
58
58
|
"prettier-plugin-organize-imports": "3.2.3",
|
|
59
59
|
"prettier-plugin-sh": "0.13.1",
|
|
60
|
-
"release-it": "16.1
|
|
60
|
+
"release-it": "16.2.1",
|
|
61
61
|
"ts-jest": "29.1.1",
|
|
62
62
|
"ts-node": "10.9.1",
|
|
63
63
|
"typescript": "5.2.2"
|