formatting

Formats money, numbers, percentages, dates, and durations through centralized locale-aware Intl formatters.

10|3|Updated Oct 23, 2023
One-click install
npx skills add https://github.com/Layer-Fi/layer-react --skill formatting-layer-fi
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: formatting
Source: https://github.com/Layer-Fi/layer-react/tree/main/src/utils/shared/i18n
Command: npx skills add https://github.com/Layer-Fi/layer-react --skill formatting-layer-fi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires react-intl, i18next, i18next-pseudo, date-fns, @formatjs/intl-durationformat.

What problem does it solve? Hand-rolled formatting like $${value} or toLocaleString() breaks under the fr-CA locale and slips through code review unnoticed. This Skill enforces a single centralized formatting path so currency, numbers, percentages, dates, and durations always render correctly for the user's locale, currency, and timezone. ## Core Features & Use Cases - Nine locale-aware formatters via useIntlFormatter(): formatCurrencyFromCents, formatNumber, formatPercent, formatDate, formatDateRange, formatMonthName, formatMinutesAsDuration, formatSecondsAsDuration, and formatList, all memoized and safe in dependency arrays. - Permissive inputs with safe failure: formatters accept raw API values (number | string | null | undefined, Date | string | number) and return an empty string on unparseable input instead of throwing or rendering NaN. - JSX components and date pattern enums: <MoneySpan> and <DurationSpan> for rendered values, and a DateFormat enum so display dates never use custom format strings. - Use Case: Rendering an invoice due date and amount in a React component — call formatDate(invoice.dueAt, DateFormat.DateShort) and <MoneySpan amount={invoice.totalCents} /> instead of concatenating strings, so the same code renders correctly in both en-US (USD) and fr-CA (CAD). ## Quick Start Use the formatting skill to render this invoice amount and due date with useIntlFormatter and MoneySpan instead of manual string formatting.

Frequently Asked Questions about formatting

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I format currency in React with locale support?▼

Use the formatCurrencyFromCents formatter from the useIntlFormatter hook, or render the MoneySpan component for JSX. The input must be in cents since the formatter divides by 100 internally, and the currency is resolved from the locale (en-US to USD, fr-CA to CAD).

How do I format dates in React without custom format strings?▼

Call formatDate from useIntlFormatter with a member of the DateFormat enum, such as DateFormat.DateShort for "Jan 5, 2026" or DateFormat.DateWithTimeReadable for "January 5, 2026 at 3:30 PM". If a needed pattern is missing, add it to the enum rather than formatting inline.

Why does my formatted currency show a value 100 times too small?▼

formatCurrencyFromCents expects input in cents and divides by 100 internally. Passing a dollar amount directly renders a value 100x too small, so convert dollars to cents before calling the formatter.

How do I combine a formatted value with a translated string in i18next?▼

Format the value first, then pass it into t() as an interpolation variable, for example t('key', 'Due on {{date}}', { date: formatDate(d) }). Never build the default string with a template literal or concatenate formatted values in JSX, since that breaks translation word order.

What happens when a formatter receives invalid or null input?▼

The formatters accept number, string, null, or undefined inputs and return an empty string when the value cannot be parsed, rather than throwing or rendering NaN. A blank cell therefore indicates bad data, not a missing formatter call.

Should I use formatPercent with 5 or 0.05 for five percent?▼

formatPercent expects a fraction, so formatPercent(0.05) renders "5%". If your value is 5 meaning 5%, divide by 100 first before passing it to the formatter.