Skip to content

Commit

Permalink
bugfix: ignore whitespaces in sexagesimal patterns. fixes #254
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbieh committed Mar 29, 2021
1 parent 28ea1d8 commit 47850ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/sexagesimalToDecimal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@ describe('sexagesimalToDecimal', () => {

expect(sexagesimalToDecimal('51°15′13"N')).toEqual(51.25361111111111);
});

it('trims whitespace', () => {
expect(sexagesimalToDecimal('19° 22\' 32" S ')).toEqual(
-19.375555555555557
);

expect(sexagesimalToDecimal(' 19° 22\' 32" S')).toEqual(
-19.375555555555557
);
});
});
4 changes: 2 additions & 2 deletions src/sexagesimalToDecimal.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { sexagesimalPattern } from './constants';

// Converts a sexagesimal coordinate to decimal format
const sexagesimalToDecimal = (sexagesimal: any) => {
const data = new RegExp(sexagesimalPattern).exec(sexagesimal);
const sexagesimalToDecimal = (sexagesimal: string) => {
const data = new RegExp(sexagesimalPattern).exec(sexagesimal.trim());

if (typeof data === 'undefined' || data === null) {
throw new Error('Given value is not in sexagesimal format');
Expand Down

0 comments on commit 47850ea

Please sign in to comment.