Format number

From TryGhost/Ghost · View interactive version

Format number is an AI agent skill from the GitHub repository TryGhost/Ghost. Format numbers using the formatNumber function from Shade whenever someone edits a TSX file.

How to use this skill

Skill file

Format Numbers

When editing .tsx files, ensure all user-facing numbers are formatted using the formatNumber utility from @tryghost/shade/utils.

Import

import { formatNumber } from '@tryghost/shade/utils';

When to use formatNumber

Use formatNumber() when rendering any numeric value that is displayed to the user, including:

Correct usage

<span>{formatNumber(totalMembers)}</span>
<span>{formatNumber(link.count || 0)}</span>
<span>{`${currencySymbol}${formatNumber(centsToDollars(mrr))}`}</span>
<span>{post.members > 0 ? `+${formatNumber(post.members)}` : '0'}</span>

Antipatterns to avoid

Do NOT use any of these patterns for formatting numbers in TSX files:

// BAD: raw .toLocaleString()
<span>{count.toLocaleString()}</span>

// BAD: manual Intl.NumberFormat
<span>{new Intl.NumberFormat('en-US').format(count)}</span>

// BAD: raw number without formatting
<span>{memberCount}</span>

// BAD: manual regex formatting
<span>{count.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')}</span>

Related utilities

All are imported from @tryghost/shade/utils.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.