@@ -24,17 +24,17 @@ export class AcceptLanguage implements HeaderValue, Iterable<[string, number]> {
24
24
if ( params . length < 1 ) continue ;
25
25
26
26
let language = params [ 0 ] [ 0 ] ;
27
- let quality = 1 ;
27
+ let weight = 1 ;
28
28
29
29
for ( let i = 1 ; i < params . length ; i ++ ) {
30
30
let [ key , value ] = params [ i ] ;
31
31
if ( key === 'q' ) {
32
- quality = Number ( value ) ;
32
+ weight = Number ( value ) ;
33
33
break ;
34
34
}
35
35
}
36
36
37
- this . #map. set ( language . toLowerCase ( ) , quality ) ;
37
+ this . #map. set ( language . toLowerCase ( ) , weight ) ;
38
38
}
39
39
} else if ( isIterable ( init ) ) {
40
40
for ( let value of init ) {
@@ -66,9 +66,9 @@ export class AcceptLanguage implements HeaderValue, Iterable<[string, number]> {
66
66
}
67
67
68
68
/**
69
- * An array of all quality values in the header.
69
+ * An array of all weight values in the header.
70
70
*/
71
- get qualities ( ) : number [ ] {
71
+ get weights ( ) : number [ ] {
72
72
return Array . from ( this . #map. values ( ) ) ;
73
73
}
74
74
@@ -78,16 +78,16 @@ export class AcceptLanguage implements HeaderValue, Iterable<[string, number]> {
78
78
* @returns `true` if the language is acceptable, `false` otherwise.
79
79
*/
80
80
accepts ( language : string ) : boolean {
81
- return this . getQuality ( language ) > 0 ;
81
+ return this . getWeight ( language ) > 0 ;
82
82
}
83
83
84
84
/**
85
- * Gets the quality of a language with the given locale identifier. Performs wildcard and subtype
85
+ * Gets the weight of a language with the given locale identifier. Performs wildcard and subtype
86
86
* matching, so `en` matches `en-US` and `en-GB`, and `*` matches all languages.
87
87
* @param language The locale identifier of the language to get.
88
- * @returns The quality of the language, or `0` if it is not in the header.
88
+ * @returns The weight of the language, or `0` if it is not in the header.
89
89
*/
90
- getQuality ( language : string ) : number {
90
+ getWeight ( language : string ) : number {
91
91
let [ base , subtype ] = language . toLowerCase ( ) . split ( '-' ) ;
92
92
93
93
for ( let [ key , value ] of this ) {
@@ -110,7 +110,7 @@ export class AcceptLanguage implements HeaderValue, Iterable<[string, number]> {
110
110
*/
111
111
getPreferred ( languages : string [ ] ) : string | null {
112
112
let sorted = languages
113
- . map ( ( language ) => [ language , this . getQuality ( language ) ] as const )
113
+ . map ( ( language ) => [ language , this . getWeight ( language ) ] as const )
114
114
. sort ( ( a , b ) => b [ 1 ] - a [ 1 ] ) ;
115
115
116
116
let first = sorted [ 0 ] ;
@@ -119,22 +119,22 @@ export class AcceptLanguage implements HeaderValue, Iterable<[string, number]> {
119
119
}
120
120
121
121
/**
122
- * Gets the quality of a language with the given locale identifier. If it is not in the header
122
+ * Gets the weight of a language with the given locale identifier. If it is not in the header
123
123
* verbatim, this returns `null`.
124
124
* @param language The locale identifier of the language to get.
125
- * @returns The quality of the language, or `null` if it is not in the header.
125
+ * @returns The weight of the language, or `null` if it is not in the header.
126
126
*/
127
127
get ( language : string ) : number | null {
128
128
return this . #map. get ( language . toLowerCase ( ) ) ?? null ;
129
129
}
130
130
131
131
/**
132
- * Sets a language with the given quality .
132
+ * Sets a language with the given weight .
133
133
* @param language The locale identifier of the language to set.
134
- * @param quality The quality of the language. Defaults to 1.
134
+ * @param weight The weight of the language. Defaults to 1.
135
135
*/
136
- set ( language : string , quality = 1 ) : void {
137
- this . #map. set ( language . toLowerCase ( ) , quality ) ;
136
+ set ( language : string , weight = 1 ) : void {
137
+ this . #map. set ( language . toLowerCase ( ) , weight ) ;
138
138
this . #sort( ) ;
139
139
}
140
140
@@ -171,11 +171,11 @@ export class AcceptLanguage implements HeaderValue, Iterable<[string, number]> {
171
171
}
172
172
173
173
forEach (
174
- callback : ( language : string , quality : number , header : AcceptLanguage ) => void ,
174
+ callback : ( language : string , weight : number , header : AcceptLanguage ) => void ,
175
175
thisArg ?: any ,
176
176
) : void {
177
- for ( let [ language , quality ] of this ) {
178
- callback . call ( thisArg , language , quality , this ) ;
177
+ for ( let [ language , weight ] of this ) {
178
+ callback . call ( thisArg , language , weight , this ) ;
179
179
}
180
180
}
181
181
@@ -189,8 +189,8 @@ export class AcceptLanguage implements HeaderValue, Iterable<[string, number]> {
189
189
toString ( ) : string {
190
190
let pairs : string [ ] = [ ] ;
191
191
192
- for ( let [ language , quality ] of this . #map) {
193
- pairs . push ( `${ language } ${ quality === 1 ? '' : `;q=${ quality } ` } ` ) ;
192
+ for ( let [ language , weight ] of this . #map) {
193
+ pairs . push ( `${ language } ${ weight === 1 ? '' : `;q=${ weight } ` } ` ) ;
194
194
}
195
195
196
196
return pairs . join ( ',' ) ;
0 commit comments