node-red-contrib-web-worldmap 5.0.4 → 5.0.6
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/CHANGELOG.md +1 -0
- package/README.md +1 -0
- package/node_modules/accepts/node_modules/negotiator/HISTORY.md +108 -0
- package/node_modules/{body-parser/node_modules/bytes → accepts/node_modules/negotiator}/LICENSE +3 -2
- package/node_modules/accepts/node_modules/negotiator/README.md +203 -0
- package/node_modules/accepts/node_modules/negotiator/index.js +82 -0
- package/node_modules/accepts/node_modules/negotiator/lib/charset.js +169 -0
- package/node_modules/accepts/node_modules/negotiator/lib/encoding.js +184 -0
- package/node_modules/accepts/node_modules/negotiator/lib/language.js +179 -0
- package/node_modules/accepts/node_modules/negotiator/lib/mediaType.js +294 -0
- package/node_modules/accepts/node_modules/negotiator/package.json +42 -0
- package/node_modules/bytes/History.md +15 -0
- package/node_modules/bytes/Readme.md +45 -18
- package/node_modules/bytes/index.js +15 -4
- package/node_modules/bytes/package.json +7 -4
- package/node_modules/compression/HISTORY.md +15 -0
- package/node_modules/compression/README.md +4 -6
- package/node_modules/compression/index.js +3 -8
- package/node_modules/compression/package.json +19 -19
- package/node_modules/negotiator/HISTORY.md +5 -0
- package/node_modules/negotiator/README.md +9 -0
- package/node_modules/negotiator/index.js +4 -4
- package/node_modules/negotiator/lib/encoding.js +26 -5
- package/node_modules/negotiator/lib/mediaType.js +3 -3
- package/node_modules/negotiator/package.json +1 -1
- package/node_modules/object-inspect/CHANGELOG.md +12 -0
- package/node_modules/object-inspect/index.js +17 -3
- package/node_modules/object-inspect/package.json +6 -6
- package/node_modules/object-inspect/test/quoteStyle.js +9 -0
- package/node_modules/safe-buffer/index.js +3 -0
- package/node_modules/safe-buffer/package.json +18 -4
- package/node_modules/tslib/modules/index.d.ts +1 -0
- package/node_modules/tslib/modules/index.js +2 -0
- package/node_modules/tslib/package.json +1 -1
- package/node_modules/tslib/tslib.d.ts +7 -0
- package/node_modules/tslib/tslib.es6.js +24 -1
- package/node_modules/tslib/tslib.es6.mjs +24 -1
- package/node_modules/tslib/tslib.js +56 -1
- package/package.json +2 -2
- package/worldmap/worldmap.js +4 -1
- package/worldmap.js +2 -2
- package/node_modules/body-parser/node_modules/bytes/History.md +0 -97
- package/node_modules/body-parser/node_modules/bytes/Readme.md +0 -152
- package/node_modules/body-parser/node_modules/bytes/index.js +0 -170
- package/node_modules/body-parser/node_modules/bytes/package.json +0 -42
- package/node_modules/content-disposition/node_modules/safe-buffer/LICENSE +0 -21
- package/node_modules/content-disposition/node_modules/safe-buffer/README.md +0 -584
- package/node_modules/content-disposition/node_modules/safe-buffer/index.d.ts +0 -187
- package/node_modules/content-disposition/node_modules/safe-buffer/index.js +0 -65
- package/node_modules/content-disposition/node_modules/safe-buffer/package.json +0 -51
- package/node_modules/express/node_modules/safe-buffer/LICENSE +0 -21
- package/node_modules/express/node_modules/safe-buffer/README.md +0 -584
- package/node_modules/express/node_modules/safe-buffer/index.d.ts +0 -187
- package/node_modules/express/node_modules/safe-buffer/index.js +0 -65
- package/node_modules/express/node_modules/safe-buffer/package.json +0 -51
- package/node_modules/raw-body/node_modules/bytes/History.md +0 -97
- package/node_modules/raw-body/node_modules/bytes/LICENSE +0 -23
- package/node_modules/raw-body/node_modules/bytes/Readme.md +0 -152
- package/node_modules/raw-body/node_modules/bytes/index.js +0 -170
- package/node_modules/raw-body/node_modules/bytes/package.json +0 -42
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
### Change Log for Node-RED Worldmap
|
|
2
2
|
|
|
3
|
+
- v5.0.6 - Tweak SIDC flag handling slightly to show direction if available and moving.
|
|
3
4
|
- v5.0.4 - Tweak CoT handling slightly.
|
|
4
5
|
- v5.0.3 - Add great context menu example flow. PR#290. Bump express lib. PR#291.
|
|
5
6
|
- v5.0.2 - Fix sidcEdgeIcon docs PR#289.
|
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ Feel free to [
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2012-2014
|
|
4
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2012-2014 Federico Romero
|
|
4
|
+
Copyright (c) 2012-2014 Isaac Z. Schlueter
|
|
5
|
+
Copyright (c) 2014-2015 Douglas Christopher Wilson
|
|
5
6
|
|
|
6
7
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
7
8
|
a copy of this software and associated documentation files (the
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# negotiator
|
|
2
|
+
|
|
3
|
+
[![NPM Version][npm-image]][npm-url]
|
|
4
|
+
[![NPM Downloads][downloads-image]][downloads-url]
|
|
5
|
+
[![Node.js Version][node-version-image]][node-version-url]
|
|
6
|
+
[![Build Status][github-actions-ci-image]][github-actions-ci-url]
|
|
7
|
+
[![Test Coverage][coveralls-image]][coveralls-url]
|
|
8
|
+
|
|
9
|
+
An HTTP content negotiator for Node.js
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
$ npm install negotiator
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## API
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
var Negotiator = require('negotiator')
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Accept Negotiation
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
availableMediaTypes = ['text/html', 'text/plain', 'application/json']
|
|
27
|
+
|
|
28
|
+
// The negotiator constructor receives a request object
|
|
29
|
+
negotiator = new Negotiator(request)
|
|
30
|
+
|
|
31
|
+
// Let's say Accept header is 'text/html, application/*;q=0.2, image/jpeg;q=0.8'
|
|
32
|
+
|
|
33
|
+
negotiator.mediaTypes()
|
|
34
|
+
// -> ['text/html', 'image/jpeg', 'application/*']
|
|
35
|
+
|
|
36
|
+
negotiator.mediaTypes(availableMediaTypes)
|
|
37
|
+
// -> ['text/html', 'application/json']
|
|
38
|
+
|
|
39
|
+
negotiator.mediaType(availableMediaTypes)
|
|
40
|
+
// -> 'text/html'
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
You can check a working example at `examples/accept.js`.
|
|
44
|
+
|
|
45
|
+
#### Methods
|
|
46
|
+
|
|
47
|
+
##### mediaType()
|
|
48
|
+
|
|
49
|
+
Returns the most preferred media type from the client.
|
|
50
|
+
|
|
51
|
+
##### mediaType(availableMediaType)
|
|
52
|
+
|
|
53
|
+
Returns the most preferred media type from a list of available media types.
|
|
54
|
+
|
|
55
|
+
##### mediaTypes()
|
|
56
|
+
|
|
57
|
+
Returns an array of preferred media types ordered by the client preference.
|
|
58
|
+
|
|
59
|
+
##### mediaTypes(availableMediaTypes)
|
|
60
|
+
|
|
61
|
+
Returns an array of preferred media types ordered by priority from a list of
|
|
62
|
+
available media types.
|
|
63
|
+
|
|
64
|
+
### Accept-Language Negotiation
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
negotiator = new Negotiator(request)
|
|
68
|
+
|
|
69
|
+
availableLanguages = ['en', 'es', 'fr']
|
|
70
|
+
|
|
71
|
+
// Let's say Accept-Language header is 'en;q=0.8, es, pt'
|
|
72
|
+
|
|
73
|
+
negotiator.languages()
|
|
74
|
+
// -> ['es', 'pt', 'en']
|
|
75
|
+
|
|
76
|
+
negotiator.languages(availableLanguages)
|
|
77
|
+
// -> ['es', 'en']
|
|
78
|
+
|
|
79
|
+
language = negotiator.language(availableLanguages)
|
|
80
|
+
// -> 'es'
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
You can check a working example at `examples/language.js`.
|
|
84
|
+
|
|
85
|
+
#### Methods
|
|
86
|
+
|
|
87
|
+
##### language()
|
|
88
|
+
|
|
89
|
+
Returns the most preferred language from the client.
|
|
90
|
+
|
|
91
|
+
##### language(availableLanguages)
|
|
92
|
+
|
|
93
|
+
Returns the most preferred language from a list of available languages.
|
|
94
|
+
|
|
95
|
+
##### languages()
|
|
96
|
+
|
|
97
|
+
Returns an array of preferred languages ordered by the client preference.
|
|
98
|
+
|
|
99
|
+
##### languages(availableLanguages)
|
|
100
|
+
|
|
101
|
+
Returns an array of preferred languages ordered by priority from a list of
|
|
102
|
+
available languages.
|
|
103
|
+
|
|
104
|
+
### Accept-Charset Negotiation
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
availableCharsets = ['utf-8', 'iso-8859-1', 'iso-8859-5']
|
|
108
|
+
|
|
109
|
+
negotiator = new Negotiator(request)
|
|
110
|
+
|
|
111
|
+
// Let's say Accept-Charset header is 'utf-8, iso-8859-1;q=0.8, utf-7;q=0.2'
|
|
112
|
+
|
|
113
|
+
negotiator.charsets()
|
|
114
|
+
// -> ['utf-8', 'iso-8859-1', 'utf-7']
|
|
115
|
+
|
|
116
|
+
negotiator.charsets(availableCharsets)
|
|
117
|
+
// -> ['utf-8', 'iso-8859-1']
|
|
118
|
+
|
|
119
|
+
negotiator.charset(availableCharsets)
|
|
120
|
+
// -> 'utf-8'
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
You can check a working example at `examples/charset.js`.
|
|
124
|
+
|
|
125
|
+
#### Methods
|
|
126
|
+
|
|
127
|
+
##### charset()
|
|
128
|
+
|
|
129
|
+
Returns the most preferred charset from the client.
|
|
130
|
+
|
|
131
|
+
##### charset(availableCharsets)
|
|
132
|
+
|
|
133
|
+
Returns the most preferred charset from a list of available charsets.
|
|
134
|
+
|
|
135
|
+
##### charsets()
|
|
136
|
+
|
|
137
|
+
Returns an array of preferred charsets ordered by the client preference.
|
|
138
|
+
|
|
139
|
+
##### charsets(availableCharsets)
|
|
140
|
+
|
|
141
|
+
Returns an array of preferred charsets ordered by priority from a list of
|
|
142
|
+
available charsets.
|
|
143
|
+
|
|
144
|
+
### Accept-Encoding Negotiation
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
availableEncodings = ['identity', 'gzip']
|
|
148
|
+
|
|
149
|
+
negotiator = new Negotiator(request)
|
|
150
|
+
|
|
151
|
+
// Let's say Accept-Encoding header is 'gzip, compress;q=0.2, identity;q=0.5'
|
|
152
|
+
|
|
153
|
+
negotiator.encodings()
|
|
154
|
+
// -> ['gzip', 'identity', 'compress']
|
|
155
|
+
|
|
156
|
+
negotiator.encodings(availableEncodings)
|
|
157
|
+
// -> ['gzip', 'identity']
|
|
158
|
+
|
|
159
|
+
negotiator.encoding(availableEncodings)
|
|
160
|
+
// -> 'gzip'
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
You can check a working example at `examples/encoding.js`.
|
|
164
|
+
|
|
165
|
+
#### Methods
|
|
166
|
+
|
|
167
|
+
##### encoding()
|
|
168
|
+
|
|
169
|
+
Returns the most preferred encoding from the client.
|
|
170
|
+
|
|
171
|
+
##### encoding(availableEncodings)
|
|
172
|
+
|
|
173
|
+
Returns the most preferred encoding from a list of available encodings.
|
|
174
|
+
|
|
175
|
+
##### encodings()
|
|
176
|
+
|
|
177
|
+
Returns an array of preferred encodings ordered by the client preference.
|
|
178
|
+
|
|
179
|
+
##### encodings(availableEncodings)
|
|
180
|
+
|
|
181
|
+
Returns an array of preferred encodings ordered by priority from a list of
|
|
182
|
+
available encodings.
|
|
183
|
+
|
|
184
|
+
## See Also
|
|
185
|
+
|
|
186
|
+
The [accepts](https://npmjs.org/package/accepts#readme) module builds on
|
|
187
|
+
this module and provides an alternative interface, mime type validation,
|
|
188
|
+
and more.
|
|
189
|
+
|
|
190
|
+
## License
|
|
191
|
+
|
|
192
|
+
[MIT](LICENSE)
|
|
193
|
+
|
|
194
|
+
[npm-image]: https://img.shields.io/npm/v/negotiator.svg
|
|
195
|
+
[npm-url]: https://npmjs.org/package/negotiator
|
|
196
|
+
[node-version-image]: https://img.shields.io/node/v/negotiator.svg
|
|
197
|
+
[node-version-url]: https://nodejs.org/en/download/
|
|
198
|
+
[coveralls-image]: https://img.shields.io/coveralls/jshttp/negotiator/master.svg
|
|
199
|
+
[coveralls-url]: https://coveralls.io/r/jshttp/negotiator?branch=master
|
|
200
|
+
[downloads-image]: https://img.shields.io/npm/dm/negotiator.svg
|
|
201
|
+
[downloads-url]: https://npmjs.org/package/negotiator
|
|
202
|
+
[github-actions-ci-image]: https://img.shields.io/github/workflow/status/jshttp/negotiator/ci/master?label=ci
|
|
203
|
+
[github-actions-ci-url]: https://github.com/jshttp/negotiator/actions/workflows/ci.yml
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* negotiator
|
|
3
|
+
* Copyright(c) 2012 Federico Romero
|
|
4
|
+
* Copyright(c) 2012-2014 Isaac Z. Schlueter
|
|
5
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
6
|
+
* MIT Licensed
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
var preferredCharsets = require('./lib/charset')
|
|
12
|
+
var preferredEncodings = require('./lib/encoding')
|
|
13
|
+
var preferredLanguages = require('./lib/language')
|
|
14
|
+
var preferredMediaTypes = require('./lib/mediaType')
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Module exports.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
module.exports = Negotiator;
|
|
22
|
+
module.exports.Negotiator = Negotiator;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Create a Negotiator instance from a request.
|
|
26
|
+
* @param {object} request
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
function Negotiator(request) {
|
|
31
|
+
if (!(this instanceof Negotiator)) {
|
|
32
|
+
return new Negotiator(request);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
this.request = request;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
Negotiator.prototype.charset = function charset(available) {
|
|
39
|
+
var set = this.charsets(available);
|
|
40
|
+
return set && set[0];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
Negotiator.prototype.charsets = function charsets(available) {
|
|
44
|
+
return preferredCharsets(this.request.headers['accept-charset'], available);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
Negotiator.prototype.encoding = function encoding(available) {
|
|
48
|
+
var set = this.encodings(available);
|
|
49
|
+
return set && set[0];
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
Negotiator.prototype.encodings = function encodings(available) {
|
|
53
|
+
return preferredEncodings(this.request.headers['accept-encoding'], available);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
Negotiator.prototype.language = function language(available) {
|
|
57
|
+
var set = this.languages(available);
|
|
58
|
+
return set && set[0];
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
Negotiator.prototype.languages = function languages(available) {
|
|
62
|
+
return preferredLanguages(this.request.headers['accept-language'], available);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
Negotiator.prototype.mediaType = function mediaType(available) {
|
|
66
|
+
var set = this.mediaTypes(available);
|
|
67
|
+
return set && set[0];
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
Negotiator.prototype.mediaTypes = function mediaTypes(available) {
|
|
71
|
+
return preferredMediaTypes(this.request.headers.accept, available);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// Backwards compatibility
|
|
75
|
+
Negotiator.prototype.preferredCharset = Negotiator.prototype.charset;
|
|
76
|
+
Negotiator.prototype.preferredCharsets = Negotiator.prototype.charsets;
|
|
77
|
+
Negotiator.prototype.preferredEncoding = Negotiator.prototype.encoding;
|
|
78
|
+
Negotiator.prototype.preferredEncodings = Negotiator.prototype.encodings;
|
|
79
|
+
Negotiator.prototype.preferredLanguage = Negotiator.prototype.language;
|
|
80
|
+
Negotiator.prototype.preferredLanguages = Negotiator.prototype.languages;
|
|
81
|
+
Negotiator.prototype.preferredMediaType = Negotiator.prototype.mediaType;
|
|
82
|
+
Negotiator.prototype.preferredMediaTypes = Negotiator.prototype.mediaTypes;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* negotiator
|
|
3
|
+
* Copyright(c) 2012 Isaac Z. Schlueter
|
|
4
|
+
* Copyright(c) 2014 Federico Romero
|
|
5
|
+
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
|
6
|
+
* MIT Licensed
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Module exports.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
module.exports = preferredCharsets;
|
|
17
|
+
module.exports.preferredCharsets = preferredCharsets;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Module variables.
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
var simpleCharsetRegExp = /^\s*([^\s;]+)\s*(?:;(.*))?$/;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Parse the Accept-Charset header.
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
function parseAcceptCharset(accept) {
|
|
32
|
+
var accepts = accept.split(',');
|
|
33
|
+
|
|
34
|
+
for (var i = 0, j = 0; i < accepts.length; i++) {
|
|
35
|
+
var charset = parseCharset(accepts[i].trim(), i);
|
|
36
|
+
|
|
37
|
+
if (charset) {
|
|
38
|
+
accepts[j++] = charset;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// trim accepts
|
|
43
|
+
accepts.length = j;
|
|
44
|
+
|
|
45
|
+
return accepts;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Parse a charset from the Accept-Charset header.
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
function parseCharset(str, i) {
|
|
54
|
+
var match = simpleCharsetRegExp.exec(str);
|
|
55
|
+
if (!match) return null;
|
|
56
|
+
|
|
57
|
+
var charset = match[1];
|
|
58
|
+
var q = 1;
|
|
59
|
+
if (match[2]) {
|
|
60
|
+
var params = match[2].split(';')
|
|
61
|
+
for (var j = 0; j < params.length; j++) {
|
|
62
|
+
var p = params[j].trim().split('=');
|
|
63
|
+
if (p[0] === 'q') {
|
|
64
|
+
q = parseFloat(p[1]);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
charset: charset,
|
|
72
|
+
q: q,
|
|
73
|
+
i: i
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Get the priority of a charset.
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
function getCharsetPriority(charset, accepted, index) {
|
|
83
|
+
var priority = {o: -1, q: 0, s: 0};
|
|
84
|
+
|
|
85
|
+
for (var i = 0; i < accepted.length; i++) {
|
|
86
|
+
var spec = specify(charset, accepted[i], index);
|
|
87
|
+
|
|
88
|
+
if (spec && (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0) {
|
|
89
|
+
priority = spec;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return priority;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Get the specificity of the charset.
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
function specify(charset, spec, index) {
|
|
102
|
+
var s = 0;
|
|
103
|
+
if(spec.charset.toLowerCase() === charset.toLowerCase()){
|
|
104
|
+
s |= 1;
|
|
105
|
+
} else if (spec.charset !== '*' ) {
|
|
106
|
+
return null
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
i: index,
|
|
111
|
+
o: spec.i,
|
|
112
|
+
q: spec.q,
|
|
113
|
+
s: s
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Get the preferred charsets from an Accept-Charset header.
|
|
119
|
+
* @public
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
function preferredCharsets(accept, provided) {
|
|
123
|
+
// RFC 2616 sec 14.2: no header = *
|
|
124
|
+
var accepts = parseAcceptCharset(accept === undefined ? '*' : accept || '');
|
|
125
|
+
|
|
126
|
+
if (!provided) {
|
|
127
|
+
// sorted list of all charsets
|
|
128
|
+
return accepts
|
|
129
|
+
.filter(isQuality)
|
|
130
|
+
.sort(compareSpecs)
|
|
131
|
+
.map(getFullCharset);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
var priorities = provided.map(function getPriority(type, index) {
|
|
135
|
+
return getCharsetPriority(type, accepts, index);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// sorted list of accepted charsets
|
|
139
|
+
return priorities.filter(isQuality).sort(compareSpecs).map(function getCharset(priority) {
|
|
140
|
+
return provided[priorities.indexOf(priority)];
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Compare two specs.
|
|
146
|
+
* @private
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
function compareSpecs(a, b) {
|
|
150
|
+
return (b.q - a.q) || (b.s - a.s) || (a.o - b.o) || (a.i - b.i) || 0;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Get full charset string.
|
|
155
|
+
* @private
|
|
156
|
+
*/
|
|
157
|
+
|
|
158
|
+
function getFullCharset(spec) {
|
|
159
|
+
return spec.charset;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Check if a spec has any quality.
|
|
164
|
+
* @private
|
|
165
|
+
*/
|
|
166
|
+
|
|
167
|
+
function isQuality(spec) {
|
|
168
|
+
return spec.q > 0;
|
|
169
|
+
}
|