diff --git a/README.md b/README.md index 00559cf..23015cc 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ const parser = new Parser({ formatParsers: [customFormatParser, decimalParser] } ### Supported Formats -Currently the out-of-the-box format parsers supports various formats and handles their various variations ,e.g. with or without whitespaces, gracefully: +Currently the out-of-the-box format parsers supports various formats and handles their various variations, i.e. with or without whitespaces and comma, gracefully: - `1° 5°` - `1.234° 5.678°` @@ -107,6 +107,12 @@ Currently the out-of-the-box format parsers supports various formats and handles - `N 4007.38 W 7407.38` - `4007 N 7407 W` - `4007.38 N 7407.38 W` +- `40°7'23" -74°7'23"` +- `40°7'23", -74°7'23"` +- `40°7'23.123", -74°7'23.123"` +- `` +- `` +- `` - `` - `` - `` diff --git a/src/parser.ts b/src/parser.ts index 9f898c3..0270c05 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -8,6 +8,7 @@ import { DecimalUnsignedPrefixedHemisphereFormat } from './formats/decimal-unsig import { DecimalUnsignedSuffixedHemisphereFormat } from './formats/decimal-unsigned-suffixed-hemisphere-format.js'; import { DmUnsignedPrefixedHemisphereFormat } from './formats/dm-unsigned-prefixed-hemisphere-format.js'; import { DmUnsignedSuffixedHemisphereFormat } from './formats/dm-unsigned-suffixed-hemisphere-format.js'; +import { DmsSignedFormat } from './formats/dms-signed-format.js'; import type { Coordinate } from './types.js'; import { validateSchema } from './validate-schema.js'; @@ -52,6 +53,7 @@ export class Parser { new DecimalSignedSuffixedHemisphereFormat({ precision: precision }), new DmUnsignedPrefixedHemisphereFormat({ precision: precision }), new DmUnsignedSuffixedHemisphereFormat({ precision: precision }), + new DmsSignedFormat({ precision: precision }), ]; let formatParsers = options?.formatParsers || defaultParsers; if (formatParsers.length > 0 && extendFormatParsers === true) { diff --git a/tests/parser.test.ts b/tests/parser.test.ts index 3a8edb6..73b749c 100644 --- a/tests/parser.test.ts +++ b/tests/parser.test.ts @@ -290,4 +290,50 @@ describe('Test that all configured format parsers do not interfere', () => { expect(result.longitude).toBe(-74.123); }); }); + + describe('test dsm signed format', () => { + it(`returns the correct latitude and longitude for 40°7'23" -74°7'23"`, () => { + const parser = new Parser(); + const result = parser.parse(`40°7'23" -74°7'23"`); + expect(result.latitude).toBe(40.123); + expect(result.longitude).toBe(-74.123); + }); + + it(`returns the correct latitude and longitude for 40°7'23", -74°7'23"`, () => { + const parser = new Parser(); + const result = parser.parse(`40°7'23", -74°7'23"`); + expect(result.latitude).toBe(40.123); + expect(result.longitude).toBe(-74.123); + }); + + it(`returns the correct latitude and longitude for 40°7'23",-74°7'23"`, () => { + const parser = new Parser(); + const result = parser.parse(`40°7'23",-74°7'23"`); + expect(result.latitude).toBe(40.123); + expect(result.longitude).toBe(-74.123); + }); + + it(`returns the correct latitude and longitude for 40° 7' 23" -74° 7' 23"`, () => { + const parser = new Parser(); + const result = parser.parse(`40° 7' 23" -74° 7' 23"`); + expect(result.latitude).toBe(40.123); + expect(result.longitude).toBe(-74.123); + }); + + it(`returns the correct latitude and longitude for 40° 7' 23", -74° 7' 23"`, () => { + const parser = new Parser(); + const result = parser.parse(`40° 7' 23", -74° 7' 23"`); + expect(result.latitude).toBe(40.123); + expect(result.longitude).toBe(-74.123); + }); + + it(`returns the correct latitude and longitude for 40° 7' 23.9999", -74° 7' 23.9999"`, () => { + const parser = new Parser({ precision: 5 }); + const result = parser.parse(`40° 7' 23.9999", -74° 7' 23.9999"`); + + expect(result.latitude).toBe(40.12333); + expect(result.longitude).toBe(-74.12333); + }); + }); + // describe('test', () => {}); });