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

utm-coordinate-parser

v1.1.0

Published

Parse UTM northing and easting from text input

Downloads

222

Readme

utm-coordinate-parser

Parse northing and easting from various UTM coordinate string formats in your JavaScript projects. UTM, abbreviation of Universal Transverse Mercator, is a popular zoned coordinate system and used as the default coordinate system in many countries including Sweden and Finland. In contrast to the latitude and longitude pair of WGS84, UTM coordinate consists of a easting and northing pair in metres and relative to the origin of their zone.

To parse latitude and longitude from text input, see coordinate-parser.

Installation

Install via NPM:

$ npm install utm-coordinate-parser

Usage

To parse coordinates from text:

const utmp = require('utm-coordinate-parser')
const pos = utmp.parse('N 12345 W 23456')

The result pos is an object:

{
  x: -23456, // easting
  y: 12345 // northing
}

If input cannot be parsed or is in unknown format, an Error is thrown.

Supported input text formats:

23456 12345
N 12345 E 23456
12345 N 23456 E
W -23456 S -12345
N12345;E23456
x=23456 y=12345
y:12345;x:23456
x23456 y12345
w-23456n12345

If the input has no recognisable direction labels such as N or x then the easting is assumed to come first. If input has language-specific labels, for example P and I in Finland, you might want to customise label patterns with options eastingLabel and northingLabel. See API for details.

API

utmp.parse(text, options)

Extract numeric coordinates from a free-form UTM coordinate string.

Parameters:

  • text: string containing a UTM coordinate pair
  • options: optional object with optional properties:
    • eastingLabel
      • a RegExp pattern for easting label.
      • Defaults to /^[xe]/i
    • westingLabel
      • a RegExp pattern for negative easting label.
      • Defaults to /^w/i
    • northingLabel
      • a RegExp pattern for northing label.
      • Defaults to /^[yn]/i
    • southingLabel
      • a RegExp pattern for negative northing label.
      • Defaults to /^s/i

Returns object { x: <number>, y: <number> } where x denotes easting and y northing.

Throws an error if parsing fails due to invalid input or unknown coordinate format.

Example:

utmp.parse('N 12345, E 23456')
// => { x: 23456, y: 12345 }

Example with custom label patterns:

const opts = {
  northingLabel: /^[yYnNpP]/,
  eastingLabel: /^[xXeEiI]/
}
utmp.parse('P: 12345, I: 23456', opts)
// => { x: 23456, y: 12345 }

utmp.validate(text, options)

Not yet implemented. Let us know by submitting an issue if you happen to need such feature.

Contribute

Pull requests and bug reports are highly appreciated. The code is written in ES6 in StandardJS style. Please test your contribution with the following scripts.

Run test suite:

$ npm test

Run only linter:

$ npm run lint

License

MIT