Something went wrong. Try again.
yet another localization library
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637import { describe, expect, it } from 'vitest';
import { dateTimeFormat, lazy, numberFormat, pluralRules } from './runtime.ts';
describe('lazy', () => { it('computes once on first access and caches the result', () => { let calls = 0; const holder = lazy(() => { calls++; return { id: calls }; }); expect(holder.value).toBe(holder.value); expect(holder.value.id).toBe(1); expect(calls).toBe(1); });});
describe('Intl shorthands', () => { it('builds an Intl.PluralRules', () => { const rules = pluralRules('en', { type: 'cardinal' }); expect(rules).toBeInstanceOf(Intl.PluralRules); expect(rules.select(1)).toBe('one'); });
it('builds an Intl.NumberFormat', () => { const format = numberFormat('en', { style: 'percent' }); expect(format).toBeInstanceOf(Intl.NumberFormat); expect(format.format(0.5)).toBe('50%'); });
it('builds an Intl.DateTimeFormat', () => { const format = dateTimeFormat('en', { timeZone: 'UTC', year: 'numeric' }); expect(format).toBeInstanceOf(Intl.DateTimeFormat); expect(format.format(new Date('2026-06-28T00:00:00Z'))).toBe('2026'); });});