npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

formatcoords

v1.1.3

Published

format decimal lat/lon coords into degrees/minutes/seconds formats (like DMS).

Downloads

66,570

Readme

formatcoords Build Status

A simple and flexible tool to format decimal lat/lon coordinates into degrees/minutes/seconds formats (like DMS), using a moment.js-like API.

For geo hipsters that think that 48° 54′ 16.016″ S 71° 0′ 56.250″ W looks way more awesome than -48.9044488,-71.015625.

install: node/browserify

npm install formatcoords

use

var formatcoords = require('formatcoords');
formatcoords(40.76,-73.984).format();
//40° 45′ 36.000″ N 73° 59′ 2.400″ W

parsing

The formatcoords(coord1[, coord2, lonlat]) method accepts decimal lat/lon coordinates in several formats :

  • formatcoords([lat, lon]): an array of floats.
  • formatcoords([lon, lat], true): an array of floats. First longitude, then latitude. Useful for use with GeoJSON, for example.
  • formatcoords(lat, lon) : floats.
  • formatcoords(lon, lat, true) : floats. First longitude, then latitude. Useful for use with GeoJSON, for example.
  • formatcoords('latlon') : latlon is a string in "lat,lon" format.
  • formatcoords({lat: lat, lng: lon} an object with lat and lng properties (Leaflet LatLng object)

formatting

var coords = formatcoords(27.725499,-18.024301);
coords.format(format, {options})

Default output format is DMS (degrees minutes seconds), with a space to separate lat and lon, and 5 decimal places :

coords.format()
//27° 43′ 31.796″ N 18° 1′ 27.484″ W

Available short formats:

| | Token | Output | |----------------------:|:--------|--------| |degrees minutes seconds (DMS)|FFf |27° 43′ 31.796″ N 18° 1′ 27.484″ W | |degrees decimal minutes|Ff |27° 43.529933333333′ N -18° 1.4580666666667′ W | |decimal degrees |f |27.725499° N 18.024301° W |

Custom formats:

The following values are available for both latitudes and longitudes:

| | Token | Output | |------------------------------:|:--------|--------| |degrees |D |27 | |degrees with unit |DD |27° | |decimal degrees |d |27.725499 | |decimal degrees with unit |dd |27.725499° | |minutes |M |7 | |minutes with unit |MM |7′ | |decimal minutes |m |7.63346 | |decimal minutes with unit |mm |7.63346′ | |decimal seconds |s |31.796 | |decimal seconds with unit |ss |31.796″ | |direction |X |[N,S], [E,W] | |minus sign (west of Greenwich and south of equator)|- |[-] |

Custom format example

coord.format('-D M s');
//-35 16 55.20000 149 7 43.26240
options

| Option Name | Description | Default & type | |-------------------------:|:--------------|---------| |latLonSeparator | The separator to use between the lat and lon values | ' ' string | |decimalPlaces | The number of decimal places to return | 5 number|

Custom format example with additional options

coord.format('DD MM ss X', {latLonSeparator: ', ',  decimalPlaces: 0);
//35° 43′ 49″ S, 86° 1′ 55″ E

Browser support

IE <= 8 not supported.

DMS to decimal

Use parse-dms.