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

@r47onfire/hyperspace

v1.0.0

Published

Simple dimensional analysis and unit conversion library designed for basing games in physical units

Readme

hyperspace

Simple dimensional analysis and unit conversion library designed for basing games in physical units.

Install

pnpm install @r47onfire/hyperspace

Quick start

import { UnitSystem, basicUnits, physicsUnits, dataUnits } from "@r47onfire/hyperspace";

const U = new UnitSystem();
basicUnits(U);      // installs basic length, time, mass, temperature
physicsUnits(U);   // installs newtons, pascals, joules, watts, etc.
dataUnits(U);      // installs bytes, kilobytes, megabytes, etc.

// Convert units numerically
const v = U.parse(100, "km/h");
U.convert(v, "m/s") // => 27.777777...

// Format as a string
U.format(v, "m/s") // => "27.777777... meters seconds^-1"
U.format(v, "m/s", false) // => "27.777777... m/s"

// Format as compound unit
U.format(U.parse(3661, "s"), ["h", "min", "s"])
// => "1 hour 1 minute 1 second"

// Format as best unit
U.format(U.parse(214523, "B"), ["B", "KB", "MB"], true)
// => "214.523 KB"

// Unit recognition
U.parse(5, "kg*m/s^2").kind // => "force" (equivalent to newtons)

Define units

// base dimension kind name
U.addKind("length");
// derived dimension kind with composition exponents
U.addKind("speed", { length: 1, time -1 });

// base unit: name, abbreviation, kind, aliases
U.addBase("meters", "m", "length", ["metres"]);

// converted unit: name, abbreviation, conversion factor, reference unit
U.addConversion("centimeters", "cm", 100, "m", ["centimetres"]);
// unit = base * perBase

// non-affine unit: 2 numbers are ratio and offset
U.addOffsetConversion("celsius", "°C", 1, -273.15, "kelvin", ["℃"]);
U.addOffsetConversion("fahrenheit", "°F", 1.8, 32, "celsius", ["℉"]);
// unit = base * perBase + zeroOffset

Math with units

U.parseUnit("N*m") // => the entry for Joules

U.add(a, b), U.sub(a, b), // must be the same dimensions, error if not
U.mul(a, b), U.div(a, b), // can be different dimensions
U.pow(a, n) // n must be a dimensionless number

Metadata

U.kinds                 // => ["length", "time", ...]
U.dimensionsOf("force") // => { mass: 1, length: 1, time: -2 }
U.baseFor("length")     // => "meters"
U.expand("velocity")    // => { length: 1, time: -1 }

Built-in units

Provided by basicUnits():

  • meters, centimeters, kilometers, feet, inches (length)
  • pixels as configurable ratio length unit (default 64 pixels per meter)
  • seconds milliseconds, minutes, hours (time)
  • hertz (frequency = 1/time)
  • kilograms, grams (mass)
  • celsius, fahrenheit, kelvin (temperature)
  • names "area", "volume", "velocity", "acceleration" (for length^2, length^3, length/time, and length/time^2)

Provided by physicsUnits():

  • amperes (current)
  • newtons (force = mass*acceleration)
  • pascals (pressure = force/area)
  • joules (energy = force*length)
  • watts (power = energy/time)
  • coulombs (charge = current*time)
  • volts (voltage = energy/charge)
  • ohms (resistance = voltage/current)
  • farads (capacitance = charge/voltage)
  • webers (magnetic flux = voltage*time)
  • henries (inductance = flux/current)
  • teslas (magnetic field density = flux/area)

Provided by dataUnits():

  • bits, bytes (data)
  • kilobytes, megabytes, gigabytes, terabytes (factor of 1000 scaling)
  • kibibytes, mebibytes, gibibytes, tebibytes (factor of 1024 scaling)
  • name "bitrate" for data/time

Caveats

  • No support for differentiating between normal frequency and angular frequency. For example:

    const L = U.parse(0.001, "henries")
    const C = U.parse(0.001, "farads");
    // resonant angular frequency = 1/sqrt(L*C) = 1000 rad/s
    const omega0 = U.pow(U.mul(L, C), -0.5);
    U.format(omega0, "Hz") // => "1000 Hz" - should error!!
  • No support for logarithmic units (e.g. decibels) yet.