Prism · guide

Money and dates

An amount and a moment, written the way the reader’s language writes them. Components do not format.

Install it
pnpm add @niscorp/prism @niscorp/strata zod
Step 1 of 3

A booking

A booking as the box office stores it: who, which show, which seats, and what a seat costs in cents. Every guide here reads this row or a few like it.

A booking
import { evaluate } from '@niscorp/prism';

const booking = {
  id: 'B-2041',
  member: { name: 'Grace', pass: 'season' },
  show: { title: 'The Tempest', starts_at: '2026-10-24T19:30:00+02:00' },
  seats: ['C4', 'C5'],
  seat_price_cents: 3800,
};
Step 2 of 3

A config that takes a locale

A config is data, so a function can build one. This one is given a locale and answers the config for it.

$localeMoney writes cents as money and $localeDate writes a moment for a person, both for a named locale. $dateAdd moves a moment: the doors open half an hour before.

A config that takes a locale
const ticketFor = (locale: string) => ({
  price: { $localeMoney: { value: { $ref: '$.seat_price_cents' }, currency: 'EUR', locale } },
  day: {
    $localeDate: {
      value: { $ref: '$.show.starts_at' },
      locale,
      options: { weekday: 'long', day: 'numeric', month: 'long', timeZone: 'Europe/Vienna' },
    },
  },
  doors: {
    $localeDate: {
      value: { $dateAdd: { date: { $ref: '$.show.starts_at' }, amount: -30, unit: 'minute' } },
      locale,
      options: { hour: '2-digit', minute: '2-digit', timeZone: 'Europe/Vienna' },
    },
  },
});
Step 3 of 3

Two readers

The same row, for a reader in Vienna and one in Dublin. The time zone is the theatre’s, wherever the reader is.

Two readers
for (const locale of ['de-AT', 'en-IE']) {
  console.log(locale, JSON.stringify(evaluate(ticketFor(locale), booking)));
}
Then

Run it.

One booking, written twice: the price, the day and when the doors open, each as that language writes them.

Run it
npx tsx format.mts
It prints
de-AT {"price":"€ 38,00","day":"Samstag, 24. Oktober","doors":"19:00"}
en-IE {"price":"€38.00","day":"Saturday, 24 October","doors":"19:00"}