1.1.4 • Published 6 years ago

dmsformat v1.1.4

Weekly downloads
38
License
MIT
Repository
-
Last release
6 years ago

dmsformat

This is a small library which lets you convert from decimal lon/lat coordinates to dms (date-minute-second) format and back. It is mainly an attempt to merge the functionality of formatcoords and parse-dms behind a single API.

Usage

import { fromDMS, toDMS } from 'dmsformat';

// parse a decimal coordinate from a dms string 
const coordinate = fromDMS('59°12\'7.7"N 02°15\'39.6"W') // should be [ -2.261, 59.20213888888889 ]


// format a decimal coordinate to a dms string
const dmsString = toDMS([-2.261, 59.20213888888889]) // should be '59°12\'7.7"N 02°15\'39.6"W'

fromDMS(value)

The function fromDMS(value) always expect a valid dms string in the order latitude, longitude. It returns a lon, lat coordinate array.

toDMS(coordinate, ?format, ?options)

The function toDMS(coordinate, ?format, ?options) always expect a valid lon, lat coordinate array. format should be a format string and options an options object.

Example formats:
FormatOutput
degrees minutes seconds (default)DD MM ss X27° 43′ 31.796″ N 18° 1′ 27.484″ W
degrees decimal minutesDD mm X27° 43.529933333333′ N -18° 1.4580666666667′ W
decimal degreesdd X27.725499° N 18.024301° W
Custom formats:

The following values are available for both latitudes and longitudes:

TokenOutput
degreesD27
degrees with unitDD27°
decimal degreesd27.725499
decimal degrees with unitdd27.725499°
minutesM7
minutes with unitMM7′
decimal minutesm7.63346
decimal minutes with unitmm7.63346′
decimal secondss31.796
decimal seconds with unitss31.796″
directionXN,S, E,W
minus sign (west of Greenwich and south of equator)--
Options
Option NameDescriptionDefault & type
latLonSeparatorThe separator to use between the lat and lon values' ' string
decimalPlacesThe number of decimal places to return5 number

See src/dmsformat.test.js for more details on what the functions can do.

Browser support

IE <= 8 not supported.

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago