@osimatic/helpers-js 1.4.14 → 1.4.15

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 (2) hide show
  1. package/location.js +18 -19
  2. package/package.json +1 -1
package/location.js CHANGED
@@ -429,9 +429,7 @@ class PostalAddress {
429
429
 
430
430
  class Polygon {
431
431
  static format(geoJsonPolygon) {
432
- if (typeof geoJsonPolygon == 'string') {
433
- geoJsonPolygon = JSON.parse(geoJsonPolygon);
434
- }
432
+ geoJsonPolygon = typeof geoJsonPolygon == 'string' ? JSON.parse(geoJsonPolygon) : geoJsonPolygon;
435
433
 
436
434
  const rings = geoJsonPolygon.coordinates || [];
437
435
  const ring0 = rings[0] || [];
@@ -452,10 +450,8 @@ class Polygon {
452
450
  };
453
451
  }
454
452
 
455
- static getStartCoordinates(geoJsonPolygon) {
456
- if (typeof geoJsonPolygon == 'string') {
457
- geoJsonPolygon = JSON.parse(geoJsonPolygon);
458
- }
453
+ static getStartCoordinates(geoJsonPolygon, asString=false) {
454
+ geoJsonPolygon = typeof geoJsonPolygon == 'string' ? JSON.parse(geoJsonPolygon) : geoJsonPolygon;
459
455
 
460
456
  const rings = geoJsonPolygon.coordinates || [];
461
457
  const ring0 = rings[0] || [];
@@ -464,7 +460,7 @@ class Polygon {
464
460
  }
465
461
 
466
462
  const [firstLon, firstLat] = ring0[0];
467
- return [firstLat, firstLon];
463
+ return asString ? str.join(',') : [firstLat, firstLon];
468
464
  }
469
465
 
470
466
  static convertToGeoJson(latlngs) {
@@ -491,9 +487,7 @@ class Polygon {
491
487
  }
492
488
 
493
489
  static toLatLngRings(geoJsonPolygon) {
494
- if (typeof geoJsonPolygon == 'string') {
495
- geoJsonPolygon = JSON.parse(geoJsonPolygon);
496
- }
490
+ geoJsonPolygon = typeof geoJsonPolygon == 'string' ? JSON.parse(geoJsonPolygon) : geoJsonPolygon;
497
491
 
498
492
  const polygonCoords = geoJsonPolygon.coordinates;
499
493
  if (!Array.isArray(polygonCoords) || polygonCoords.length === 0) {
@@ -631,11 +625,7 @@ class GeographicCoordinates {
631
625
  }
632
626
 
633
627
  static formatPoint(geoJsonPoint, fractionDigit=6) {
634
- if (typeof geoJsonPoint == 'string') {
635
- geoJsonPoint = JSON.parse(geoJsonPoint);
636
- }
637
-
638
- const [long, lat] = geoJsonPoint.coordinates || [];
628
+ const [long, lat] = GeographicCoordinates.parseFromGeoJson(geoJsonPoint);
639
629
  if (typeof long == 'undefined' || typeof lat == 'undefined') {
640
630
  return '';
641
631
  }
@@ -646,11 +636,20 @@ class GeographicCoordinates {
646
636
  return { type: 'Point', coordinates: [Number(long), Number(lat)] };
647
637
  }
648
638
 
649
- static getAllLatLongsFromGeoJsonList(geoJsonList) {
650
- if (typeof geoJsonList == 'string') {
651
- geoJsonList = JSON.parse(geoJsonList);
639
+ static parseFromGeoJson(geoJsonPoint, asString=false) {
640
+ geoJsonPoint = typeof geoJsonPoint == 'string' ? JSON.parse(geoJsonPoint) : geoJsonPoint;
641
+
642
+ const [long, lat] = geoJsonPoint.coordinates || [];
643
+ if (typeof long == 'undefined' || typeof lat == 'undefined') {
644
+ return null;
652
645
  }
653
646
 
647
+ return asString ? str.join(',') : [lat, lon];
648
+ }
649
+
650
+ static getAllLatLongsFromGeoJsonList(geoJsonList) {
651
+ geoJsonList = typeof geoJsonList == 'string' ? JSON.parse(geoJsonList) : geoJsonList;
652
+
654
653
  const arr = [];
655
654
  for (const geoJsonItem of geoJsonList) {
656
655
  if (!geoJsonItem) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.4.14",
3
+ "version": "1.4.15",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"