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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rwgps/units

v1.2.0

Published

Unit conversion and formatting

Readme

rwgps-units

Library for converting and formatting rwgps units.

Currently supported unit types:

distance

  • meters
  • km
  • feet
  • miles

incline

  • %
  • degrees

speed

  • mph
  • kph

Example Usage:

Conversion:

import {convert} from '@rwgps/units'

convert(3.5).from('miles').to('km') // 5.632689999999999
convert(19).from('grade').to('degrees') // 10.757967088390005

alternatively, you can use the static function converters

import {conversions as C} from '@rwgps/units'
C.milesToKm(3.5) // 5.632689999999999
C.gradeToDegrees(10) // 10.757967088390005

Formatting:

All formatters expect native rwgps units. That means meters for distances, kph for speeds, and percentages for grades. They return unitType objects, which allow for flexible presentation of the result.

All formatters accept two arguments, value and options. value should be the metric quanitity that you would like to format in rwgps native units. options is an object that can contain the following configuration parameters:

  • metricUnits (boolean) - Set this to true to output metric unitTypes. Defaults to false.
  • unit (string) - Explicitly request a specific unitType as output. Will override metricUnits if set.
  • ...rest - Other keys are passed through to the unitType constructor, and can be used to override the toLocaleString options used to format numeric labels. See the unitTypes documentation for more info about what you can pass here.

formatDistance will automatically select between output in feet/meters or miles/km based on the length of the distance passed to it. You can override this behavior by requesting your desired units explicitly.

import {formatDistance} from '@rwpgs/units'

// 500m formatted in imperial units
const i = formatDistance(500)
i.value // 1640.4199475065616
i.long // "feet"
i.short // "ft"
i.compound // false
i.toString() // "1,640 feet"
i.toString({short: true}) // "1,640 ft"
i.valueToString() // "1,640"
// for more info about what arguments the toString and valueToString props accept
// see the documentation on unitTypes below

// 50km formatted in imperial units
formatDistance(50 * 1000).toString() // "31.1 miles"
// you can also request specific output units
formatDistance(50 * 1000, {units: 'feet'}).toString() // "164,042 feet"

// requesting metric units
formatDistance(50 * 1000, {metricUnits: true}).toString() // "50 kilometers"
formatDistance(500, {metricUnits: true}).toString() // "500 meters"
import {formatSpeed} from '@rwpgs/units'

formatSpeed(12).toString() // "7.5 miles per hour"
formatSpeed(12).toString({maximumFractionDigits: 3, short: true}) // "7.456 mph"
formatSpeed(12, {metricUnits: true}).toString() // "12 km per hour"
import {formatGrade} from '@rwgps/units'

// Newberry
formatGrade(12.2).toString() // 12.2 percent
formatGrade(12.2).toString({short: true}) // 12.2%
formatGrade(12.2, {units: 'degrees'}).toString() // 7.0 degrees

unitTypes

unitType objects are used to provide rich formatting of returned units for display. They have the following properties:

  • value - the numeric quantity being formatted
  • long - the long unit type label (ex. "meters" or "percent")
  • short - the short unit type label (ex. "m" or "%")
  • compound - false if the unit is not a compound unit type, otherwise a {numerator, denominator} object of the component units
  • valueToString(opts) - returns the value, formatted as a string. opts is an options object that is passed through to Number.toLocaleString.
  • toString({short = false, ...opts}) - returns the value and unit type label, formatted as a string. short is a boolean parameter, default false, which determines whether to render with a short or long unit label. opts are passed through to Number.toLocaleString.