Skip to content

Commit e9cad78

Browse files
committed
Allow 'deg' in lat/lon format
1 parent f2efd5c commit e9cad78

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ test:
77
@nodemon --exec "make test-once --quiet" --ext "coffee,js" --quiet
88

99
test-once:
10-
@mocha --compilers coffee:coffee-script/register
10+
@mocha --require coffeescript/register --ext "coffee,js" 'test/**/*.coffee'
1111

src/coordinates.coffee

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ class Coordinates
3131

3232
extractCoordinateNumbers: (coordinates) ->
3333
return coordinates.match(/-?\d+(\.\d+)?/g)
34-
35-
34+
3635
extractLatitude: ->
3736
latitude = @coordinateNumbersToDecimal(@latitudeNumbers)
3837
if @latitudeIsNegative()

src/validator.coffee

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ class Validator
1010

1111

1212
validate: (coordinates) ->
13-
@checkContainsNoLetters(coordinates)
14-
@checkValidOrientation(coordinates)
15-
@checkNumbers(coordinates)
13+
cleaned = @removeKnownStrings(coordinates)
14+
@checkContainsNoLetters(cleaned)
15+
@checkValidOrientation(cleaned)
16+
@checkNumbers(cleaned)
1617

1718

1819
checkContainsNoLetters: (coordinates) ->
@@ -21,6 +22,10 @@ class Validator
2122
throw new Error('Coordinate contains invalid alphanumeric characters.')
2223

2324

25+
removeKnownStrings: (coordinates) ->
26+
coordinates.replace(/\bdeg\b/gi, '')
27+
28+
2429
checkValidOrientation: (coordinates) ->
2530
validOrientation = /^[^nsew]*[ns]?[^nsew]*[ew]?[^nsew]*$/i.test(coordinates)
2631
if not validOrientation

test/parser.test.coffee

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ expectation =
2525
"40°25’6\"N 74°38’28\"W"
2626
"40°25’6\" -74°38’28\""
2727
"40d 25’ 6\" N 74d 38’ 28\" W"
28+
"40 deg 25' 6\" N, 74 deg 38’ 28\" W"
29+
"40 deg 25' 6\", -74 deg 38’ 28\""
2830
"40.4183318N 74.6411133W"
2931
"40° 25.0999, -74° 38.4668"
3032
]
@@ -52,6 +54,8 @@ reversedExpectation =
5254
"40°25’6\"S 74°38’28\"E"
5355
"-40°25’6\" 74°38’28\""
5456
"40d 25’ 6\" S 74d 38’ 28\" E"
57+
"40 deg 25' 6\" S, 74 deg 38’ 28\" E"
58+
"-40 deg 25' 6\", 74 deg 38’ 28\""
5559
"40.4183318S 74.6411133E"
5660
"40.4183318S 74.6411133"
5761
"-40° 25.0999, 74° 38.4668"
@@ -79,6 +83,8 @@ invalidFormats = [
7983
"40.1° W 60.1° W"
8084
"40.1° N 60.1° N"
8185
"-40.4183318, 12.345, 74.6411133"
86+
"-40 degrees 25' 6\", 74 degrees 38’ 28\""
87+
"-40 degN 25' 6\", 74 degW 38’ 28\""
8288
]
8389

8490

0 commit comments

Comments
 (0)