@quantities/units
v1.0.0
Published
Uncommon and specialized unit definitions for @quantities/core
Maintainers
Readme
@quantities/units
A set of uncommon or specialized unit definitions for @quantities/core.
Use with @quantities/registry to build a Quantity constructor that understands them. Once the units are registered, the same Quantity class will carry them everywhere.
Install
npm install @quantities/units @quantities/registry
bun add @quantities/units @quantities/registryImporting
Everything is importable from the package root, so you needn't know which kind a unit belongs to. Individual units, kind groups (arrays of unit entries), and ALL (every unit) are named exports. Collections are spelled in uppercase to set them apart from lowercase units:
// import all units
import UNITS from "@quantities/units";
// import only length units
import { LENGTH } from "@quantities/units";
// import a single unit
import { league } from "@quantities/units";Each kind is also a separate entry point. There, the default export is the whole kind, and named exports are individual units:
// import every length unit
import LENGTH from "@quantities/units/length";
// import specific units only
import { league, furlong } from "@quantities/units/length";Using with a registry
Pass the imported definitions to createRegistry(), then bind a constructor with withRegistry():
import LENGTH from "@quantities/units/length";
import SPEED from "@quantities/units/speed";
import { createRegistry, withRegistry } from "@quantities/registry";
// LENGTH's hubbleLength references a speed unit, so register SPEED alongside it
const registry = createRegistry([LENGTH, SPEED]);
const { default: Quantity } = withRegistry(registry);
Quantity("3 leagues").to("km").format(); // → "14.484 km"createRegistry accepts an array of arrays, so you can combine any kinds:
import PREFIX from "@quantities/units/prefix";
const registry = createRegistry([LENGTH, SPEED, PREFIX]); // adds "googol"Available kinds
Each kind (uppercase) lists the units importable under it.
ACCELERATIONgal
ACTIVITYkatalunit
ANGLEgradian
CHARGEelementaryCharge
COUNTINGcellbasePairnucleotidemolecule
CURRENTbiotabampere
ENERGYergthermUSelectronvolt
FORCEdynegramForce
LENGTHleaguemilfurlongrodfathomlightMinutelightSeconddatamilehubbleLengthredshift
MAGNETISMgaussmaxwelloersted
MASSgrainslugdramdaltonamu
MOLAR_CONCENTRATIONwtpercent
POWERvoltAmpereReactive
PREFIXgoogol
PREFIX_ONLYpptppqgross
PRESSUREcmH2OinH2O
RADIATIONroentgencurie
RATEcpmdpm
SPEEDceehubbleConstanthubbleConstant70
TEMPERATURErankinetempR
TIMEfortnight
VISCOSITYpoisestokes
VOLUMEtablespoonIntteaspoonIntbeerbarrelImpbusheloilbarrelbeerbarrel
License
MIT
