wkt-parse-and-geojson 1.0.7 → 1.0.8

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/dist/index.cjs.js CHANGED
@@ -288,9 +288,9 @@ class WKTParser {
288
288
  }
289
289
  }
290
290
  function parse(wkt) {
291
- const parser = new WKTParser();
292
- return parser.parse(wkt);
291
+ return WKT_PARSER.parse(wkt);
293
292
  }
293
+ const WKT_PARSER = new WKTParser();
294
294
 
295
295
  var wktParser = /*#__PURE__*/Object.freeze({
296
296
  __proto__: null,
@@ -316,14 +316,15 @@ function hasZ(coordinates) {
316
316
  if (coordinates.length === 0)
317
317
  return false;
318
318
  const first = coordinates[0];
319
- if (Array.isArray(first)) {
320
- if (typeof first[0] === 'number') {
321
- return first.length === 3;
322
- }
323
- if (Array.isArray(first[0])) {
324
- const firstRing = first;
325
- return firstRing.length > 0 && firstRing[0].length === 3;
326
- }
319
+ if (typeof first === 'number') {
320
+ return coordinates.length === 3;
321
+ }
322
+ if (Array.isArray(first) && typeof first[0] === 'number') {
323
+ return first.length === 3;
324
+ }
325
+ if (Array.isArray(first) && Array.isArray(first[0])) {
326
+ const firstRing = first;
327
+ return firstRing.length > 0 && firstRing[0].length === 3;
327
328
  }
328
329
  return false;
329
330
  }
@@ -540,6 +541,7 @@ const VALID_GEOMETRY_TYPES = [
540
541
  'MultiPoint', 'MultiLineString', 'MultiPolygon',
541
542
  'GeometryCollection'
542
543
  ];
544
+ const VALID_TYPES_MESSAGE = `Invalid geometry type. Must be one of: ${VALID_GEOMETRY_TYPES.join(', ')}`;
543
545
  function validateWKT(wkt) {
544
546
  if (!wkt || typeof wkt !== 'string') {
545
547
  return { valid: false, error: 'WKT must be a non-empty string' };
@@ -566,7 +568,7 @@ function validateGeoJSON(geojson) {
566
568
  }
567
569
  const type = obj.type;
568
570
  if (!VALID_GEOMETRY_TYPES.includes(type)) {
569
- return { valid: false, error: `Invalid geometry type: "${type}". Must be one of: ${VALID_GEOMETRY_TYPES.join(', ')}` };
571
+ return { valid: false, error: VALID_TYPES_MESSAGE };
570
572
  }
571
573
  if (type === 'GeometryCollection') {
572
574
  if (!obj.geometries || !Array.isArray(obj.geometries)) {
@@ -651,7 +653,7 @@ function validatePosition(pos) {
651
653
  return { valid: false, error: `Position must have 2 or 3 coordinates, got ${pos.length}` };
652
654
  }
653
655
  for (let i = 0; i < pos.length; i++) {
654
- if (typeof pos[i] !== 'number' || isNaN(pos[i])) {
656
+ if (typeof pos[i] !== 'number' || !Number.isFinite(pos[i])) {
655
657
  return { valid: false, error: `Position[${i}] must be a valid number` };
656
658
  }
657
659
  }
package/dist/index.esm.js CHANGED
@@ -286,9 +286,9 @@ class WKTParser {
286
286
  }
287
287
  }
288
288
  function parse(wkt) {
289
- const parser = new WKTParser();
290
- return parser.parse(wkt);
289
+ return WKT_PARSER.parse(wkt);
291
290
  }
291
+ const WKT_PARSER = new WKTParser();
292
292
 
293
293
  var wktParser = /*#__PURE__*/Object.freeze({
294
294
  __proto__: null,
@@ -314,14 +314,15 @@ function hasZ(coordinates) {
314
314
  if (coordinates.length === 0)
315
315
  return false;
316
316
  const first = coordinates[0];
317
- if (Array.isArray(first)) {
318
- if (typeof first[0] === 'number') {
319
- return first.length === 3;
320
- }
321
- if (Array.isArray(first[0])) {
322
- const firstRing = first;
323
- return firstRing.length > 0 && firstRing[0].length === 3;
324
- }
317
+ if (typeof first === 'number') {
318
+ return coordinates.length === 3;
319
+ }
320
+ if (Array.isArray(first) && typeof first[0] === 'number') {
321
+ return first.length === 3;
322
+ }
323
+ if (Array.isArray(first) && Array.isArray(first[0])) {
324
+ const firstRing = first;
325
+ return firstRing.length > 0 && firstRing[0].length === 3;
325
326
  }
326
327
  return false;
327
328
  }
@@ -538,6 +539,7 @@ const VALID_GEOMETRY_TYPES = [
538
539
  'MultiPoint', 'MultiLineString', 'MultiPolygon',
539
540
  'GeometryCollection'
540
541
  ];
542
+ const VALID_TYPES_MESSAGE = `Invalid geometry type. Must be one of: ${VALID_GEOMETRY_TYPES.join(', ')}`;
541
543
  function validateWKT(wkt) {
542
544
  if (!wkt || typeof wkt !== 'string') {
543
545
  return { valid: false, error: 'WKT must be a non-empty string' };
@@ -564,7 +566,7 @@ function validateGeoJSON(geojson) {
564
566
  }
565
567
  const type = obj.type;
566
568
  if (!VALID_GEOMETRY_TYPES.includes(type)) {
567
- return { valid: false, error: `Invalid geometry type: "${type}". Must be one of: ${VALID_GEOMETRY_TYPES.join(', ')}` };
569
+ return { valid: false, error: VALID_TYPES_MESSAGE };
568
570
  }
569
571
  if (type === 'GeometryCollection') {
570
572
  if (!obj.geometries || !Array.isArray(obj.geometries)) {
@@ -649,7 +651,7 @@ function validatePosition(pos) {
649
651
  return { valid: false, error: `Position must have 2 or 3 coordinates, got ${pos.length}` };
650
652
  }
651
653
  for (let i = 0; i < pos.length; i++) {
652
- if (typeof pos[i] !== 'number' || isNaN(pos[i])) {
654
+ if (typeof pos[i] !== 'number' || !Number.isFinite(pos[i])) {
653
655
  return { valid: false, error: `Position[${i}] must be a valid number` };
654
656
  }
655
657
  }
package/dist/index.umd.js CHANGED
@@ -292,9 +292,9 @@
292
292
  }
293
293
  }
294
294
  function parse(wkt) {
295
- const parser = new WKTParser();
296
- return parser.parse(wkt);
295
+ return WKT_PARSER.parse(wkt);
297
296
  }
297
+ const WKT_PARSER = new WKTParser();
298
298
 
299
299
  var wktParser = /*#__PURE__*/Object.freeze({
300
300
  __proto__: null,
@@ -320,14 +320,15 @@
320
320
  if (coordinates.length === 0)
321
321
  return false;
322
322
  const first = coordinates[0];
323
- if (Array.isArray(first)) {
324
- if (typeof first[0] === 'number') {
325
- return first.length === 3;
326
- }
327
- if (Array.isArray(first[0])) {
328
- const firstRing = first;
329
- return firstRing.length > 0 && firstRing[0].length === 3;
330
- }
323
+ if (typeof first === 'number') {
324
+ return coordinates.length === 3;
325
+ }
326
+ if (Array.isArray(first) && typeof first[0] === 'number') {
327
+ return first.length === 3;
328
+ }
329
+ if (Array.isArray(first) && Array.isArray(first[0])) {
330
+ const firstRing = first;
331
+ return firstRing.length > 0 && firstRing[0].length === 3;
331
332
  }
332
333
  return false;
333
334
  }
@@ -544,6 +545,7 @@
544
545
  'MultiPoint', 'MultiLineString', 'MultiPolygon',
545
546
  'GeometryCollection'
546
547
  ];
548
+ const VALID_TYPES_MESSAGE = `Invalid geometry type. Must be one of: ${VALID_GEOMETRY_TYPES.join(', ')}`;
547
549
  function validateWKT(wkt) {
548
550
  if (!wkt || typeof wkt !== 'string') {
549
551
  return { valid: false, error: 'WKT must be a non-empty string' };
@@ -570,7 +572,7 @@
570
572
  }
571
573
  const type = obj.type;
572
574
  if (!VALID_GEOMETRY_TYPES.includes(type)) {
573
- return { valid: false, error: `Invalid geometry type: "${type}". Must be one of: ${VALID_GEOMETRY_TYPES.join(', ')}` };
575
+ return { valid: false, error: VALID_TYPES_MESSAGE };
574
576
  }
575
577
  if (type === 'GeometryCollection') {
576
578
  if (!obj.geometries || !Array.isArray(obj.geometries)) {
@@ -655,7 +657,7 @@
655
657
  return { valid: false, error: `Position must have 2 or 3 coordinates, got ${pos.length}` };
656
658
  }
657
659
  for (let i = 0; i < pos.length; i++) {
658
- if (typeof pos[i] !== 'number' || isNaN(pos[i])) {
660
+ if (typeof pos[i] !== 'number' || !Number.isFinite(pos[i])) {
659
661
  return { valid: false, error: `Position[${i}] must be a valid number` };
660
662
  }
661
663
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wkt-parse-and-geojson",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "type": "module",
5
5
  "description": "Zero-dependency WKT parser/builder and WKT↔GeoJSON converter",
6
6
  "main": "dist/index.cjs.js",