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

units-converter-ts

v2.0.1

Published

A simple utility library for converting units

Downloads

311

Readme

units-converter-ts

NPM Downloads NPM License

A simple utility library for converting units. Inspired by convert-units and units-converter. I didn't liked the syntax used in these libraries so I decided to make my own one.

Installation

npm install units-converter-ts --save

Usage

The package is simple and straightforward to use. First, you need to import the specific measure:

import { mass } from 'units-converter-ts';

or if you're using Node.js:

const { mass } = require('units-converter-ts');

Then you can use the convert method to convert units from that measurement. The function takes three arguments: the source unit, the target unit and the value to convert, respectively:

mass.convert('kg', 'g', 1);
// 1000

In the example 1 kilogram (kg) is being converted to grams (g) which will return 1000.

You can also import all objects at once like so:

import * as converter from 'units-converter-ts';

or if you're using Node.js:

const converter = require('units-converter-ts');

In this case you would use it like this:

converter.mass.convert('kg', 'g', 1);
// 1000

There is another alternative, if you don't want to use specific measure, you can import convert object and convert any unit. For example:

import { convert } from 'units-converter-ts';

or for Node.js:

const converter = require('units-converter-ts');

and use it like so:

converter.convert.convert('mm', 'm', 1000);
// 1

Examples

The library has other methods as well, here are use cases for all of them.

Get list of measures:

convert.measures();
/// [ 'mass', 'length', 'speed', ... ]

Get list of all available units:

convert.possibilities();
// [ 'mm2', 'deg', 'mC', 'ml', 'l', 'fl-oz', ... ]

Get list of units for specific measure:

power.possibilities();
// [ 'mW', 'W', 'kW', 'MW', 'GW' ]

// OR

convert.possibilities('power');
// [ 'mW', 'W', 'kW', 'MW', 'GW' ]

Get list of units for specific measures:

convert.possibilities('power', 'pace');
// [ "mW", "W", "kW", "MW", "GW", "min/km", "s/m", "min/mi", "s/ft"]

Get list of all unit descriptions

convert.list();
/*
  [{
      "abbreviation": "gal",
      "measure": "acceleration",
      "plural": "gals"
      "singular": "gal",
      "system": "metric",
    },
    {
      "abbreviation": "m/s2",
      "measure": "acceleration",
      "plural": "metres per second squared"
      "singular": "metre per second squared",
      "system": "metric",
    }
    ...
  ]
*/

Get list of unit descriptions for specific measure:

illuminance.list();
/*
  [{
      "abbreviation": "lx",
      "measure": "illuminance",
      "plural": "lux"
      "singular": "lux",
      "system": "metric",
    },
    {
      "abbreviation": "ft-cd",
      "measure": "illuminance",
      "plural": "foot-candles"
      "singular": "foot-candle",
      "system": "imperial",
  }]
*/

// OR

convert.list('illuminance');
/*
  [{
      "abbreviation": "lx",
      "measure": "illuminance",
      "plural": "lux"
      "singular": "lux",
      "system": "metric",
    },
    {
      "abbreviation": "ft-cd",
      "measure": "illuminance",
      "plural": "foot-candles"
      "singular": "foot-candle",
      "system": "imperial",
  }]
*/

Get list of units for specific measures:

convert.list('illuminance', 'force');
/*
  [{
      "abbreviation": "lx",
      "measure": "illuminance",
      "plural": "lux"
      "singular": "lux",
      "system": "metric",
    },
    {
      "abbreviation": "ft-cd",
      "measure": "illuminance",
      "plural": "foot-candles"
      "singular": "foot-candle",
      "system": "imperial",
    }
    {
      abbreviation: 'N',
      measure: 'force',
      plural: 'newtons',
      singular: 'newton',
      system: 'metric',
    },
    {
      abbreviation: 'kN',
      measure: 'force',
      plural: 'kilonewtons',
      singular: 'kilonewton',
      system: 'metric',
    },
    {
      abbreviation: 'lbf',
      measure: 'force',
      plural: 'pound-forces',
      singular: 'pound-force',
      system: 'imperial',
  }]
*/

Get information about specific unit:

convert.describe('kN');
/*
  {
    abbreviation: "kN",
    measure: "force",
    plural: "kilonewtons",
    singular: "kilonewton",
    system: "metric"
  }
*/

Units

  • gal
  • g-force
  • m/s2
  • rev
  • rad
  • deg
  • grad
  • arcmin
  • arcsec
  • mVA
  • VA
  • kVA
  • MVA
  • GVA
  • mm2
  • cm2
  • m2
  • are
  • ha
  • km2
  • circ-mil
  • circ-inch
  • in2
  • ft2
  • yd2
  • ro
  • ac
  • mi2
  • twp
  • abC
  • c
  • mC
  • μC
  • nC
  • stC
  • pC
  • e
  • stA
  • mA
  • A
  • abA
  • kA
  • b
  • Kb
  • Mb
  • Gb
  • Tb
  • B
  • KB
  • MB
  • GB
  • TB
  • J
  • kJ
  • mWh
  • Wh
  • kWh
  • MWh
  • GWh
  • Btu-it
  • N
  • kN
  • lbf
  • mHz
  • Hz
  • kHz
  • MHz
  • GHz
  • THz
  • rpm
  • deg/s
  • rad/s
  • lx
  • ft-cd
  • mm
  • cm
  • m
  • km
  • in
  • hand
  • ft
  • ft-us
  • yd
  • fath
  • fur
  • mi
  • nMi
  • mg
  • g
  • kg
  • t
  • kt
  • mt
  • gr
  • dr
  • oz
  • lb
  • stone
  • qr
  • slug
  • tn
  • ton-uk
  • min/km
  • s/m
  • min/mi
  • s/ft
  • mW
  • W
  • kW
  • MW
  • GW
  • Pa
  • hPa
  • kPa
  • bar
  • MPa
  • torr
  • psi
  • ksi
  • mVARh
  • VARh
  • kVARh
  • MVARh
  • GVARh
  • mVAR
  • VAR
  • kVAR
  • MVAR
  • GVAR
  • km/h
  • m/s
  • ft/s
  • mi/h
  • knot
  • C
  • K
  • F
  • R
  • ns
  • mu
  • ms
  • s
  • min
  • h
  • d
  • week
  • fortnight
  • month
  • year
  • mV
  • V
  • kV
  • mm3
  • cm3
  • ml
  • cl
  • dl
  • l
  • kl
  • m3
  • km3
  • krm
  • tsk
  • msk
  • kkp
  • glas
  • kanna
  • tsp
  • Tbs
  • in3
  • fl-oz
  • cup
  • pnt
  • qt
  • gal
  • ft3
  • yd3
  • mm3/s
  • cm3/s
  • ml/s
  • cl/s
  • dl/s
  • l/s
  • l/min
  • l/h
  • kl/s
  • kl/min
  • kl/h
  • m3/s
  • m3/min
  • m3/h
  • km3/s
  • tsp/s
  • Tbs/s
  • in3/s
  • in3/min
  • in3/h
  • fl-oz/s
  • fl-oz/min
  • fl-oz/h
  • cup/s
  • pnt/s
  • pnt/min
  • pnt/h
  • qt/s
  • gal/s
  • gal/min
  • gal/h
  • ft3/s
  • ft3/min
  • ft3/h
  • yd3/s
  • yd3/min
  • yd3/h