@hpcc-js/map 3.5.2 → 3.5.4

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 (96) hide show
  1. package/LICENSE +43 -43
  2. package/README.md +88 -88
  3. package/TopoJSON/BR.json +122 -122
  4. package/TopoJSON/GB_idx.json +1 -1
  5. package/TopoJSON/IE_idx.json +1 -1
  6. package/TopoJSON/ND_idx.json +1 -1
  7. package/TopoJSON/countries.json +257 -257
  8. package/TopoJSON/us-counties.json +16550 -16550
  9. package/TopoJSON/us-states.json +458 -458
  10. package/dist/index.js +1 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.umd.cjs +1 -1
  13. package/dist/index.umd.cjs.map +1 -1
  14. package/package.json +9 -9
  15. package/src/CanvasPinLayer.ts +99 -99
  16. package/src/CanvasPins.ts +397 -397
  17. package/src/Choropleth.css +26 -26
  18. package/src/Choropleth.ts +203 -203
  19. package/src/ChoroplethContinents.ts +13 -13
  20. package/src/ChoroplethCounties.ts +111 -111
  21. package/src/ChoroplethCountries.ts +100 -100
  22. package/src/ChoroplethStates.ts +103 -103
  23. package/src/ChoroplethStatesHeat.ts +8 -8
  24. package/src/GMap.css +20 -20
  25. package/src/GMap.ts +880 -880
  26. package/src/GMapCounties.ts +93 -93
  27. package/src/GMapGraph.ts +61 -61
  28. package/src/GMapHeat.ts +27 -27
  29. package/src/GMapLayered.ts +94 -94
  30. package/src/GMapPin.ts +115 -115
  31. package/src/GMapPinLine.ts +138 -138
  32. package/src/GeoHash.css +14 -14
  33. package/src/GeoHash.ts +139 -139
  34. package/src/Graph.css +9 -9
  35. package/src/Graph.ts +98 -98
  36. package/src/Graticule.css +12 -12
  37. package/src/Graticule.ts +97 -97
  38. package/src/Heat.ts +87 -87
  39. package/src/IChoropleth.ts +8 -8
  40. package/src/Layer.ts +99 -99
  41. package/src/Layered.css +18 -18
  42. package/src/Layered.ts +206 -206
  43. package/src/Lines.css +8 -8
  44. package/src/Lines.ts +78 -78
  45. package/src/OpenStreet.css +15 -15
  46. package/src/OpenStreet.ts +126 -126
  47. package/src/Pins.css +17 -17
  48. package/src/Pins.ts +350 -350
  49. package/src/Projection.ts +42 -42
  50. package/src/TestHeatMap.ts +8 -8
  51. package/src/TopoJSONChoropleth.ts +125 -125
  52. package/src/Utility.ts +484 -484
  53. package/src/__package__.ts +3 -3
  54. package/src/index.ts +33 -33
  55. package/src/leaflet/AlbersPR.ts +48 -48
  56. package/src/leaflet/Blank.ts +9 -9
  57. package/src/leaflet/Circles.ts +139 -139
  58. package/src/leaflet/ClusterCircles.css +26 -26
  59. package/src/leaflet/ClusterCircles.ts +88 -88
  60. package/src/leaflet/Countries.ts +43 -43
  61. package/src/leaflet/DrawLayer.ts +167 -167
  62. package/src/leaflet/FeatureLayer.ts +138 -138
  63. package/src/leaflet/GMap.ts +44 -44
  64. package/src/leaflet/HeatLayer.ts +77 -77
  65. package/src/leaflet/Icons.ts +60 -60
  66. package/src/leaflet/Leaflet.css +3 -3
  67. package/src/leaflet/Leaflet.ts +239 -239
  68. package/src/leaflet/MapBox.ts +35 -35
  69. package/src/leaflet/Markers.ts +109 -109
  70. package/src/leaflet/OpenStreet.ts +27 -27
  71. package/src/leaflet/Path.ts +138 -138
  72. package/src/leaflet/Pins.ts +73 -73
  73. package/src/leaflet/Polygons.ts +113 -113
  74. package/src/leaflet/Region.ts +138 -138
  75. package/src/leaflet/Text.ts +99 -99
  76. package/src/leaflet/TileLayer.ts +81 -81
  77. package/src/leaflet/TopoJSON.ts +146 -146
  78. package/src/leaflet/US.ts +15 -15
  79. package/src/leaflet/USCounties.ts +43 -43
  80. package/src/leaflet/USStates.ts +41 -41
  81. package/src/leaflet/World.css +3 -3
  82. package/src/leaflet/World.ts +172 -172
  83. package/src/leaflet/index.ts +18 -18
  84. package/src/leaflet/leaflet-shim.ts +18 -18
  85. package/src/leaflet/plugins/BeautifyIcon.css +44 -44
  86. package/src/leaflet/plugins/BeautifyIcon.ts +190 -190
  87. package/src/leaflet/plugins/BeutifyIcon.licence +20 -20
  88. package/src/leaflet/plugins/D3SvgOverlay.css +2 -2
  89. package/src/leaflet/plugins/D3SvgOverlay.licence +20 -20
  90. package/src/leaflet/plugins/D3SvgOverlay.ts +175 -175
  91. package/src/leaflet/plugins/HeatLayer.license +21 -21
  92. package/src/leaflet/plugins/HeatLayer.ts +224 -224
  93. package/src/leaflet/plugins/Leaflet.GoogleMutant.ts +424 -424
  94. package/src/leaflet/plugins/lru_map.ts +352 -352
  95. package/src/test.ts +114 -114
  96. package/types/Layered.d.ts +1 -1
@@ -1,352 +1,352 @@
1
- // This implementation of LRUMap is a copy of https://github.com/rsms/js-lru/ ,
2
- // trivially adapted for ES6 exports.
3
-
4
- /*
5
- The MIT License
6
-
7
- Copyright (c) 2010-2020 Rasmus Andersson <https://rsms.me/>
8
-
9
- Permission is hereby granted, free of charge, to any person obtaining a copy
10
- of this software and associated documentation files (the "Software"), to deal
11
- in the Software without restriction, including without limitation the rights
12
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
- copies of the Software, and to permit persons to whom the Software is
14
- furnished to do so, subject to the following conditions:
15
-
16
- The above copyright notice and this permission notice shall be included in
17
- all copies or substantial portions of the Software.
18
-
19
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
- THE SOFTWARE.
26
- */
27
-
28
- /**
29
- * A doubly linked list-based Least Recently Used (LRU) cache. Will keep most
30
- * recently used items while discarding least recently used items when its limit
31
- * is reached.
32
- *
33
- * Licensed under MIT. Copyright (c) 2010 Rasmus Andersson <http://hunch.se/>
34
- * See README.md for details.
35
- *
36
- * Illustration of the design:
37
- *
38
- * entry entry entry entry
39
- * ______ ______ ______ ______
40
- * | head |.newer => | |.newer => | |.newer => | tail |
41
- * | A | | B | | C | | D |
42
- * |______| <= older.|______| <= older.|______| <= older.|______|
43
- *
44
- * removed <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- added
45
- */
46
-
47
- const NEWER = Symbol("newer");
48
- const OLDER = Symbol("older");
49
-
50
- class Entry<T> {
51
- key: string;
52
- value: T;
53
-
54
- constructor(key: string, value: T) {
55
- this.key = key;
56
- this.value = value;
57
- this[NEWER] = undefined;
58
- this[OLDER] = undefined;
59
- }
60
- }
61
-
62
- export class LRUMap<T> {
63
-
64
- size: number;
65
- limit: number;
66
- oldest: Entry<T>;
67
- newest: Entry<T>;
68
- _keymap: Map<string, Entry<T>>;
69
-
70
- constructor(entries: Entry<T>[]);
71
- constructor(limit: number, entries: Entry<T>[]);
72
- constructor(limit: Entry<T>[] | number, entries?: Entry<T>[]) {
73
- if (typeof limit !== "number") {
74
- // called as (entries)
75
- entries = limit;
76
- limit = 0;
77
- }
78
-
79
- this.size = 0;
80
- this.limit = limit;
81
- this.oldest = this.newest = undefined;
82
- this._keymap = new Map<string, Entry<T>>();
83
-
84
- if (entries) {
85
- this.assign(entries);
86
- if (limit < 1) {
87
- this.limit = this.size;
88
- }
89
- }
90
- }
91
-
92
- _markEntryAsUsed(entry: Entry<T>) {
93
- if (entry === this.newest) {
94
- // Already the most recenlty used entry, so no need to update the list
95
- return;
96
- }
97
- // HEAD--------------TAIL
98
- // <.older .newer>
99
- // <--- add direction --
100
- // A B C <D> E
101
- if (entry[NEWER]) {
102
- if (entry === this.oldest) {
103
- this.oldest = entry[NEWER];
104
- }
105
- entry[NEWER][OLDER] = entry[OLDER]; // C <-- E.
106
- }
107
- if (entry[OLDER]) {
108
- entry[OLDER][NEWER] = entry[NEWER]; // C. --> E
109
- }
110
- entry[NEWER] = undefined; // D --x
111
- entry[OLDER] = this.newest; // D. --> E
112
- if (this.newest) {
113
- this.newest[NEWER] = entry; // E. <-- D
114
- }
115
- this.newest = entry;
116
- }
117
-
118
- assign(entries: Entry<T>[]) {
119
- let entry,
120
- limit = this.limit || Number.MAX_VALUE;
121
- this._keymap.clear();
122
- const it = entries[Symbol.iterator]();
123
- for (let itv = it.next(); !itv.done; itv = it.next()) {
124
- const e = new Entry(itv.value[0], itv.value[1]);
125
- this._keymap.set(e.key, e);
126
- if (!entry) {
127
- this.oldest = e;
128
- } else {
129
- entry[NEWER] = e;
130
- e[OLDER] = entry;
131
- }
132
- entry = e;
133
- if (limit-- == 0) {
134
- throw new Error("overflow");
135
- }
136
- }
137
- this.newest = entry;
138
- this.size = this._keymap.size;
139
- }
140
-
141
- get(key: string) {
142
- // First, find our cache entry
143
- const entry = this._keymap.get(key);
144
- if (!entry) return; // Not cached. Sorry.
145
- // As <key> was found in the cache, register it as being requested recently
146
- this._markEntryAsUsed(entry);
147
- return entry.value;
148
- }
149
-
150
- set(key: string, value: T) {
151
- let entry = this._keymap.get(key);
152
-
153
- if (entry) {
154
- // update existing
155
- entry.value = value;
156
- this._markEntryAsUsed(entry);
157
- return this;
158
- }
159
-
160
- // new entry
161
- this._keymap.set(key, (entry = new Entry(key, value)));
162
-
163
- if (this.newest) {
164
- // link previous tail to the new tail (entry)
165
- this.newest[NEWER] = entry;
166
- entry[OLDER] = this.newest;
167
- } else {
168
- // we're first in -- yay
169
- this.oldest = entry;
170
- }
171
-
172
- // add new entry to the end of the linked list -- it's now the freshest entry.
173
- this.newest = entry;
174
- ++this.size;
175
- if (this.size > this.limit) {
176
- // we hit the limit -- remove the head
177
- this.shift();
178
- }
179
-
180
- return this;
181
- }
182
-
183
- shift() {
184
- // todo: handle special case when limit == 1
185
- const entry = this.oldest;
186
- if (entry) {
187
- if (this.oldest[NEWER]) {
188
- // advance the list
189
- this.oldest = this.oldest[NEWER];
190
- this.oldest[OLDER] = undefined;
191
- } else {
192
- // the cache is exhausted
193
- this.oldest = undefined;
194
- this.newest = undefined;
195
- }
196
- // Remove last strong reference to <entry> and remove links from the purged
197
- // entry being returned:
198
- entry[NEWER] = entry[OLDER] = undefined;
199
- this._keymap.delete(entry.key);
200
- --this.size;
201
- return [entry.key, entry.value];
202
- }
203
- }
204
-
205
- // -------------------------------------------------------------------------------------
206
- // Following code (until end of class definition) is optional and can be removed without
207
- // breaking the core functionality.
208
-
209
- find(key: string) {
210
- const e = this._keymap.get(key);
211
- return e ? e.value : undefined;
212
- }
213
-
214
- has(key: string) {
215
- return this._keymap.has(key);
216
- }
217
-
218
- delete(key: string) {
219
- const entry = this._keymap.get(key);
220
- if (!entry) return;
221
- this._keymap.delete(entry.key);
222
- if (entry[NEWER] && entry[OLDER]) {
223
- // relink the older entry with the newer entry
224
- entry[OLDER][NEWER] = entry[NEWER];
225
- entry[NEWER][OLDER] = entry[OLDER];
226
- } else if (entry[NEWER]) {
227
- // remove the link to us
228
- entry[NEWER][OLDER] = undefined;
229
- // link the newer entry to head
230
- this.oldest = entry[NEWER];
231
- } else if (entry[OLDER]) {
232
- // remove the link to us
233
- entry[OLDER][NEWER] = undefined;
234
- // link the newer entry to head
235
- this.newest = entry[OLDER];
236
- } else {
237
- // if(entry[OLDER] === undefined && entry.newer === undefined) {
238
- this.oldest = this.newest = undefined;
239
- }
240
-
241
- this.size--;
242
- return entry.value;
243
- }
244
-
245
- clear() {
246
- // Not clearing links should be safe, as we don't expose live links to user
247
- this.oldest = this.newest = undefined;
248
- this.size = 0;
249
- this._keymap.clear();
250
- }
251
-
252
- keys() {
253
- return new KeyIterator(this.oldest);
254
- }
255
-
256
- values() {
257
- return new ValueIterator(this.oldest);
258
- }
259
-
260
- entries() {
261
- return this;
262
- }
263
-
264
- [Symbol.iterator]() {
265
- return new EntryIterator(this.oldest);
266
- }
267
-
268
- forEach(fun, thisObj) {
269
- if (typeof thisObj !== "object") {
270
- thisObj = this;
271
- }
272
- let entry = this.oldest;
273
- while (entry) {
274
- fun.call(thisObj, entry.value, entry.key, this);
275
- entry = entry[NEWER];
276
- }
277
- }
278
-
279
- /** Returns a JSON (array) representation */
280
- toJSON() {
281
- const s = new Array(this.size);
282
- let i = 0;
283
- let entry = this.oldest;
284
- while (entry) {
285
- s[i++] = { key: entry.key, value: entry.value };
286
- entry = entry[NEWER];
287
- }
288
- return s;
289
- }
290
-
291
- /** Returns a String representation */
292
- toString() {
293
- let s = "",
294
- entry = this.oldest;
295
- while (entry) {
296
- s += String(entry.key) + ":" + entry.value;
297
- entry = entry[NEWER];
298
- if (entry) {
299
- s += " < ";
300
- }
301
- }
302
- return s;
303
- }
304
- }
305
-
306
- function EntryIterator(oldestEntry) {
307
- this.entry = oldestEntry;
308
- }
309
- EntryIterator.prototype[Symbol.iterator] = function () {
310
- return this;
311
- };
312
- EntryIterator.prototype.next = function () {
313
- const ent = this.entry;
314
- if (ent) {
315
- this.entry = ent[NEWER];
316
- return { done: false, value: [ent.key, ent.value] };
317
- } else {
318
- return { done: true, value: undefined };
319
- }
320
- };
321
-
322
- function KeyIterator(oldestEntry) {
323
- this.entry = oldestEntry;
324
- }
325
- KeyIterator.prototype[Symbol.iterator] = function () {
326
- return this;
327
- };
328
- KeyIterator.prototype.next = function () {
329
- const ent = this.entry;
330
- if (ent) {
331
- this.entry = ent[NEWER];
332
- return { done: false, value: ent.key };
333
- } else {
334
- return { done: true, value: undefined };
335
- }
336
- };
337
-
338
- function ValueIterator(oldestEntry) {
339
- this.entry = oldestEntry;
340
- }
341
- ValueIterator.prototype[Symbol.iterator] = function () {
342
- return this;
343
- };
344
- ValueIterator.prototype.next = function () {
345
- const ent = this.entry;
346
- if (ent) {
347
- this.entry = ent[NEWER];
348
- return { done: false, value: ent.value };
349
- } else {
350
- return { done: true, value: undefined };
351
- }
352
- };
1
+ // This implementation of LRUMap is a copy of https://github.com/rsms/js-lru/ ,
2
+ // trivially adapted for ES6 exports.
3
+
4
+ /*
5
+ The MIT License
6
+
7
+ Copyright (c) 2010-2020 Rasmus Andersson <https://rsms.me/>
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ THE SOFTWARE.
26
+ */
27
+
28
+ /**
29
+ * A doubly linked list-based Least Recently Used (LRU) cache. Will keep most
30
+ * recently used items while discarding least recently used items when its limit
31
+ * is reached.
32
+ *
33
+ * Licensed under MIT. Copyright (c) 2010 Rasmus Andersson <http://hunch.se/>
34
+ * See README.md for details.
35
+ *
36
+ * Illustration of the design:
37
+ *
38
+ * entry entry entry entry
39
+ * ______ ______ ______ ______
40
+ * | head |.newer => | |.newer => | |.newer => | tail |
41
+ * | A | | B | | C | | D |
42
+ * |______| <= older.|______| <= older.|______| <= older.|______|
43
+ *
44
+ * removed <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- added
45
+ */
46
+
47
+ const NEWER = Symbol("newer");
48
+ const OLDER = Symbol("older");
49
+
50
+ class Entry<T> {
51
+ key: string;
52
+ value: T;
53
+
54
+ constructor(key: string, value: T) {
55
+ this.key = key;
56
+ this.value = value;
57
+ this[NEWER] = undefined;
58
+ this[OLDER] = undefined;
59
+ }
60
+ }
61
+
62
+ export class LRUMap<T> {
63
+
64
+ size: number;
65
+ limit: number;
66
+ oldest: Entry<T>;
67
+ newest: Entry<T>;
68
+ _keymap: Map<string, Entry<T>>;
69
+
70
+ constructor(entries: Entry<T>[]);
71
+ constructor(limit: number, entries: Entry<T>[]);
72
+ constructor(limit: Entry<T>[] | number, entries?: Entry<T>[]) {
73
+ if (typeof limit !== "number") {
74
+ // called as (entries)
75
+ entries = limit;
76
+ limit = 0;
77
+ }
78
+
79
+ this.size = 0;
80
+ this.limit = limit;
81
+ this.oldest = this.newest = undefined;
82
+ this._keymap = new Map<string, Entry<T>>();
83
+
84
+ if (entries) {
85
+ this.assign(entries);
86
+ if (limit < 1) {
87
+ this.limit = this.size;
88
+ }
89
+ }
90
+ }
91
+
92
+ _markEntryAsUsed(entry: Entry<T>) {
93
+ if (entry === this.newest) {
94
+ // Already the most recenlty used entry, so no need to update the list
95
+ return;
96
+ }
97
+ // HEAD--------------TAIL
98
+ // <.older .newer>
99
+ // <--- add direction --
100
+ // A B C <D> E
101
+ if (entry[NEWER]) {
102
+ if (entry === this.oldest) {
103
+ this.oldest = entry[NEWER];
104
+ }
105
+ entry[NEWER][OLDER] = entry[OLDER]; // C <-- E.
106
+ }
107
+ if (entry[OLDER]) {
108
+ entry[OLDER][NEWER] = entry[NEWER]; // C. --> E
109
+ }
110
+ entry[NEWER] = undefined; // D --x
111
+ entry[OLDER] = this.newest; // D. --> E
112
+ if (this.newest) {
113
+ this.newest[NEWER] = entry; // E. <-- D
114
+ }
115
+ this.newest = entry;
116
+ }
117
+
118
+ assign(entries: Entry<T>[]) {
119
+ let entry,
120
+ limit = this.limit || Number.MAX_VALUE;
121
+ this._keymap.clear();
122
+ const it = entries[Symbol.iterator]();
123
+ for (let itv = it.next(); !itv.done; itv = it.next()) {
124
+ const e = new Entry(itv.value[0], itv.value[1]);
125
+ this._keymap.set(e.key, e);
126
+ if (!entry) {
127
+ this.oldest = e;
128
+ } else {
129
+ entry[NEWER] = e;
130
+ e[OLDER] = entry;
131
+ }
132
+ entry = e;
133
+ if (limit-- == 0) {
134
+ throw new Error("overflow");
135
+ }
136
+ }
137
+ this.newest = entry;
138
+ this.size = this._keymap.size;
139
+ }
140
+
141
+ get(key: string) {
142
+ // First, find our cache entry
143
+ const entry = this._keymap.get(key);
144
+ if (!entry) return; // Not cached. Sorry.
145
+ // As <key> was found in the cache, register it as being requested recently
146
+ this._markEntryAsUsed(entry);
147
+ return entry.value;
148
+ }
149
+
150
+ set(key: string, value: T) {
151
+ let entry = this._keymap.get(key);
152
+
153
+ if (entry) {
154
+ // update existing
155
+ entry.value = value;
156
+ this._markEntryAsUsed(entry);
157
+ return this;
158
+ }
159
+
160
+ // new entry
161
+ this._keymap.set(key, (entry = new Entry(key, value)));
162
+
163
+ if (this.newest) {
164
+ // link previous tail to the new tail (entry)
165
+ this.newest[NEWER] = entry;
166
+ entry[OLDER] = this.newest;
167
+ } else {
168
+ // we're first in -- yay
169
+ this.oldest = entry;
170
+ }
171
+
172
+ // add new entry to the end of the linked list -- it's now the freshest entry.
173
+ this.newest = entry;
174
+ ++this.size;
175
+ if (this.size > this.limit) {
176
+ // we hit the limit -- remove the head
177
+ this.shift();
178
+ }
179
+
180
+ return this;
181
+ }
182
+
183
+ shift() {
184
+ // todo: handle special case when limit == 1
185
+ const entry = this.oldest;
186
+ if (entry) {
187
+ if (this.oldest[NEWER]) {
188
+ // advance the list
189
+ this.oldest = this.oldest[NEWER];
190
+ this.oldest[OLDER] = undefined;
191
+ } else {
192
+ // the cache is exhausted
193
+ this.oldest = undefined;
194
+ this.newest = undefined;
195
+ }
196
+ // Remove last strong reference to <entry> and remove links from the purged
197
+ // entry being returned:
198
+ entry[NEWER] = entry[OLDER] = undefined;
199
+ this._keymap.delete(entry.key);
200
+ --this.size;
201
+ return [entry.key, entry.value];
202
+ }
203
+ }
204
+
205
+ // -------------------------------------------------------------------------------------
206
+ // Following code (until end of class definition) is optional and can be removed without
207
+ // breaking the core functionality.
208
+
209
+ find(key: string) {
210
+ const e = this._keymap.get(key);
211
+ return e ? e.value : undefined;
212
+ }
213
+
214
+ has(key: string) {
215
+ return this._keymap.has(key);
216
+ }
217
+
218
+ delete(key: string) {
219
+ const entry = this._keymap.get(key);
220
+ if (!entry) return;
221
+ this._keymap.delete(entry.key);
222
+ if (entry[NEWER] && entry[OLDER]) {
223
+ // relink the older entry with the newer entry
224
+ entry[OLDER][NEWER] = entry[NEWER];
225
+ entry[NEWER][OLDER] = entry[OLDER];
226
+ } else if (entry[NEWER]) {
227
+ // remove the link to us
228
+ entry[NEWER][OLDER] = undefined;
229
+ // link the newer entry to head
230
+ this.oldest = entry[NEWER];
231
+ } else if (entry[OLDER]) {
232
+ // remove the link to us
233
+ entry[OLDER][NEWER] = undefined;
234
+ // link the newer entry to head
235
+ this.newest = entry[OLDER];
236
+ } else {
237
+ // if(entry[OLDER] === undefined && entry.newer === undefined) {
238
+ this.oldest = this.newest = undefined;
239
+ }
240
+
241
+ this.size--;
242
+ return entry.value;
243
+ }
244
+
245
+ clear() {
246
+ // Not clearing links should be safe, as we don't expose live links to user
247
+ this.oldest = this.newest = undefined;
248
+ this.size = 0;
249
+ this._keymap.clear();
250
+ }
251
+
252
+ keys() {
253
+ return new KeyIterator(this.oldest);
254
+ }
255
+
256
+ values() {
257
+ return new ValueIterator(this.oldest);
258
+ }
259
+
260
+ entries() {
261
+ return this;
262
+ }
263
+
264
+ [Symbol.iterator]() {
265
+ return new EntryIterator(this.oldest);
266
+ }
267
+
268
+ forEach(fun, thisObj) {
269
+ if (typeof thisObj !== "object") {
270
+ thisObj = this;
271
+ }
272
+ let entry = this.oldest;
273
+ while (entry) {
274
+ fun.call(thisObj, entry.value, entry.key, this);
275
+ entry = entry[NEWER];
276
+ }
277
+ }
278
+
279
+ /** Returns a JSON (array) representation */
280
+ toJSON() {
281
+ const s = new Array(this.size);
282
+ let i = 0;
283
+ let entry = this.oldest;
284
+ while (entry) {
285
+ s[i++] = { key: entry.key, value: entry.value };
286
+ entry = entry[NEWER];
287
+ }
288
+ return s;
289
+ }
290
+
291
+ /** Returns a String representation */
292
+ toString() {
293
+ let s = "",
294
+ entry = this.oldest;
295
+ while (entry) {
296
+ s += String(entry.key) + ":" + entry.value;
297
+ entry = entry[NEWER];
298
+ if (entry) {
299
+ s += " < ";
300
+ }
301
+ }
302
+ return s;
303
+ }
304
+ }
305
+
306
+ function EntryIterator(oldestEntry) {
307
+ this.entry = oldestEntry;
308
+ }
309
+ EntryIterator.prototype[Symbol.iterator] = function () {
310
+ return this;
311
+ };
312
+ EntryIterator.prototype.next = function () {
313
+ const ent = this.entry;
314
+ if (ent) {
315
+ this.entry = ent[NEWER];
316
+ return { done: false, value: [ent.key, ent.value] };
317
+ } else {
318
+ return { done: true, value: undefined };
319
+ }
320
+ };
321
+
322
+ function KeyIterator(oldestEntry) {
323
+ this.entry = oldestEntry;
324
+ }
325
+ KeyIterator.prototype[Symbol.iterator] = function () {
326
+ return this;
327
+ };
328
+ KeyIterator.prototype.next = function () {
329
+ const ent = this.entry;
330
+ if (ent) {
331
+ this.entry = ent[NEWER];
332
+ return { done: false, value: ent.key };
333
+ } else {
334
+ return { done: true, value: undefined };
335
+ }
336
+ };
337
+
338
+ function ValueIterator(oldestEntry) {
339
+ this.entry = oldestEntry;
340
+ }
341
+ ValueIterator.prototype[Symbol.iterator] = function () {
342
+ return this;
343
+ };
344
+ ValueIterator.prototype.next = function () {
345
+ const ent = this.entry;
346
+ if (ent) {
347
+ this.entry = ent[NEWER];
348
+ return { done: false, value: ent.value };
349
+ } else {
350
+ return { done: true, value: undefined };
351
+ }
352
+ };