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

@quantities/to-compound

v0.5.0

Published

Compound formatting extension for @quantities/core

Readme

@quantities/to-compound

Compound string output for @quantities/core: render a quantity in a human-readable fashion, e.g. "1 kg 200 g" or "6 ft 4 in".

Install

npm install @quantities/to-compound
bun add @quantities/to-compound

Setup

The default export is an extension. Register it with Quantity.extend() to add the .toCompound() method to the prototype:

import Quantity from "@quantities/core";
import toCompound from "@quantities/to-compound";

const Q = Quantity.extend(toCompound);

extend() mutates the prototype and returns the same constructor, so existing Quantity instances gain the method too — Q is just a convenient handle.

Usage

Called with no arguments, it walks the quantity's unit family and picks metric prefix tiers automatically, attempting to produce the best representation of the quantity across at most 3 units:

Q("1200 g").toCompound(); // → "1 kg 200 g"

Pass an explicit list of target units to control the breakdown:

Q("1.5 h").toCompound(["h", "min"]); // → "1 h 30 min"
Q("1020.56 g").toCompound(["kg", "mg"]); // → "1 kg 20560 mg"

Options

A second argument tunes the output:

Q("100 cm").toCompound(["m", "cm"], { skipZeros: false }); // → "1 m 0 cm"

| Option | Type | Default | Description | | ----------------------- | ----------- | ------------------- | ------------------------------------------------------------------ | | skipZeros | boolean | true | Omit zero-valued components (the largest unit is kept if all zero) | | precision | number | — | Max decimals on the smallest component | | threshold | number | — | Drop components below this absolute value | | step | number | 3 | Exponent step between SI prefix tiers (e.g. kilo→mega) | | metricPrefixPowerStep | 1 \| 3 | 3 | Prefix granularity used in automatic (no-target) mode | | formatter | Formatter | DEFAULT_FORMATTER | Custom per-component formatter from core |

License

MIT