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

@smartput/mass

v0.2.0

Published

Milligram to ton, with the imperial pounds and ounces.

Readme

@smartput/mass

Milligram to ton, with the imperial pounds and ounces.

Metric and avoirdupois in one table, canonical in grams.

Three doors, one table. The kind descriptor is for the engine, /validate is free functions over JS numbers, /class is an immutable value class — and all three read the same UnitTable, so a unit added once is added everywhere. See Validating without the engine.

Setup

npm add @smartput/mass

Example

import { parseMass, asMass, formatMass } from "@smartput/mass/validate";
import { Mass } from "@smartput/mass/class";

parseMass("500 g")                         // {"ok":true,"value":500,"unit":"g","raw":"500"}
asMass("500 g", "mg")                      // {"ok":true,"value":500000,"unit":"mg","raw":"500000"}
formatMass(parseMass("500 g"))             // "500g"
String(Mass.parse("500 g"))                // "500g"

// …and the same table through the engine:
engine.evaluate("1 kg + 500 g").formatted  // "1.5 kilograms"
engine.evaluate("3 lbs").formatted         // "3 pounds"
engine.evaluate("2 t in kg").formatted     // "2,000 kilograms"

parse and as never throw — they answer { ok: true, … } or { ok: false, code, input }. The value class throws on bad input and Mass.tryParse does not. All three read the one UnitTable below.

Entry points

| Import | Contents | | --- | --- | | @smartput/mass | The package root. | | @smartput/mass/units | The UnitTable: ratios and aliases, with no engine and no Decimal. | | @smartput/mass/validate | Free functions over JS numbers. Ok \| Err, never a throw. | | @smartput/mass/class | The immutable value class. | | @smartput/mass/locale/<id> | One language's words for this kind. 17 ship: en, de, fr, es, pt, it, nl, zh, ja, ar, ru, pl, tr, hi, ko, id, uk. |

Units

Read from the table itself, not typed out — a unit added to the source appears here on the next bun run docs:packages. Ratios are decimal strings, which is what lets the engine widen them to Decimal without a float in between.

MASS_UNITS

| Unit | Ratio to g | Aliases | | --- | --- | --- | | g | 1 | g gram grams | | mg | 0.001 | mg milligram milligrams | | kg | 1000 | kg kilo kilos kilogram | | t | 1000000 | t tonne tonnes | | oz | 28.349523125 | oz ounce ounces | | lb | 453.59237 | lb lbs pound pounds |

Runtime exports

Type-only exports are erased and do not appear here.

MASS_UNITS · mass

Dependencies

What it costs

Ceilings, not measurements. bun run check-size bundles each entry with bun build --minify and fails if a row crosses its ceiling or drops more than 30 % below it — a budget that is only an upper bound reports a vanished graph as a triumph.

| Import | Minified | Gzipped | | --- | --- | --- | | mass/validate parseMass only | ≤ 1.4 kB | ≤ 750 B |


Generated by scripts/gen-readmes.ts — run bun run docs:readmes. Every output above was produced by running the line beside it. The full page, with live demos, is docs/packages/mass.md.