wkt-parse-and-geojson 1.0.2 → 1.0.3
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/LICENSE +21 -0
- package/dist/index.cjs.js +19 -19
- package/dist/index.esm.js +19 -19
- package/dist/index.umd.js +19 -19
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// Precompiled regex for better performance
|
|
4
|
+
const RE_WHITESPACE = /\s/;
|
|
5
|
+
const RE_NUMBER_START = /[0-9\-]/;
|
|
6
|
+
const RE_NUMBER_BODY = /[0-9\.\-eE\+]/;
|
|
7
|
+
const RE_WORD_CHAR = /[a-zA-Z_]/;
|
|
3
8
|
class Lexer {
|
|
4
9
|
constructor(input) {
|
|
5
10
|
this.pos = 0;
|
|
@@ -12,14 +17,13 @@ class Lexer {
|
|
|
12
17
|
return this.input[this.pos++] || '';
|
|
13
18
|
}
|
|
14
19
|
isWhitespace(c) {
|
|
15
|
-
return
|
|
20
|
+
return RE_WHITESPACE.test(c);
|
|
16
21
|
}
|
|
17
|
-
/** 数字开头字符:数字 或 负号 */
|
|
18
22
|
isNumberStart(c) {
|
|
19
|
-
return
|
|
23
|
+
return RE_NUMBER_START.test(c);
|
|
20
24
|
}
|
|
21
25
|
isNumberBody(c) {
|
|
22
|
-
return
|
|
26
|
+
return RE_NUMBER_BODY.test(c);
|
|
23
27
|
}
|
|
24
28
|
nextToken() {
|
|
25
29
|
// skip whitespace
|
|
@@ -44,18 +48,18 @@ class Lexer {
|
|
|
44
48
|
}
|
|
45
49
|
// Number: starts with digit or minus
|
|
46
50
|
if (this.isNumberStart(c)) {
|
|
47
|
-
|
|
51
|
+
const start = this.pos;
|
|
48
52
|
while (this.pos < this.input.length && this.isNumberBody(this.peek())) {
|
|
49
|
-
|
|
53
|
+
this.pos++;
|
|
50
54
|
}
|
|
51
|
-
return { type: 'NUMBER', value:
|
|
55
|
+
return { type: 'NUMBER', value: this.input.slice(start, this.pos) };
|
|
52
56
|
}
|
|
53
57
|
// Word (geometry type or EMPTY/Z/M keyword)
|
|
54
|
-
|
|
55
|
-
while (this.pos < this.input.length &&
|
|
56
|
-
|
|
58
|
+
const start = this.pos;
|
|
59
|
+
while (this.pos < this.input.length && RE_WORD_CHAR.test(this.peek())) {
|
|
60
|
+
this.pos++;
|
|
57
61
|
}
|
|
58
|
-
return { type: 'WORD', value:
|
|
62
|
+
return { type: 'WORD', value: this.input.slice(start, this.pos).toUpperCase() };
|
|
59
63
|
}
|
|
60
64
|
}
|
|
61
65
|
class WKTParser {
|
|
@@ -250,11 +254,9 @@ class WKTParser {
|
|
|
250
254
|
}
|
|
251
255
|
this.advance(); // consume (
|
|
252
256
|
const geometries = [];
|
|
253
|
-
while (this.
|
|
257
|
+
while (!this.isDone()) {
|
|
254
258
|
geometries.push(this.parseGeometry());
|
|
255
|
-
|
|
256
|
-
this.advance();
|
|
257
|
-
}
|
|
259
|
+
this.skipComma();
|
|
258
260
|
}
|
|
259
261
|
this.consume('RPAREN');
|
|
260
262
|
return { type: 'GeometryCollection', geometries };
|
|
@@ -300,11 +302,9 @@ class WKTParser {
|
|
|
300
302
|
return [];
|
|
301
303
|
this.advance(); // consume outer (
|
|
302
304
|
const lists = [];
|
|
303
|
-
while (this.
|
|
305
|
+
while (!this.isDone()) {
|
|
304
306
|
lists.push(this.parseCoordinatesList());
|
|
305
|
-
|
|
306
|
-
this.advance();
|
|
307
|
-
}
|
|
307
|
+
this.skipComma();
|
|
308
308
|
}
|
|
309
309
|
this.consume('RPAREN');
|
|
310
310
|
return lists;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// Precompiled regex for better performance
|
|
2
|
+
const RE_WHITESPACE = /\s/;
|
|
3
|
+
const RE_NUMBER_START = /[0-9\-]/;
|
|
4
|
+
const RE_NUMBER_BODY = /[0-9\.\-eE\+]/;
|
|
5
|
+
const RE_WORD_CHAR = /[a-zA-Z_]/;
|
|
1
6
|
class Lexer {
|
|
2
7
|
constructor(input) {
|
|
3
8
|
this.pos = 0;
|
|
@@ -10,14 +15,13 @@ class Lexer {
|
|
|
10
15
|
return this.input[this.pos++] || '';
|
|
11
16
|
}
|
|
12
17
|
isWhitespace(c) {
|
|
13
|
-
return
|
|
18
|
+
return RE_WHITESPACE.test(c);
|
|
14
19
|
}
|
|
15
|
-
/** 数字开头字符:数字 或 负号 */
|
|
16
20
|
isNumberStart(c) {
|
|
17
|
-
return
|
|
21
|
+
return RE_NUMBER_START.test(c);
|
|
18
22
|
}
|
|
19
23
|
isNumberBody(c) {
|
|
20
|
-
return
|
|
24
|
+
return RE_NUMBER_BODY.test(c);
|
|
21
25
|
}
|
|
22
26
|
nextToken() {
|
|
23
27
|
// skip whitespace
|
|
@@ -42,18 +46,18 @@ class Lexer {
|
|
|
42
46
|
}
|
|
43
47
|
// Number: starts with digit or minus
|
|
44
48
|
if (this.isNumberStart(c)) {
|
|
45
|
-
|
|
49
|
+
const start = this.pos;
|
|
46
50
|
while (this.pos < this.input.length && this.isNumberBody(this.peek())) {
|
|
47
|
-
|
|
51
|
+
this.pos++;
|
|
48
52
|
}
|
|
49
|
-
return { type: 'NUMBER', value:
|
|
53
|
+
return { type: 'NUMBER', value: this.input.slice(start, this.pos) };
|
|
50
54
|
}
|
|
51
55
|
// Word (geometry type or EMPTY/Z/M keyword)
|
|
52
|
-
|
|
53
|
-
while (this.pos < this.input.length &&
|
|
54
|
-
|
|
56
|
+
const start = this.pos;
|
|
57
|
+
while (this.pos < this.input.length && RE_WORD_CHAR.test(this.peek())) {
|
|
58
|
+
this.pos++;
|
|
55
59
|
}
|
|
56
|
-
return { type: 'WORD', value:
|
|
60
|
+
return { type: 'WORD', value: this.input.slice(start, this.pos).toUpperCase() };
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
class WKTParser {
|
|
@@ -248,11 +252,9 @@ class WKTParser {
|
|
|
248
252
|
}
|
|
249
253
|
this.advance(); // consume (
|
|
250
254
|
const geometries = [];
|
|
251
|
-
while (this.
|
|
255
|
+
while (!this.isDone()) {
|
|
252
256
|
geometries.push(this.parseGeometry());
|
|
253
|
-
|
|
254
|
-
this.advance();
|
|
255
|
-
}
|
|
257
|
+
this.skipComma();
|
|
256
258
|
}
|
|
257
259
|
this.consume('RPAREN');
|
|
258
260
|
return { type: 'GeometryCollection', geometries };
|
|
@@ -298,11 +300,9 @@ class WKTParser {
|
|
|
298
300
|
return [];
|
|
299
301
|
this.advance(); // consume outer (
|
|
300
302
|
const lists = [];
|
|
301
|
-
while (this.
|
|
303
|
+
while (!this.isDone()) {
|
|
302
304
|
lists.push(this.parseCoordinatesList());
|
|
303
|
-
|
|
304
|
-
this.advance();
|
|
305
|
-
}
|
|
305
|
+
this.skipComma();
|
|
306
306
|
}
|
|
307
307
|
this.consume('RPAREN');
|
|
308
308
|
return lists;
|
package/dist/index.umd.js
CHANGED
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.WKTGeoJSON = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
+
// Precompiled regex for better performance
|
|
8
|
+
const RE_WHITESPACE = /\s/;
|
|
9
|
+
const RE_NUMBER_START = /[0-9\-]/;
|
|
10
|
+
const RE_NUMBER_BODY = /[0-9\.\-eE\+]/;
|
|
11
|
+
const RE_WORD_CHAR = /[a-zA-Z_]/;
|
|
7
12
|
class Lexer {
|
|
8
13
|
constructor(input) {
|
|
9
14
|
this.pos = 0;
|
|
@@ -16,14 +21,13 @@
|
|
|
16
21
|
return this.input[this.pos++] || '';
|
|
17
22
|
}
|
|
18
23
|
isWhitespace(c) {
|
|
19
|
-
return
|
|
24
|
+
return RE_WHITESPACE.test(c);
|
|
20
25
|
}
|
|
21
|
-
/** 数字开头字符:数字 或 负号 */
|
|
22
26
|
isNumberStart(c) {
|
|
23
|
-
return
|
|
27
|
+
return RE_NUMBER_START.test(c);
|
|
24
28
|
}
|
|
25
29
|
isNumberBody(c) {
|
|
26
|
-
return
|
|
30
|
+
return RE_NUMBER_BODY.test(c);
|
|
27
31
|
}
|
|
28
32
|
nextToken() {
|
|
29
33
|
// skip whitespace
|
|
@@ -48,18 +52,18 @@
|
|
|
48
52
|
}
|
|
49
53
|
// Number: starts with digit or minus
|
|
50
54
|
if (this.isNumberStart(c)) {
|
|
51
|
-
|
|
55
|
+
const start = this.pos;
|
|
52
56
|
while (this.pos < this.input.length && this.isNumberBody(this.peek())) {
|
|
53
|
-
|
|
57
|
+
this.pos++;
|
|
54
58
|
}
|
|
55
|
-
return { type: 'NUMBER', value:
|
|
59
|
+
return { type: 'NUMBER', value: this.input.slice(start, this.pos) };
|
|
56
60
|
}
|
|
57
61
|
// Word (geometry type or EMPTY/Z/M keyword)
|
|
58
|
-
|
|
59
|
-
while (this.pos < this.input.length &&
|
|
60
|
-
|
|
62
|
+
const start = this.pos;
|
|
63
|
+
while (this.pos < this.input.length && RE_WORD_CHAR.test(this.peek())) {
|
|
64
|
+
this.pos++;
|
|
61
65
|
}
|
|
62
|
-
return { type: 'WORD', value:
|
|
66
|
+
return { type: 'WORD', value: this.input.slice(start, this.pos).toUpperCase() };
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
69
|
class WKTParser {
|
|
@@ -254,11 +258,9 @@
|
|
|
254
258
|
}
|
|
255
259
|
this.advance(); // consume (
|
|
256
260
|
const geometries = [];
|
|
257
|
-
while (this.
|
|
261
|
+
while (!this.isDone()) {
|
|
258
262
|
geometries.push(this.parseGeometry());
|
|
259
|
-
|
|
260
|
-
this.advance();
|
|
261
|
-
}
|
|
263
|
+
this.skipComma();
|
|
262
264
|
}
|
|
263
265
|
this.consume('RPAREN');
|
|
264
266
|
return { type: 'GeometryCollection', geometries };
|
|
@@ -304,11 +306,9 @@
|
|
|
304
306
|
return [];
|
|
305
307
|
this.advance(); // consume outer (
|
|
306
308
|
const lists = [];
|
|
307
|
-
while (this.
|
|
309
|
+
while (!this.isDone()) {
|
|
308
310
|
lists.push(this.parseCoordinatesList());
|
|
309
|
-
|
|
310
|
-
this.advance();
|
|
311
|
-
}
|
|
311
|
+
this.skipComma();
|
|
312
312
|
}
|
|
313
313
|
this.consume('RPAREN');
|
|
314
314
|
return lists;
|