Initial commit

This commit is contained in:
2026-03-10 21:30:52 -03:00
commit 72a4f0be26
145 changed files with 14881 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
/**
* Formats a date using the Intl.DateTimeFormat API.
*
* @param date - The date to format.
* @param locale - The locale to use.
* @param options - Optional Intl.DateTimeFormatOptions.
* @returns The formatted date string.
*/
export function formatDate(
date: Date | string,
locale: string,
options?: Intl.DateTimeFormatOptions,
): string {
const d = typeof date === 'string' ? new Date(date) : date;
return new Intl.DateTimeFormat(locale, options).format(d);
}
/**
* Formats a number as a currency string.
*
* @param amount - The amount to format.
* @param currency - The ISO 4217 currency code.
* @param locale - The locale to use.
* @returns The formatted currency string.
*/
export function formatCurrency(amount: number, currency: string, locale: string): string {
return new Intl.NumberFormat(locale, {
style: 'currency',
currency,
}).format(amount);
}

View File

@@ -0,0 +1,11 @@
/**
* @dwellops/i18n — shared internationalization utilities.
*
* Translation files live alongside components as `translations.json`.
* A shared `common.json` holds truly cross-cutting strings.
* The `scripts/aggregate-translations.ts` script compiles them into
* per-locale message files for next-intl.
*/
export * from './locales';
export * from './format';

View File

@@ -0,0 +1,17 @@
/** All supported locale codes. */
export const locales = ['en'] as const;
/** The default locale. */
export const defaultLocale = 'en' as const;
/** Union type of all supported locale strings. */
export type Locale = (typeof locales)[number];
/**
* Returns true if the provided string is a supported locale.
*
* @param value - The string to check.
*/
export function isLocale(value: string): value is Locale {
return (locales as readonly string[]).includes(value);
}