node-red-contrib-web-worldmap 5.0.5 → 5.0.7

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/README.md +3 -1
  3. package/examples/Custom Tooltip.json +83 -0
  4. package/node_modules/accepts/node_modules/negotiator/HISTORY.md +108 -0
  5. package/node_modules/{body-parser/node_modules/bytes → accepts/node_modules/negotiator}/LICENSE +3 -2
  6. package/node_modules/accepts/node_modules/negotiator/README.md +203 -0
  7. package/node_modules/accepts/node_modules/negotiator/index.js +82 -0
  8. package/node_modules/accepts/node_modules/negotiator/lib/charset.js +169 -0
  9. package/node_modules/accepts/node_modules/negotiator/lib/encoding.js +184 -0
  10. package/node_modules/accepts/node_modules/negotiator/lib/language.js +179 -0
  11. package/node_modules/accepts/node_modules/negotiator/lib/mediaType.js +294 -0
  12. package/node_modules/accepts/node_modules/negotiator/package.json +42 -0
  13. package/node_modules/bytes/History.md +15 -0
  14. package/node_modules/bytes/Readme.md +45 -18
  15. package/node_modules/bytes/index.js +15 -4
  16. package/node_modules/bytes/package.json +7 -4
  17. package/node_modules/compression/HISTORY.md +15 -0
  18. package/node_modules/compression/README.md +4 -6
  19. package/node_modules/compression/index.js +3 -8
  20. package/node_modules/compression/package.json +19 -19
  21. package/node_modules/negotiator/HISTORY.md +5 -0
  22. package/node_modules/negotiator/README.md +9 -0
  23. package/node_modules/negotiator/index.js +4 -4
  24. package/node_modules/negotiator/lib/encoding.js +26 -5
  25. package/node_modules/negotiator/lib/mediaType.js +3 -3
  26. package/node_modules/negotiator/package.json +1 -1
  27. package/node_modules/object-inspect/CHANGELOG.md +12 -0
  28. package/node_modules/object-inspect/index.js +17 -3
  29. package/node_modules/object-inspect/package.json +6 -6
  30. package/node_modules/object-inspect/test/quoteStyle.js +9 -0
  31. package/node_modules/safe-buffer/index.js +3 -0
  32. package/node_modules/safe-buffer/package.json +18 -4
  33. package/node_modules/tslib/modules/index.d.ts +1 -0
  34. package/node_modules/tslib/modules/index.js +2 -0
  35. package/node_modules/tslib/package.json +1 -1
  36. package/node_modules/tslib/tslib.d.ts +7 -0
  37. package/node_modules/tslib/tslib.es6.js +24 -1
  38. package/node_modules/tslib/tslib.es6.mjs +24 -1
  39. package/node_modules/tslib/tslib.js +56 -1
  40. package/package.json +1 -1
  41. package/worldmap/worldmap.js +7 -4
  42. package/worldmap.js +2 -2
  43. package/node_modules/body-parser/node_modules/bytes/History.md +0 -97
  44. package/node_modules/body-parser/node_modules/bytes/Readme.md +0 -152
  45. package/node_modules/body-parser/node_modules/bytes/index.js +0 -170
  46. package/node_modules/body-parser/node_modules/bytes/package.json +0 -42
  47. package/node_modules/content-disposition/node_modules/safe-buffer/LICENSE +0 -21
  48. package/node_modules/content-disposition/node_modules/safe-buffer/README.md +0 -584
  49. package/node_modules/content-disposition/node_modules/safe-buffer/index.d.ts +0 -187
  50. package/node_modules/content-disposition/node_modules/safe-buffer/index.js +0 -65
  51. package/node_modules/content-disposition/node_modules/safe-buffer/package.json +0 -51
  52. package/node_modules/express/node_modules/safe-buffer/LICENSE +0 -21
  53. package/node_modules/express/node_modules/safe-buffer/README.md +0 -584
  54. package/node_modules/express/node_modules/safe-buffer/index.d.ts +0 -187
  55. package/node_modules/express/node_modules/safe-buffer/index.js +0 -65
  56. package/node_modules/express/node_modules/safe-buffer/package.json +0 -51
  57. package/node_modules/raw-body/node_modules/bytes/History.md +0 -97
  58. package/node_modules/raw-body/node_modules/bytes/LICENSE +0 -23
  59. package/node_modules/raw-body/node_modules/bytes/Readme.md +0 -152
  60. package/node_modules/raw-body/node_modules/bytes/index.js +0 -170
  61. package/node_modules/raw-body/node_modules/bytes/package.json +0 -42
package/CHANGELOG.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ### Change Log for Node-RED Worldmap
2
2
 
3
- - v5.0.5 - Tweak SIDC flag handling slightly.
4
- - v5.0.4 - Tweak CoT handling slightly.
3
+ - v5.0.7 - Tweak SIDC flag handling slightly to show direction if available and moving.
4
+ - v5.0.4 - Tweak CoT handling slightly.
5
5
  - v5.0.3 - Add great context menu example flow. PR#290. Bump express lib. PR#291.
6
6
  - v5.0.2 - Fix sidcEdgeIcon docs PR#289.
7
7
  - v5.0.1 - Fix isArray error PR #288.
package/README.md CHANGED
@@ -13,7 +13,8 @@ Feel free to [![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%
13
13
 
14
14
  ### Updates
15
15
 
16
- - v5.0.5 - Tweak SIDC flag handling slightly.
16
+ - v5.0.7 - Allow Tooltip options (see new example). #PR295.
17
+ - v5.0.6 - Tweak SIDC flag handling slightly to show direction if available and moving.
17
18
  - v5.0.4 - Tweak CoT handling slightly.
18
19
  - v5.0.3 - Add great context menu example flow. PR#290. Bump express lib. PR#291.
19
20
  - v5.0.2 - Fix sidcEdgeIcon docs PR#289.
@@ -88,6 +89,7 @@ Optional properties for **msg.payload** include
88
89
  - **popup** : html to fill the popup if you don't want the automatic default of the properties list. Using this overrides photourl, videourl and weblink options.
89
90
  - **label** : displays the contents as a permanent label next to the marker, or
90
91
  - **tooltip** : displays the contents when you hover over the marker. (Mutually exclusive with label. Label has priority)
92
+ - **tooltipOptions** : custom tooltip/label options (offset, direction, permanent, sticky, interactive, opacity, className) )
91
93
  - **contextmenu** : an html fragment to display on right click of marker - defaults to delete marker. You can specify `${name}` to substitute in the name of the marker. Set to `""` to disable just this instance.
92
94
 
93
95
  Any other `msg.payload` properties will be added to the icon popup text box. This can be
@@ -0,0 +1,83 @@
1
+ [
2
+ {
3
+ "id": "ec9da974.051b48",
4
+ "type": "inject",
5
+ "z": "f6f2187d.f17ca8",
6
+ "name": "",
7
+ "repeat": "",
8
+ "crontab": "",
9
+ "once": false,
10
+ "topic": "",
11
+ "payload": "",
12
+ "payloadType": "str",
13
+ "x": 1010,
14
+ "y": 560,
15
+ "wires": [
16
+ [
17
+ "f77a7ed4.f955d"
18
+ ]
19
+ ]
20
+ },
21
+ {
22
+ "id": "f77a7ed4.f955d",
23
+ "type": "function",
24
+ "z": "f6f2187d.f17ca8",
25
+ "name": "Car + Label",
26
+ "func": "var thing = {\n name:\"Jason Isaacs\", \n lat:51, \n lon:-1.45,\n icon:\"car\",\n iconColor:\"darkred\",\n extrainfo:\"Hello to Jason Isaacs\",\n label:\"This is a custom label\",\n tooltipOptions: {\"offset\" : [-100,-100], \"permanent\" : true, \"opacity\" : 1, \"direction\" : \"top\", \"className\" : \"tooltip\"}\n};\nmsg.payload = thing;\nreturn msg;",
27
+ "outputs": 1,
28
+ "timeout": "",
29
+ "noerr": 0,
30
+ "initialize": "",
31
+ "finalize": "",
32
+ "libs": [],
33
+ "x": 1230,
34
+ "y": 560,
35
+ "wires": [
36
+ [
37
+ "f83930ff.b21488"
38
+ ]
39
+ ]
40
+ },
41
+ {
42
+ "id": "cd09f7be.079518",
43
+ "type": "comment",
44
+ "z": "f6f2187d.f17ca8",
45
+ "name": "Simple map - click inject to send info to map.",
46
+ "info": "Adds a map at http://(your-server-ip):1880/worldmap. \n\nThe `function` node creates an object with some basic properties required to add to a map.",
47
+ "x": 1170,
48
+ "y": 500,
49
+ "wires": []
50
+ },
51
+ {
52
+ "id": "f83930ff.b21488",
53
+ "type": "worldmap",
54
+ "z": "f6f2187d.f17ca8",
55
+ "name": "",
56
+ "lat": "",
57
+ "lon": "",
58
+ "zoom": "",
59
+ "layer": "OSMG",
60
+ "cluster": "",
61
+ "maxage": "",
62
+ "usermenu": "show",
63
+ "layers": "show",
64
+ "panit": "false",
65
+ "panlock": "false",
66
+ "zoomlock": "false",
67
+ "hiderightclick": "false",
68
+ "coords": "none",
69
+ "showgrid": "false",
70
+ "showruler": "true",
71
+ "allowFileDrop": "false",
72
+ "path": "/worldmap",
73
+ "overlist": "DR,CO,RA,DN,HM",
74
+ "maplist": "OSMG,OSMC,EsriC,EsriS,EsriT,EsriO,EsriDG,NatGeo,UKOS,OpTop",
75
+ "mapname": "",
76
+ "mapurl": "",
77
+ "mapopt": "",
78
+ "mapwms": false,
79
+ "x": 1400,
80
+ "y": 560,
81
+ "wires": []
82
+ }
83
+ ]
@@ -0,0 +1,108 @@
1
+ 0.6.3 / 2022-01-22
2
+ ==================
3
+
4
+ * Revert "Lazy-load modules from main entry point"
5
+
6
+ 0.6.2 / 2019-04-29
7
+ ==================
8
+
9
+ * Fix sorting charset, encoding, and language with extra parameters
10
+
11
+ 0.6.1 / 2016-05-02
12
+ ==================
13
+
14
+ * perf: improve `Accept` parsing speed
15
+ * perf: improve `Accept-Charset` parsing speed
16
+ * perf: improve `Accept-Encoding` parsing speed
17
+ * perf: improve `Accept-Language` parsing speed
18
+
19
+ 0.6.0 / 2015-09-29
20
+ ==================
21
+
22
+ * Fix including type extensions in parameters in `Accept` parsing
23
+ * Fix parsing `Accept` parameters with quoted equals
24
+ * Fix parsing `Accept` parameters with quoted semicolons
25
+ * Lazy-load modules from main entry point
26
+ * perf: delay type concatenation until needed
27
+ * perf: enable strict mode
28
+ * perf: hoist regular expressions
29
+ * perf: remove closures getting spec properties
30
+ * perf: remove a closure from media type parsing
31
+ * perf: remove property delete from media type parsing
32
+
33
+ 0.5.3 / 2015-05-10
34
+ ==================
35
+
36
+ * Fix media type parameter matching to be case-insensitive
37
+
38
+ 0.5.2 / 2015-05-06
39
+ ==================
40
+
41
+ * Fix comparing media types with quoted values
42
+ * Fix splitting media types with quoted commas
43
+
44
+ 0.5.1 / 2015-02-14
45
+ ==================
46
+
47
+ * Fix preference sorting to be stable for long acceptable lists
48
+
49
+ 0.5.0 / 2014-12-18
50
+ ==================
51
+
52
+ * Fix list return order when large accepted list
53
+ * Fix missing identity encoding when q=0 exists
54
+ * Remove dynamic building of Negotiator class
55
+
56
+ 0.4.9 / 2014-10-14
57
+ ==================
58
+
59
+ * Fix error when media type has invalid parameter
60
+
61
+ 0.4.8 / 2014-09-28
62
+ ==================
63
+
64
+ * Fix all negotiations to be case-insensitive
65
+ * Stable sort preferences of same quality according to client order
66
+ * Support Node.js 0.6
67
+
68
+ 0.4.7 / 2014-06-24
69
+ ==================
70
+
71
+ * Handle invalid provided languages
72
+ * Handle invalid provided media types
73
+
74
+ 0.4.6 / 2014-06-11
75
+ ==================
76
+
77
+ * Order by specificity when quality is the same
78
+
79
+ 0.4.5 / 2014-05-29
80
+ ==================
81
+
82
+ * Fix regression in empty header handling
83
+
84
+ 0.4.4 / 2014-05-29
85
+ ==================
86
+
87
+ * Fix behaviors when headers are not present
88
+
89
+ 0.4.3 / 2014-04-16
90
+ ==================
91
+
92
+ * Handle slashes on media params correctly
93
+
94
+ 0.4.2 / 2014-02-28
95
+ ==================
96
+
97
+ * Fix media type sorting
98
+ * Handle media types params strictly
99
+
100
+ 0.4.1 / 2014-01-16
101
+ ==================
102
+
103
+ * Use most specific matches
104
+
105
+ 0.4.0 / 2014-01-09
106
+ ==================
107
+
108
+ * Remove preferred prefix from methods
@@ -1,7 +1,8 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2012-2014 TJ Holowaychuk <tj@vision-media.ca>
4
- Copyright (c) 2015 Jed Watson <jed.watson@me.com>
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
+ }