Skip to content

Install

Terminal window
pnpm add yugajs
import { yuga } from "yugajs";
yuga().format("dddd, MMMM D");

yugajs is ESM only: import it, there is no require build.

yuga runs on the native Temporal and Intl APIs. It doesn’t bundle polyfills or look for them, so where an API is missing, load its polyfill once at the entry of your app, before anything imports yugajs.

API Native in Polyfill
Temporal Node.js 26+, Chromium 159, Firefox 159, Safari 27.2 temporal-polyfill
Intl.Locale#getWeekInfo Node.js 26+, Chromium 159, Firefox 159, Safari 27.2 @formatjs/intl-locale

The browser versions are the ones yuga’s tests run in. Earlier versions may have the APIs too.

// The entry of your app, before anything imports yugajs.
import "temporal-polyfill/global"; // Defines `globalThis.Temporal` only when it's missing.
import "@formatjs/intl-locale/polyfill.js"; // Installs itself only when `getWeekInfo` is missing.
import { yuga } from "yugajs";
  • Temporal is needed by parsing strings, time zones and anything that reads an instance’s Temporal value. Without it, importing yugajs works and yuga() still makes an instance, but those throw a ReferenceError.
  • Intl.Locale#getWeekInfo is only needed by locales built from a language tag (yuga().locale("fr")), which read the first day of the week from it. A custom locale with its own weekStart doesn’t need it.

Core parses ISO 8601 strings, Day.js’s loose YYYY-MM-DD HH:mm strings, dates, numbers and Temporal values. Strings in your own format need the custom-parse-format extension, the same as Day.js’s customParseFormat plugin:

import { yuga } from "yugajs";
import { customParseFormat } from "yugajs/extension/custom-parse-format";
yuga.extend(customParseFormat);
yuga("15/05/2024", "DD/MM/YYYY");

Every other extension installs the same way. See Extensions and plugins for the list.