Socket
Socket
Sign inDemoInstall

geo-coordinates-parser

Package Overview
Dependencies
0
Maintainers
0
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.7.1 to 1.7.2

24

dist/cjs/converter.js

@@ -26,2 +26,3 @@ "use strict";

let lngdir = "";
let originalFormat = null;
let match = [];

@@ -41,2 +42,3 @@ let matchSuccess = false;

}
originalFormat = "DM";
}

@@ -60,2 +62,3 @@ else {

}
originalFormat = "DD";
//validation, we don't want things like 23.00000

@@ -90,5 +93,7 @@ //some more validation: no zero coords or degrees only

ddLat += match[4] / 60;
originalFormat = "DM";
}
if (match[6]) {
ddLat += match[6].replace(',', '.') / 3600;
originalFormat = "DMS";
}

@@ -129,5 +134,7 @@ if (parseInt(match[2]) < 0) {

ddLat += match[4] / 60;
originalFormat = "DM";
}
if (match[6]) {
ddLat += match[6] / 3600;
originalFormat = "DMS";
}

@@ -168,5 +175,7 @@ if (parseInt(match[2]) < 0) {

ddLat += match[4].replace(',', '.') / 60;
originalFormat = "DM";
}
if (match[6]) {
ddLat += match[6].replace(',', '.') / 3600;
originalFormat = "DMS";
}

@@ -218,2 +227,9 @@ if (parseInt(match[2]) < 0) {

}
// a bit of tidying up...
if (ddLat.toString().includes(',')) {
ddLat = ddLat.replace(',', '.');
}
if (ddLng.toString().includes(',')) {
ddLng = ddLng.replace(',', '.');
}
//make sure the signs and cardinal directions match

@@ -294,9 +310,2 @@ let patt = /S|SOUTH/i;

}
// last bit of tidying up...
if (isNaN(ddLat) && ddLat.includes(',')) {
ddLat = ddLat.replace(',', '.');
}
if (isNaN(ddLng) && ddLng.includes(',')) {
ddLng = ddLng.replace(',', '.');
}
//all done!!

@@ -313,2 +322,3 @@ //just truncate the decimals appropriately

decimalCoordinates: `${ddLat},${ddLng}`,
originalFormat,
closeEnough: coordsCloseEnough,

@@ -315,0 +325,0 @@ toCoordinateFormat: toCoordinateFormat_js_1.default

@@ -31,4 +31,8 @@ "use strict";

if (format == 'DM') {
const dmMinsLatitude = round(minutesLatitudeNotTruncated, 3).toFixed(3).padStart(6, '0');
const dmMinsLongitude = round(minutesLongitudeNotTruncated, 3).toFixed(3).padStart(6, '0');
let dmMinsLatitude = round(minutesLatitudeNotTruncated, 3).toFixed(3).padStart(6, '0');
let dmMinsLongitude = round(minutesLongitudeNotTruncated, 3).toFixed(3).padStart(6, '0');
if (dmMinsLatitude.endsWith('.000') && dmMinsLongitude.endsWith('.000')) {
dmMinsLatitude = dmMinsLatitude.replace(/\.000$/, '');
dmMinsLongitude = dmMinsLongitude.replace(/\.000$/, '');
}
result = `${degreesLatitude}° ${dmMinsLatitude}' ${latDir}, ${degreesLongitude}° ${dmMinsLongitude}' ${longDir}`;

@@ -44,5 +48,5 @@ }

// if they both end in .0 we drop the .0
if (latSeconds.endsWith('.0"') && longSeconds.endsWith('.0"')) {
latSeconds = latSeconds.replace(/\.0"$/, '"');
longSeconds = longSeconds.replace(/\.0"$/, '"');
if (latSeconds.endsWith('.0') && longSeconds.endsWith('.0')) {
latSeconds = latSeconds.replace(/\.0$/, '');
longSeconds = longSeconds.replace(/\.0$/, '');
}

@@ -49,0 +53,0 @@ result = `${degreesLatitude}° ${latMinutesString}' ${latSeconds}" ${latDir}, ${degreesLongitude}° ${longMinutesString}' ${longSeconds}" ${longDir}`;

@@ -21,2 +21,3 @@ //function for converting coordinates from a string to decimal and verbatim

let lngdir = "";
let originalFormat = null;
let match = [];

@@ -36,2 +37,3 @@ let matchSuccess = false;

}
originalFormat = "DM";
}

@@ -55,2 +57,3 @@ else {

}
originalFormat = "DD";
//validation, we don't want things like 23.00000

@@ -85,5 +88,7 @@ //some more validation: no zero coords or degrees only

ddLat += match[4] / 60;
originalFormat = "DM";
}
if (match[6]) {
ddLat += match[6].replace(',', '.') / 3600;
originalFormat = "DMS";
}

@@ -124,5 +129,7 @@ if (parseInt(match[2]) < 0) {

ddLat += match[4] / 60;
originalFormat = "DM";
}
if (match[6]) {
ddLat += match[6] / 3600;
originalFormat = "DMS";
}

@@ -163,5 +170,7 @@ if (parseInt(match[2]) < 0) {

ddLat += match[4].replace(',', '.') / 60;
originalFormat = "DM";
}
if (match[6]) {
ddLat += match[6].replace(',', '.') / 3600;
originalFormat = "DMS";
}

@@ -213,2 +222,9 @@ if (parseInt(match[2]) < 0) {

}
// a bit of tidying up...
if (ddLat.toString().includes(',')) {
ddLat = ddLat.replace(',', '.');
}
if (ddLng.toString().includes(',')) {
ddLng = ddLng.replace(',', '.');
}
//make sure the signs and cardinal directions match

@@ -289,9 +305,2 @@ let patt = /S|SOUTH/i;

}
// last bit of tidying up...
if (isNaN(ddLat) && ddLat.includes(',')) {
ddLat = ddLat.replace(',', '.');
}
if (isNaN(ddLng) && ddLng.includes(',')) {
ddLng = ddLng.replace(',', '.');
}
//all done!!

@@ -308,2 +317,3 @@ //just truncate the decimals appropriately

decimalCoordinates: `${ddLat},${ddLng}`,
originalFormat,
closeEnough: coordsCloseEnough,

@@ -310,0 +320,0 @@ toCoordinateFormat

@@ -29,4 +29,8 @@ //borrowed from https://www.codegrepper.com/code-examples/javascript/javascript+converting+latitude+longitude+to+gps+coordinates

if (format == 'DM') {
const dmMinsLatitude = round(minutesLatitudeNotTruncated, 3).toFixed(3).padStart(6, '0');
const dmMinsLongitude = round(minutesLongitudeNotTruncated, 3).toFixed(3).padStart(6, '0');
let dmMinsLatitude = round(minutesLatitudeNotTruncated, 3).toFixed(3).padStart(6, '0');
let dmMinsLongitude = round(minutesLongitudeNotTruncated, 3).toFixed(3).padStart(6, '0');
if (dmMinsLatitude.endsWith('.000') && dmMinsLongitude.endsWith('.000')) {
dmMinsLatitude = dmMinsLatitude.replace(/\.000$/, '');
dmMinsLongitude = dmMinsLongitude.replace(/\.000$/, '');
}
result = `${degreesLatitude}° ${dmMinsLatitude}' ${latDir}, ${degreesLongitude}° ${dmMinsLongitude}' ${longDir}`;

@@ -42,5 +46,5 @@ }

// if they both end in .0 we drop the .0
if (latSeconds.endsWith('.0"') && longSeconds.endsWith('.0"')) {
latSeconds = latSeconds.replace(/\.0"$/, '"');
longSeconds = longSeconds.replace(/\.0"$/, '"');
if (latSeconds.endsWith('.0') && longSeconds.endsWith('.0')) {
latSeconds = latSeconds.replace(/\.0$/, '');
longSeconds = longSeconds.replace(/\.0$/, '');
}

@@ -47,0 +51,0 @@ result = `${degreesLatitude}° ${latMinutesString}' ${latSeconds}" ${latDir}, ${degreesLongitude}° ${longMinutesString}' ${longSeconds}" ${longDir}`;

{
"name": "geo-coordinates-parser",
"version": "1.7.1",
"version": "1.7.2",
"description": "A Javascript function for reading a variety of coordinate formats and converting to decimal numbers. Builds on other efforts by returning the verbatim coordinates and the decimal coordinates all in one object.",

@@ -5,0 +5,0 @@ "type": "module",

@@ -49,2 +49,4 @@ # Geo Coordinates Parser

converted.verbatimLongitude; // '-79° 56.93172' ✓
converted.decimalCoordinates; // for convenience
convert.originalFormat; // 'DM' to indicate degrees and minutes
```

@@ -51,0 +53,0 @@ The returned object includes properties verbatimCoordinates, verbatimLatitude, verbatimLongitude, decimalLatitude, decimalLatitude, and decimalCoordinates.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc