Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

geo-coordinates-parser

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geo-coordinates-parser - npm Package Compare versions

Comparing version 1.5.0 to 1.5.1

142

converter.js

@@ -41,8 +41,20 @@ //function for converting coordinates from a string to decimal and verbatim

}
//validation, we don't want things like 23.00000
//some more validation: no zero coords or degrees only
if (Number(Math.round(ddLat)) == Number(ddLat)) {
throw new Error('degree only coordinate provided')
}
if (Number(Math.round(ddLng)) == Number(ddLng)) {
throw new Error('degree only coordinate provided')
}
//get directions
if(match[1]){
if(match[1]) {
latdir = match[1];
lngdir = match[5];
} else if (match[4]){
}
else if (match[4]) {
latdir = match[4];

@@ -62,21 +74,37 @@ lngdir = match[8];

if (matchSuccess){
ddLat = Math.abs(parseInt(match[2]));
if (match[4])
if (match[4]) {
ddLat += match[4]/60;
if (match[6])
}
if (match[6]){
ddLat += match[6]/3600;
if (parseInt(match[2]) < 0) //needed to
}
if (parseInt(match[2]) < 0) {
ddLat = -1 * ddLat;
}
ddLng = Math.abs(parseInt(match[9]));
if (match[11])
if (match[11]) {
ddLng += match[11]/60;
if (match[13])
}
if (match[13]) {
ddLng += match[13]/3600;
if (parseInt(match[9]) < 0) //needed to
}
if (parseInt(match[9]) < 0) {
ddLng = -1 * ddLng;
if(match[1]){
}
//the compass directions
if(match[1]) {
latdir = match[1];
lngdir = match[8];
} else if (match[7]){
}
else if (match[7]) {
latdir = match[7];

@@ -94,35 +122,48 @@ lngdir = match[14];

matchSuccess = checkMatch(match);
if (matchSuccess){
if (matchSuccess) {
ddLat = Math.abs(parseInt(match[2]));
if (match[4]){
if (match[4]) {
ddLat += match[4]/60;
if(!match[3])
if(!match[3]) {
match[3] = ' ';
}
}
if (match[6]) {
ddLat += match[6]/3600;
if(!match[5])
if(!match[5]) {
match[5] = ' ';
}
}
if (parseInt(match[2]) < 0)
if (parseInt(match[2]) < 0) {
ddLat = -1 * ddLat;
}
ddLng = Math.abs(parseInt(match[10]));
if (match[12]){
if (match[12]) {
ddLng += match[12]/60;
if(!match[11])
if(!match[11]) {
match[11] = ' ';
}
}
if (match[14]){
if (match[14]) {
ddLng += match[14]/3600;
if(!match[13])
if(!match[13]) {
match[13] = ' ';
}
}
if (parseInt(match[10]) < 0)
if (parseInt(match[10]) < 0) {
ddLng = -1 * ddLng;
}
if(match[1]){
if(match[1]) {
latdir = match[1];
lngdir = match[9];
}
else if (match[8]){
else if (match[8]) {
latdir = match[8];

@@ -140,35 +181,46 @@ lngdir = match[16];

matchSuccess = checkMatch(match);
if (matchSuccess){
if (matchSuccess) {
ddLat = Math.abs(parseInt(match[2]));
if (match[4]){
ddLat += match[4]/60;
if(!match[3])
if(!match[3]) {
match[3] = ' ';
}
}
if (match[6]) {
ddLat += match[6]/3600;
if(!match[5])
if(!match[5]) {
match[5] = ' ';
}
}
if (parseInt(match[2]) < 0)
if (parseInt(match[2]) < 0) {
ddLat = -1 * ddLat;
}
ddLng = Math.abs(parseInt(match[10]));
if (match[12]){
if (match[12]) {
ddLng += match[12]/60;
if(!match[11])
if(!match[11]) {
match[11] = ' ';
}
}
if (match[14]){
if (match[14]) {
ddLng += match[14]/3600;
if(!match[13])
if(!match[13]) {
match[13] = ' ';
}
}
if (parseInt(match[10]) < 0)
if (parseInt(match[10]) < 0) {
ddLng = -1 * ddLng;
if(match[1]){
}
if(match[1]) {
latdir = match[1];
lngdir = match[9];
} else if (match[8]){
} else if (match[8]) {
latdir = match[8];

@@ -184,19 +236,11 @@ lngdir = match[16];

if (ddLat == 0.0 || ddLng == 0.0) {
throw new Error('zero coordinate/s provided')
//check longitude value - it can be wrong!
if (Math.abs(ddLng) >= 180) {
throw new Error("invalid longitude value")
}
//some more validation: no zero coords or degrees only
if (Number(Math.round(ddLat)) == Number(ddLat)) {
throw new Error('degree only coordinate provided')
//just to be safe check latitude also...
if (Math.abs(ddLng) >= 90) {
throw new Error("invalid latitude value")
}
if (Number(Math.round(ddLng)) == Number(ddLng)) {
throw new Error('degree only coordinate provided')
}
//check longitude value - it can be wrong!
if (Math.abs(ddLng) >=180) {
throw new Error("invalid longitude value")
}

@@ -203,0 +247,0 @@ if (matchSuccess){

//TODO These formats should throw...
const failingFormats = [
'N 52d12m42s E 000d0m0s', //degree only coordinate and zero coordinate
'N49 0.000 E02 33.314', //degree only coordinate
'0,0', //another zero coordinate, numbers only
'0, 24.34532', //zero coordinate on one size only
'50°4\'17.698"south, 24.34532', //different formats on each side
'90°4\'17.698"south, 23°4\'17.698"east',
'50°4\'17.698"east, 23°4\'17.698"south',
]
module.exports = failingFormats
{
"name": "geo-coordinates-parser",
"version": "1.5.0",
"version": "1.5.1",
"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 @@ "main": "merge.js",

@@ -228,3 +228,10 @@ //return an array of coordinate strings for testing

decimalLongitude: -74.123256
}
},
{
verbatimCoordinates: '18°24S 22°45E', //this is read as degrees and minutes
verbatimLatitude: '18°24S',
verbatimLongitude: '22°45E',
decimalLatitude: -18.4,
decimalLongitude: 22.75
}
]

@@ -231,0 +238,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc