A lightweight, immutable library for quantities, units, and dimensional analysis. It converts automatically, blocks nonsense math, and works the moment you install it.
Runs in your browser using the same factors & offsets as the PHP library. The PHP snippet updates as you type.
Small surface, real guarantees.
Add centimeters to meters and get the right answer — the library converts through a common base unit.
m + s throws instead of returning garbage. Mistakes fail loudly at the call site.
°C, °F, and K use affine scales (factor + offset), so conversions are accurate — not a naive multiplier.
Multiply and divide quantities to get m/s, m², and more, with dimensions tracked.
Every operation returns a new Quantity. No hidden mutation, safe to share.
Pure PHP 8.2+, PHPStan level max, tested on 8.2/8.3/8.4.
One command. Common units are ready immediately.
composer require khaledalam/unit
use KhaledAlam\Unit\Quantity; echo Quantity::of(2, 'm')->add(Quantity::of(100, 'cm'))->to('m'); // "3 m" echo Quantity::of(100, '°C')->to('°F'); // "212 °F" echo Quantity::of(4, 'm')->multiply(Quantity::of(3, 'm')); // "12 m²"