Ergonomic application localisation for JavaScript / Node, built entirely on the standard Intl API.
Cosmo is a thin, ergonomic layer over the JavaScript engine's own
ICU, reached through the standard
Intl
API. Give it a locale (and optionally a time zone) and it formats numbers, money,
dates, units, lists and messages exactly the way your users expect. There are zero
runtime dependencies and zero bundled locale data — every result comes straight
from ICU and CLDR, covering all languages, scripts,
calendars and time zones.
Cosmo is implemented consistently across four languages — the same concepts, method names and behaviour, each built directly on its platform's ICU: JavaScript · Python (docs) · Java (docs) · PHP (docs).
📖 Full documentation, API reference and live playground: https://cosmo.miloun.com/?lang=js
duration()), or any modern browsernpm install @miloun/cosmo
import { Cosmo, cosmo } from "@miloun/cosmo";
new Cosmo("es_ES").money(11000.4, "EUR"); // "11.000,40 €"
new Cosmo("tr").unit("temperature", "celsius", 26, "short"); // "26 °C"
new Cosmo("en").percentage(0.2); // "20%"
new Cosmo("fa").language("en"); // "انگلیسی"
// or the helper
cosmo("en_AU").country(); // "Australia"
Underscore locales (en_AU) and BCP-47 Unicode
extensions (fa-IR-u-nu-latn-ca-buddhist)
are both accepted.
1.2M), scientific, and number/money ranges."3 days ago")."A, B, and C" conjunctions and disjunctions.plural, selectordinal, select).See the full API reference for every method,
the platform notes for what Intl does and
doesn't expose to JavaScript, and resources for ICU/CLDR references.
Recoverable problems throw CosmoError, with InvalidArgumentError and
UnsupportedError subclasses — an invalid currency in strict mode, an unsupported
unit, an unsupported symbol name, a malformed message, and the like.
MIT © Aiden Adrian