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

@torthu/metrify

v0.2.0

Published

Helpers for working with measurements and units in TypeScript.

Readme

@torthu/metrify

Helpers for working with measurements and units in TypeScript.

Metrify is a work in progress. API changes may occur.

Installation

npm i --save @torthu/metrify

pnpm add @torthu/metrify

Usage

Measurements and conversions

Metrify provides a collection of measurement classes that contains conversion factors.

Note: the conversions are not exhaustive, meaning that the build in conversion factors are not enough to convert between all units.

You can create a new Measurement by passing a tuple with a value and a unit.

import { Mass } from "@torthu/metrify";

// I have 1 kg
const oneKG = new Mass([1, "kg"]);

// But I want to know how many pounds that is
console.log(oneKG.to("lb"));

Arithmetic operations

Metrify ships with simple arithmetic functions.

import { Distance, add } from "@torthu/metrify";

const distanceA = new Distance([1, "m"]);
const distanceB = new Distance([1, "km"]);
const distanceC = add(distanceA, distanceB);

console.log(distanceC.to("ft")); // 3284.12

Metrify will try to the best of its ability to do Measurement conversions when doing arithmetic operations.

Please note that these conversions are not complete or perfect.

const distance = new Distance([1, "m"]);
const area = multiply(distance, distance); // Area
const volume = multiply(distance, area); // Volume

If Metrify does not recognize the result type of an arithmetic operation, it will return a MeasurementTuple:

const distance = new Distance([1, "m"]);
const time = new Time([1, "s"]);

const weirdNewUnit = multiply(distance, time); // [number, "m*s"]

Metrify is expandable, you can add new Measurement classes:

import type { Measurement, Dimension } from "@torthu/metrify";
import { register } from "@torthu/metrify";

class MyCustomMeasurement implements Measurement {
  static readonly dimensions: Dimensions = { m: 1, s: 1 };
  static readonly siUnit: string = "m*s";

  type = "MS";
}

register(MyCustomMeasurement);

const distance = new Distance([1, "m"]);
const time = new Time([1, "s"]);

const weirdNewUnit = multiply(distance, time); // MyCustomMeasurement

You can also replace Measurement (i.e if you need larger or smaller measurements) classes. See examples/BigDistance.ts for an example of how to do this.

Advanced concepts

Dimensions

Every measurement class declares a static dimensions property of type Record<string, number>. The keys are SI base unit symbols and the values are their exponents, encoding the physical dimensionality of the quantity:

| Measurement | Key | SI Base Quantity | | ------------------- | ----- | ---------------- | | Length | m | meter | | Mass | kg | kilogram | | Time | s | second | | Electric current | A | ampere | | Temperature | K | kelvin | | Amount of substance | mol | mole | | Luminous intensity | cd | candela | | Angle | rad | radian |

For example:

| Measurement | Dimensions | Conceptual meaning | | ----------- | ------------------------ | ----------------------- | | Distance | { m: 1 } | length | | Area | { m: 2 } | length^2 | | Speed | { m: 1, s: -1 } | length / time | | Force | { kg: 1, m: 1, s: -2 } | mass * length / time^2 |

When you multiply two measurements, Metrify adds the exponents of their dimensions. When you divide, it subtracts them. The resulting dimensions are then looked up in the registry to find the matching measurement class:

// multiply: adds exponents
// Distance { m: 1 } * Area { m: 2 } → { m: 3 } → Volume

// divide: subtracts exponents
// Distance { m: 1 } / Time { s: 1 } → { m: 1, s: -1 } → Speed

If no registered class matches the resulting dimensions, a raw tuple [number, string] is returned instead. You can register your own measurement classes to handle custom dimension combinations.

Glossary

| Measurement | Symbol | Name | | ------------------ | ------ | ------------------------- | | Acceleration | m/s2 | meter per second squared | | Acceleration | ft/s2 | foot per second squared | | Acceleration | gforce | standard gravity | | AmountOfSubstance | mol | mole | | AmountOfSubstance | mmol | millimole | | AmountOfSubstance | μmol | micromole | | Angle | deg | degree | | Angle | rad | radian | | Angle | turn | turn | | Angle | gon | gradian | | Area | km2 | square kilometer | | Area | m2 | square meter | | Area | cm2 | square centimeter | | Area | mm2 | square millimeter | | Area | ha | hectare | | Area | ft2 | square foot | | Area | ac | acre | | Area | mi2 | square mile | | Density | kg/m3 | kilogram per cubic meter | | Density | g/cm3 | gram per cubic centimeter | | Density | lb/ft3 | pound per cubic foot | | Distance | km | kilometer | | Distance | m | meter | | Distance | dm | decimeter | | Distance | cm | centimeter | | Distance | mm | millimeter | | Distance | in | inch | | Distance | ft | foot | | Distance | yd | yard | | Distance | mi | mile | | ElectricCurrent | A | ampere | | ElectricCurrent | mA | milliampere | | ElectricCurrent | μA | microampere | | ElectricResistance | ohm | Ω | | ElectricResistance | kohm | kiloΩ | | ElectricResistance | Mohm | megaΩ | | ElectricResistance | mohm | milliΩ | | Energy | J | joule | | Energy | kJ | kilojoule | | Energy | cal | calorie | | Energy | kcal | kilocalorie | | Energy | Wh | watt-hour | | Energy | kWh | kilowatt-hour | | Energy | BTU | British thermal unit | | Force | N | newton | | Force | kN | kilonewton | | Force | lbf | pound-force | | Force | dyn | dyne | | Frequency | Hz | hertz | | Frequency | kHz | kilohertz | | Frequency | MHz | megahertz | | Frequency | GHz | gigahertz | | Frequency | rpm | revolutions per minute | | LuminousIntensity | cd | candela | | LuminousIntensity | mcd | millicandela | | LuminousIntensity | kcd | kilocandela | | Mass | kg | kilogram | | Mass | g | gram | | Mass | mg | milligram | | Mass | t | tonne | | Mass | oz | ounce | | Mass | lb | pound | | Power | W | watt | | Power | kW | kilowatt | | Power | MW | megawatt | | Power | hp | horsepower | | Pressure | Pa | pascal | | Pressure | kPa | kilopascal | | Pressure | bar | bar | | Pressure | atm | atmosphere | | Pressure | psi | pound per square inch | | Speed | m/s | meter per second | | Speed | km/h | kilometer per hour | | Speed | mph | mile per hour | | Speed | knot | knot | | Speed | ft/s | foot per second | | Temperature | K | kelvin | | Temperature | C | degree Celsius | | Temperature | F | degree Fahrenheit | | Time | h | hour | | Time | min | minute | | Time | s | second | | Time | ms | millisecond | | Voltage | V | volt | | Voltage | mV | millivolt | | Voltage | kV | kilovolt | | Volume | L | liter | | Volume | mL | milliliter | | Volume | m3 | cubic meter | | Volume | cm3 | cubic centimeter | | Volume | gal | gallon | | Volume | qt | quart | | Volume | pt | pint | | Volume | cup | cup | | Volume | floz | fluid ounce |