resolve-accept-language 1.1.45-0 → 1.1.45
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/locale-list.js +13 -14
- package/lib/locale.js +19 -15
- package/lib/lookup-list.js +38 -39
- package/lib/resolve-accept-language.js +35 -28
- package/package.json +5 -7
package/lib/locale-list.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
var locale_1 = require("./locale");
|
|
4
|
+
var LocaleList = /** @class */ (function () {
|
|
8
5
|
/**
|
|
9
6
|
* Create a list of locale identifiers.
|
|
10
7
|
*
|
|
@@ -12,7 +9,8 @@ class LocaleList {
|
|
|
12
9
|
*
|
|
13
10
|
* @throws Will throw an error if one of the locale's format is invalid.
|
|
14
11
|
*/
|
|
15
|
-
|
|
12
|
+
function LocaleList(locales) {
|
|
13
|
+
var _this = this;
|
|
16
14
|
/** A set of ISO 3166-1 alpha-2 country codes. */
|
|
17
15
|
this.countries = new Set();
|
|
18
16
|
/** A set of ISO 639-1 alpha-2 language codes. */
|
|
@@ -21,15 +19,16 @@ class LocaleList {
|
|
|
21
19
|
this.locales = new Set();
|
|
22
20
|
/** A list of locale objects. */
|
|
23
21
|
this.objects = [];
|
|
24
|
-
locales.forEach((locale)
|
|
25
|
-
|
|
26
|
-
if (!
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
locales.forEach(function (locale) {
|
|
23
|
+
var localeObject = new locale_1.default(locale);
|
|
24
|
+
if (!_this.locales.has(localeObject.identifier)) {
|
|
25
|
+
_this.objects.push(localeObject);
|
|
26
|
+
_this.locales.add(localeObject.identifier);
|
|
27
|
+
_this.languages.add(localeObject.languageCode);
|
|
28
|
+
_this.countries.add(localeObject.countryCode);
|
|
31
29
|
}
|
|
32
30
|
});
|
|
33
31
|
}
|
|
34
|
-
|
|
32
|
+
return LocaleList;
|
|
33
|
+
}());
|
|
35
34
|
exports.default = LocaleList;
|
package/lib/locale.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
/** Class to manage a locale identifier using the BCP 47 `language`-`country` format. */
|
|
4
|
-
|
|
4
|
+
var Locale = /** @class */ (function () {
|
|
5
5
|
/**
|
|
6
6
|
* Create a new `Locale` object.
|
|
7
7
|
*
|
|
@@ -9,14 +9,14 @@ class Locale {
|
|
|
9
9
|
*
|
|
10
10
|
* @throws An error if the `identifier` format is invalid.
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
function Locale(identifier) {
|
|
13
13
|
if (!Locale.isLocale(identifier, false)) {
|
|
14
|
-
throw new Error(
|
|
14
|
+
throw new Error("invalid locale identifier '".concat(identifier, "'"));
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
var _a = identifier.split('-'), languageCode = _a[0], countryCode = _a[1];
|
|
17
17
|
this.languageCode = languageCode.toLowerCase();
|
|
18
18
|
this.countryCode = countryCode.toUpperCase();
|
|
19
|
-
this.identifier =
|
|
19
|
+
this.identifier = "".concat(this.languageCode, "-").concat(this.countryCode);
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Is a given string an ISO 3166-1 alpha-2 country code.
|
|
@@ -24,29 +24,33 @@ class Locale {
|
|
|
24
24
|
* @param countryCode - An ISO 3166-1 alpha-2 country code.
|
|
25
25
|
* @param caseNormalized - Should we verify if the identifier is using the case-normalized format?
|
|
26
26
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
Locale.isCountryCode = function (countryCode, caseNormalized) {
|
|
28
|
+
if (caseNormalized === void 0) { caseNormalized = true; }
|
|
29
|
+
var regExp = new RegExp(/^[A-Z]{2}$/, caseNormalized ? undefined : 'i');
|
|
29
30
|
return regExp.test(countryCode);
|
|
30
|
-
}
|
|
31
|
+
};
|
|
31
32
|
/**
|
|
32
33
|
* Is a given string an ISO 639-1 alpha-2 language code.
|
|
33
34
|
*
|
|
34
35
|
* @param languageCode - An ISO 639-1 alpha-2 language code.
|
|
35
36
|
* @param caseNormalized - Should we verify if the identifier is using the case-normalized format?
|
|
36
37
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
Locale.isLanguageCode = function (languageCode, caseNormalized) {
|
|
39
|
+
if (caseNormalized === void 0) { caseNormalized = true; }
|
|
40
|
+
var regExp = new RegExp(/^[a-z]{2}$/, caseNormalized ? undefined : 'i');
|
|
39
41
|
return regExp.test(languageCode);
|
|
40
|
-
}
|
|
42
|
+
};
|
|
41
43
|
/**
|
|
42
44
|
* Is a given string a locale identifier following the BCP 47 `language`-`country` format.
|
|
43
45
|
*
|
|
44
46
|
* @param identifier - A potential locale identify to verify.
|
|
45
47
|
* @param caseNormalized - Should we verify if the identifier is using the case-normalized format?
|
|
46
48
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
Locale.isLocale = function (identifier, caseNormalized) {
|
|
50
|
+
if (caseNormalized === void 0) { caseNormalized = true; }
|
|
51
|
+
var regExp = new RegExp(/^[a-z]{2}-[A-Z]{2}$/, caseNormalized ? undefined : 'i');
|
|
49
52
|
return regExp.test(identifier);
|
|
50
|
-
}
|
|
51
|
-
|
|
53
|
+
};
|
|
54
|
+
return Locale;
|
|
55
|
+
}());
|
|
52
56
|
exports.default = Locale;
|
package/lib/lookup-list.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
3
|
+
var locale_list_1 = require("./locale-list");
|
|
7
4
|
/** Lookup list used to match the preferred locale based on the value of an `Accept-Language` HTTP header. */
|
|
8
|
-
|
|
5
|
+
var LookupList = /** @class */ (function () {
|
|
9
6
|
/**
|
|
10
7
|
* Create a new `LookupList` object.
|
|
11
8
|
*
|
|
@@ -13,7 +10,7 @@ class LookupList {
|
|
|
13
10
|
* @param locales - An array of locale identifiers. The order will be used for matching where the first identifier will be more
|
|
14
11
|
* likely to be matched than the last identifier.
|
|
15
12
|
*/
|
|
16
|
-
|
|
13
|
+
function LookupList(acceptLanguageHeader, locales) {
|
|
17
14
|
/**
|
|
18
15
|
* Data object where the properties are quality (in string format) and their values a set containing locale
|
|
19
16
|
* identifiers using the `language`-`country` format and ISO 639-1 alpha-2 language code.
|
|
@@ -25,15 +22,16 @@ class LookupList {
|
|
|
25
22
|
*/
|
|
26
23
|
this.relatedLocaleLanguagesByQuality = {};
|
|
27
24
|
this.localeList = new locale_list_1.default(locales);
|
|
28
|
-
|
|
25
|
+
var directiveStrings = acceptLanguageHeader
|
|
29
26
|
.split(',')
|
|
30
|
-
.map((directiveString)
|
|
31
|
-
for (
|
|
32
|
-
|
|
27
|
+
.map(function (directiveString) { return directiveString.trim(); });
|
|
28
|
+
for (var _i = 0, directiveStrings_1 = directiveStrings; _i < directiveStrings_1.length; _i++) {
|
|
29
|
+
var directiveString = directiveStrings_1[_i];
|
|
30
|
+
var directive = this.getDirective(directiveString);
|
|
33
31
|
if (directive === undefined) {
|
|
34
32
|
continue; // No match for this directive.
|
|
35
33
|
}
|
|
36
|
-
|
|
34
|
+
var locale = directive.locale, languageCode = directive.languageCode, quality = directive.quality;
|
|
37
35
|
// If the language is not supported, skip to the next match.
|
|
38
36
|
if (!this.localeList.languages.has(languageCode)) {
|
|
39
37
|
continue;
|
|
@@ -59,71 +57,71 @@ class LookupList {
|
|
|
59
57
|
*
|
|
60
58
|
* @returns The top locale with the specified language.
|
|
61
59
|
*/
|
|
62
|
-
getTopByLanguage(languageCode) {
|
|
60
|
+
LookupList.prototype.getTopByLanguage = function (languageCode) {
|
|
63
61
|
var _a;
|
|
64
|
-
return (_a = this.localeList.objects.find((locale)
|
|
65
|
-
}
|
|
62
|
+
return (_a = this.localeList.objects.find(function (locale) { return locale.languageCode === languageCode; })) === null || _a === void 0 ? void 0 : _a.identifier;
|
|
63
|
+
};
|
|
66
64
|
/**
|
|
67
65
|
* Get the top (highest-ranked) locale or language.
|
|
68
66
|
*
|
|
69
67
|
* @returns The top match, which can either be a locale or a language.
|
|
70
68
|
*/
|
|
71
|
-
getTopLocaleOrLanguage() {
|
|
72
|
-
|
|
69
|
+
LookupList.prototype.getTopLocaleOrLanguage = function () {
|
|
70
|
+
var localesAndLanguagesByQuality = Object.entries(this.localesAndLanguagesByQuality);
|
|
73
71
|
if (localesAndLanguagesByQuality.length === 0) {
|
|
74
72
|
return undefined;
|
|
75
73
|
}
|
|
76
74
|
return this.getTop(localesAndLanguagesByQuality);
|
|
77
|
-
}
|
|
75
|
+
};
|
|
78
76
|
/**
|
|
79
77
|
* Get the top (highest-ranked) related locale.
|
|
80
78
|
*
|
|
81
79
|
* @returns The top related locale.
|
|
82
80
|
*/
|
|
83
|
-
getTopRelatedLocale() {
|
|
84
|
-
|
|
81
|
+
LookupList.prototype.getTopRelatedLocale = function () {
|
|
82
|
+
var relatedLocaleLanguagesByQuality = Object.entries(this.relatedLocaleLanguagesByQuality);
|
|
85
83
|
if (relatedLocaleLanguagesByQuality.length === 0) {
|
|
86
84
|
return undefined;
|
|
87
85
|
}
|
|
88
|
-
|
|
86
|
+
var topRelatedLocaleLanguage = this.getTop(relatedLocaleLanguagesByQuality);
|
|
89
87
|
return this.getTopByLanguage(topRelatedLocaleLanguage);
|
|
90
|
-
}
|
|
88
|
+
};
|
|
91
89
|
/**
|
|
92
90
|
* Add a language in the data object matching its quality.
|
|
93
91
|
*
|
|
94
92
|
* @param quality - The HTTP header's quality factor associated with a language.
|
|
95
93
|
* @param languageCode - An ISO 639-1 alpha-2 language code.
|
|
96
94
|
*/
|
|
97
|
-
addLanguage(quality, languageCode) {
|
|
95
|
+
LookupList.prototype.addLanguage = function (quality, languageCode) {
|
|
98
96
|
if (!this.localesAndLanguagesByQuality[quality]) {
|
|
99
97
|
this.localesAndLanguagesByQuality[quality] = new Set();
|
|
100
98
|
}
|
|
101
99
|
this.localesAndLanguagesByQuality[quality].add(languageCode);
|
|
102
|
-
}
|
|
100
|
+
};
|
|
103
101
|
/**
|
|
104
102
|
* Add a locale in the data object matching its quality.
|
|
105
103
|
*
|
|
106
104
|
* @param quality - The HTTP header's quality factor associated with a locale.
|
|
107
105
|
* @param identifier - A locale identifier using the BCP 47 `language`-`country` case-normalized format.
|
|
108
106
|
*/
|
|
109
|
-
addLocale(quality, identifier) {
|
|
107
|
+
LookupList.prototype.addLocale = function (quality, identifier) {
|
|
110
108
|
if (!this.localesAndLanguagesByQuality[quality]) {
|
|
111
109
|
this.localesAndLanguagesByQuality[quality] = new Set();
|
|
112
110
|
}
|
|
113
111
|
this.localesAndLanguagesByQuality[quality].add(identifier);
|
|
114
|
-
}
|
|
112
|
+
};
|
|
115
113
|
/**
|
|
116
114
|
* Add a related locale's language in the data object matching its quality.
|
|
117
115
|
*
|
|
118
116
|
* @param quality - The HTTP header's quality factor associated with a related locale's language.
|
|
119
117
|
* @param languageCode - An ISO 639-1 alpha-2 language code.
|
|
120
118
|
*/
|
|
121
|
-
addRelatedLocaleLanguage(quality, languageCode) {
|
|
119
|
+
LookupList.prototype.addRelatedLocaleLanguage = function (quality, languageCode) {
|
|
122
120
|
if (!this.relatedLocaleLanguagesByQuality[quality]) {
|
|
123
121
|
this.relatedLocaleLanguagesByQuality[quality] = new Set();
|
|
124
122
|
}
|
|
125
123
|
this.relatedLocaleLanguagesByQuality[quality].add(languageCode);
|
|
126
|
-
}
|
|
124
|
+
};
|
|
127
125
|
/**
|
|
128
126
|
* Get a directive object from a directive string.
|
|
129
127
|
*
|
|
@@ -131,7 +129,7 @@ class LookupList {
|
|
|
131
129
|
*
|
|
132
130
|
* @returns A `Directive` object or `undefined` if the string's format is invalid.
|
|
133
131
|
*/
|
|
134
|
-
getDirective(directiveString) {
|
|
132
|
+
LookupList.prototype.getDirective = function (directiveString) {
|
|
135
133
|
/**
|
|
136
134
|
* The regular expression is excluding certain directives due to the inability to configure those options in modern
|
|
137
135
|
* browsers today (also those options seem unpractical):
|
|
@@ -140,17 +138,17 @@ class LookupList {
|
|
|
140
138
|
* - Language tags that starts with a wildcard (e.g. "*-CA") should match the first supported locale of a country.
|
|
141
139
|
* - A quality value equivalent to "0", as per RFC 2616 (section 3.9), should be considered as "not acceptable".
|
|
142
140
|
*/
|
|
143
|
-
|
|
141
|
+
var directiveMatch = directiveString.match(/^((?<matchedLanguageCode>([a-z]{2}))(-(?<matchedCountryCode>[a-z]{2}))?)(;q=(?<matchedQuality>(1(\.0{0,3})?)|(0(\.\d{0,3})?)))?$/i);
|
|
144
142
|
if (!(directiveMatch === null || directiveMatch === void 0 ? void 0 : directiveMatch.groups)) {
|
|
145
143
|
return undefined; // No regular expression match.
|
|
146
144
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return { languageCode, locale, quality };
|
|
153
|
-
}
|
|
145
|
+
var _a = directiveMatch.groups, matchedLanguageCode = _a.matchedLanguageCode, matchedCountryCode = _a.matchedCountryCode, matchedQuality = _a.matchedQuality;
|
|
146
|
+
var languageCode = matchedLanguageCode.toLowerCase();
|
|
147
|
+
var countryCode = matchedCountryCode ? matchedCountryCode.toUpperCase() : undefined;
|
|
148
|
+
var quality = matchedQuality === undefined ? '1' : Number.parseFloat(matchedQuality).toString(); // Remove trailing zeros.
|
|
149
|
+
var locale = countryCode ? "".concat(languageCode, "-").concat(countryCode) : undefined;
|
|
150
|
+
return { languageCode: languageCode, locale: locale, quality: quality };
|
|
151
|
+
};
|
|
154
152
|
/**
|
|
155
153
|
* Get the top (highest-ranked) entry from a dataset object entries.
|
|
156
154
|
*
|
|
@@ -158,8 +156,9 @@ class LookupList {
|
|
|
158
156
|
*
|
|
159
157
|
* @returns The top entry from a dataset object entries.
|
|
160
158
|
*/
|
|
161
|
-
getTop(dataObjectEntries) {
|
|
159
|
+
LookupList.prototype.getTop = function (dataObjectEntries) {
|
|
162
160
|
return dataObjectEntries.sort().reverse()[0][1].values().next().value;
|
|
163
|
-
}
|
|
164
|
-
|
|
161
|
+
};
|
|
162
|
+
return LookupList;
|
|
163
|
+
}());
|
|
165
164
|
exports.default = LookupList;
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
4
10
|
};
|
|
5
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
12
|
exports.ResolveAcceptLanguage = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
var locale_1 = require("./locale");
|
|
14
|
+
var lookup_list_1 = require("./lookup-list");
|
|
9
15
|
/** Resolve the preferred locale from an HTTP `Accept-Language` header. */
|
|
10
|
-
|
|
16
|
+
var ResolveAcceptLanguage = /** @class */ (function () {
|
|
11
17
|
/**
|
|
12
18
|
* Create a new `ResolveAcceptLanguage` object.
|
|
13
19
|
*
|
|
@@ -17,9 +23,9 @@ class ResolveAcceptLanguage {
|
|
|
17
23
|
* @param locales - An array of locale identifiers. The order will be used for matching where the first identifier will be more
|
|
18
24
|
* likely to be matched than the last identifier.
|
|
19
25
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
function ResolveAcceptLanguage(acceptLanguageHeader, locales) {
|
|
27
|
+
var lookupList = new lookup_list_1.default(acceptLanguageHeader, locales);
|
|
28
|
+
var topLocaleOrLanguage = lookupList.getTopLocaleOrLanguage();
|
|
23
29
|
if (topLocaleOrLanguage === undefined) {
|
|
24
30
|
this.relatedLocaleBasedMatch = lookupList.getTopRelatedLocale();
|
|
25
31
|
}
|
|
@@ -37,51 +43,52 @@ class ResolveAcceptLanguage {
|
|
|
37
43
|
*
|
|
38
44
|
* @returns True if the best match language-based, otherwise false.
|
|
39
45
|
*/
|
|
40
|
-
bestMatchIsLanguageBased() {
|
|
46
|
+
ResolveAcceptLanguage.prototype.bestMatchIsLanguageBased = function () {
|
|
41
47
|
return this.languageBasedMatch !== undefined;
|
|
42
|
-
}
|
|
48
|
+
};
|
|
43
49
|
/**
|
|
44
50
|
* Is the best match locale-based?
|
|
45
51
|
*
|
|
46
52
|
* @returns True if the best match locale-based, otherwise false.
|
|
47
53
|
*/
|
|
48
|
-
bestMatchIsLocaleBased() {
|
|
54
|
+
ResolveAcceptLanguage.prototype.bestMatchIsLocaleBased = function () {
|
|
49
55
|
return this.localeBasedMatch !== undefined;
|
|
50
|
-
}
|
|
56
|
+
};
|
|
51
57
|
/**
|
|
52
58
|
* Is the best match related-locale-based?
|
|
53
59
|
*
|
|
54
60
|
* @returns True if the best match related-locale-based, otherwise false.
|
|
55
61
|
*/
|
|
56
|
-
bestMatchIsRelatedLocaleBased() {
|
|
62
|
+
ResolveAcceptLanguage.prototype.bestMatchIsRelatedLocaleBased = function () {
|
|
57
63
|
return this.relatedLocaleBasedMatch !== undefined;
|
|
58
|
-
}
|
|
64
|
+
};
|
|
59
65
|
/**
|
|
60
66
|
* Get the locale which was the best match.
|
|
61
67
|
*
|
|
62
68
|
* @returns The locale which was the best match.
|
|
63
69
|
*/
|
|
64
|
-
getBestMatch() {
|
|
70
|
+
ResolveAcceptLanguage.prototype.getBestMatch = function () {
|
|
65
71
|
var _a, _b;
|
|
66
72
|
return (_b = (_a = this.localeBasedMatch) !== null && _a !== void 0 ? _a : this.languageBasedMatch) !== null && _b !== void 0 ? _b : this.relatedLocaleBasedMatch;
|
|
67
|
-
}
|
|
73
|
+
};
|
|
68
74
|
/**
|
|
69
75
|
* Was a match found when resolving the preferred locale?
|
|
70
76
|
*
|
|
71
77
|
* @returns True when a match is found, otherwise false.
|
|
72
78
|
*/
|
|
73
|
-
hasMatch() {
|
|
79
|
+
ResolveAcceptLanguage.prototype.hasMatch = function () {
|
|
74
80
|
return this.getBestMatch() === undefined ? false : true;
|
|
75
|
-
}
|
|
81
|
+
};
|
|
76
82
|
/**
|
|
77
83
|
* Did the resolution of the preferred locale find no match?
|
|
78
84
|
*
|
|
79
85
|
* @returns True when there is no match, otherwise false.
|
|
80
86
|
*/
|
|
81
|
-
hasNoMatch() {
|
|
87
|
+
ResolveAcceptLanguage.prototype.hasNoMatch = function () {
|
|
82
88
|
return !this.hasMatch();
|
|
83
|
-
}
|
|
84
|
-
|
|
89
|
+
};
|
|
90
|
+
return ResolveAcceptLanguage;
|
|
91
|
+
}());
|
|
85
92
|
exports.ResolveAcceptLanguage = ResolveAcceptLanguage;
|
|
86
93
|
/**
|
|
87
94
|
* Resolve the preferred locale from an HTTP `Accept-Language` header.
|
|
@@ -103,24 +110,24 @@ exports.ResolveAcceptLanguage = ResolveAcceptLanguage;
|
|
|
103
110
|
* 'en-US'
|
|
104
111
|
* )
|
|
105
112
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
locales.forEach((locale)
|
|
113
|
+
var resolveAcceptLanguage = function (acceptLanguageHeader, locales, defaultLocale) {
|
|
114
|
+
var localesIncludeDefault = false;
|
|
115
|
+
locales.forEach(function (locale) {
|
|
109
116
|
if (!locale_1.default.isLocale(locale, false)) {
|
|
110
|
-
throw new Error(
|
|
117
|
+
throw new Error("invalid locale identifier '".concat(locale, "'"));
|
|
111
118
|
}
|
|
112
119
|
if (locale.toLowerCase() === defaultLocale.toLocaleLowerCase()) {
|
|
113
120
|
localesIncludeDefault = true;
|
|
114
121
|
}
|
|
115
122
|
});
|
|
116
123
|
if (!locale_1.default.isLocale(defaultLocale, false)) {
|
|
117
|
-
throw new Error(
|
|
124
|
+
throw new Error("invalid default locale identifier '".concat(defaultLocale, "'"));
|
|
118
125
|
}
|
|
119
126
|
if (!localesIncludeDefault) {
|
|
120
127
|
throw new Error('the default locale must be included in the locales');
|
|
121
128
|
}
|
|
122
|
-
|
|
123
|
-
|
|
129
|
+
var rankedLocales = __spreadArray([defaultLocale], locales.filter(function (locale) { return locale !== defaultLocale; }), true);
|
|
130
|
+
var resolveAcceptLanguage = new ResolveAcceptLanguage(acceptLanguageHeader, rankedLocales);
|
|
124
131
|
if (resolveAcceptLanguage.hasMatch()) {
|
|
125
132
|
return resolveAcceptLanguage.getBestMatch();
|
|
126
133
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "resolve-accept-language",
|
|
3
|
-
"version": "1.1.45
|
|
3
|
+
"version": "1.1.45",
|
|
4
4
|
"description": "Resolve the preferred locale based on the value of an `Accept-Language` HTTP header.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"accept-language",
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"author": "Avansai (https://avansai.com)",
|
|
25
|
-
"type": "module",
|
|
26
25
|
"main": "lib/resolve-accept-language.js",
|
|
27
26
|
"types": "lib/resolve-accept-language.d.ts",
|
|
28
27
|
"files": [
|
|
@@ -33,7 +32,6 @@
|
|
|
33
32
|
"lint-check": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx --ext .json .",
|
|
34
33
|
"lint-fix": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx --ext .json --fix .",
|
|
35
34
|
"lint-print-config": "eslint --print-config ./eslintrc.yaml",
|
|
36
|
-
"pre-release": "dotenv -- release-it --only-version --preRelease",
|
|
37
35
|
"prettier": "prettier --write .",
|
|
38
36
|
"release": "dotenv -- release-it --only-version",
|
|
39
37
|
"test": "jest --coverage"
|
|
@@ -41,8 +39,8 @@
|
|
|
41
39
|
"devDependencies": {
|
|
42
40
|
"@release-it/conventional-changelog": "^5.1.1",
|
|
43
41
|
"@types/jest": "^29.4.0",
|
|
44
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
45
|
-
"@typescript-eslint/parser": "^5.
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
|
43
|
+
"@typescript-eslint/parser": "^5.54.0",
|
|
46
44
|
"dotenv-cli": "^7.0.0",
|
|
47
45
|
"eslint": "^8.35.0",
|
|
48
46
|
"eslint-config-prettier": "^8.6.0",
|
|
@@ -54,12 +52,12 @@
|
|
|
54
52
|
"eslint-plugin-prefer-arrow-functions": "^3.1.4",
|
|
55
53
|
"eslint-plugin-prettier": "^4.2.1",
|
|
56
54
|
"eslint-plugin-tsdoc": "^0.2.17",
|
|
57
|
-
"eslint-plugin-unicorn": "^
|
|
55
|
+
"eslint-plugin-unicorn": "^46.0.0",
|
|
58
56
|
"jest": "^29.4.3",
|
|
59
57
|
"prettier": "^2.8.4",
|
|
60
58
|
"prettier-plugin-organize-imports": "^3.2.2",
|
|
61
59
|
"prettier-plugin-sh": "^0.12.8",
|
|
62
|
-
"release-it": "^15.
|
|
60
|
+
"release-it": "^15.7.0",
|
|
63
61
|
"ts-jest": "^29.0.5",
|
|
64
62
|
"ts-node": "^10.9.1",
|
|
65
63
|
"typescript": "^4.9.5"
|