@alef-prime/units
v0.1.0-alpha.0
Published
Locale-aware currency, distance, duration, and number formatters. Plus haversine. Battle-tested in pundak.app delivery (real money, real km).
Maintainers
Readme
@alef-prime/units
Locale-aware money, distance, duration. Plus haversine. Zero deps.
import { formatMoney, formatDistance, formatDuration, haversineKm } from "@alef-prime/units";
formatMoney(42.5, "he", "ILS"); // → "42.50 ₪"
formatMoney(42.5, "en", "USD"); // → "$42.50"
formatDistance(0.8, "he"); // → "800 m"
formatDistance(3.4, "he"); // → '3.4 ק"מ'
formatDuration(95, "ru"); // → "1ч 35мин"
haversineKm({ lat: 32.07, lng: 34.78 }, { lat: 31.78, lng: 35.21 });
// → 70.32 (Tel Aviv → Jerusalem, km)Why
Battle-tested in pundak.app — Israeli food delivery handling real money, real km, real ETA windows. Extracted as a zero-dep package so Foresight, Backerpath, and anyone shipping in Hebrew/Russian/English can stop rewriting the same Intl.NumberFormat boilerplate.
API
| Function | Signature | Notes |
|---|---|---|
| formatMoney | (amount, locale="he", currency="ILS") → string | Uses Intl.NumberFormat. Strips trailing .00 for whole amounts. |
| formatDistance | (km, locale="he") → string | Switches to meters below 1km. RTL-safe suffix. |
| formatDuration | (minutes, locale="he") → string | "1ש' 35ד'" / "1h 35m" / "1ч 35мин". |
| haversineKm | ({lat,lng}, {lat,lng}) → km | Earth radius 6371. Pure trig. |
| formatNumber | (n, locale="he") → string | Thousand separators per locale. |
Status: alpha · 0.1.0
Born from ALEF-PRIME cross-pollination. Sibling of @alef-prime/i18n-pick, @alef-prime/deploy-verify, @alef-prime/audit. MIT.
