# @mapbox/sexagesimal

> parse coordinates in sexagesimal form

Latest version **1.2.0** (published 2019-08-05) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install @mapbox/sexagesimal
pnpm add @mapbox/sexagesimal
yarn add @mapbox/sexagesimal
bun add @mapbox/sexagesimal
```

Provides the command `sexagesimal`.

## Health

**Score 33/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2019-08-05 |
| First published | 2017-02-13 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | separate (@types/mapbox__sexagesimal) |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 0 |
| Unpacked size | 13.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 34 |
| Author | Tom MacWright |
| Maintainers | mapbox-admin, mapbox-machine-user, mapbox-npm, mapbox-npm-01, mapbox-npm-02, mapbox-npm-03, mapbox-npm-04, mapbox-npm-05, mapbox-npm-06, mapbox-npm-07, mapbox-npm-08, mapbox-npm-09, mapbox-npm-advanced-actions, mapbox-npm-ci |
| Keywords | coordinates, sexagesimal |

## Links

- npm: https://www.npmjs.com/package/@mapbox/sexagesimal
- Repository: https://github.com/mapbox/sexagesimal
- Homepage: https://github.com/mapbox/sexagesimal#readme
- Issues: https://github.com/mapbox/sexagesimal/issues
- npm.io page: https://npm.io/package/@mapbox/sexagesimal

## Recent versions

- 1.2.0 (latest) — 2019-08-05
- 1.1.0 — 2017-08-23
- 1.0.0 — 2017-02-13

## README

[![npm version](https://badge.fury.io/js/%40mapbox%2Fsexagesimal.svg)](https://badge.fury.io/js/%40mapbox%2Fsexagesimal)
[![Build Status](https://travis-ci.org/mapbox/sexagesimal.svg)](https://travis-ci.org/mapbox/sexagesimal)

## sexagesimal

Convert between [sexagesimal coordinates](http://en.wikipedia.org/wiki/Sexagesimal) and
decimal coordinates.

### Usage

with npm (and/or) browserify

    npm install @mapbox/sexagesimal

otherwise

    curl https://raw.github.com/mapbox/sexagesimal/master/sexagesimal.js

### Examples

```js
var sexagesimal = require('sexagesimal');

// Converting a single DMS coordinate:

sexagesimal('40° 42′ 45.72″ N');  // direction after
// 40.712700000000005
sexagesimal('N40° 42′ 45.72″');   // direction before
// 40.712700000000005
sexagesimal('N40°42′45.72″');     // flexible whitespace
// 40.712700000000005

// Converting a coordinate pair from DMS to lat/lng:

sexagesimal.pair('40° 42′ 45.72″ N, 74° 0′ 21.24″ W');   // direction after
// [ 40.712700000000005, -74.0059 ]
sexagesimal.pair('N 40° 42′ 45.72″, W 74° 0′ 21.24″');   // direction before
// [ 40.712700000000005, -74.0059 ]

// Converting a lat/lon coordinate to DMS:

sexagesimal.coordToDMS(40.71270000000000, 'lat');
// { whole: 40, minutes: 42, seconds: 45, dir: 'N' }
sexagesimal.coordToDMS(-74.0059, 'lon');
// { whole: 74, minutes: 0, seconds: 21, dir: 'W' }


```

### API

```js
sexagesimal(str, dims) // returns a number or null
```

`dims` is by default `NSEW` but can be other ordinal directions expressed
as a string of characters.

```js
sexagesimal.pair(str, dims) // returns [lat, lon] or null
```

`dims` is by default `NSEW` but can be other ordinal directions expressed
as a string of characters.

```js
sexagesimal.format(float, dimension) // returns a formatted string
```

Format a single sexagesimal number. `dimension` must be a string, either
`"lat"` or `"lon"`.

```js
sexagesimal.formatPair({ lat: float, lon: float }) // returns a formatted string
```

Format a sexagesimal coordinate.

---
_Source: https://npm.io/package/@mapbox/sexagesimal · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
