Skip to main content

format-numbers

Format numbers using the formatNumber function from Shade whenever someone edits a TSX file.

来源信息

仓库
TryGhost/Ghost
最近来源活动
2026年8月26日 18:18
检测到的 SKILL.md 语言
英语
星标
55,544
分支
11,995

安装方式

默认使用会先检查来源的 Prompt;你也可以切换为直接命令,或下载本地副本。

检查来源文件

决定是否安装前,请先阅读 SKILL.md,以及 SkillsMP 当前展示的配套文件。

正在显示 SKILL.md

SKILL.md
来源说明 · 只读预览
name
Format numbers
description
Format numbers using the formatNumber function from Shade whenever someone edits a TSX file.
autoTrigger
[{"fileEdit":"**/*.tsx"}]
# Format Numbers When editing `.tsx` files, ensure all user-facing numbers are formatted using the `formatNumber` utility from `@tryghost/shade/utils`. ## Import ```typescript import { formatNumber } from '@tryghost/shade/utils'; ``` ## When to use formatNumber Use `formatNumber()` when rendering any numeric value that is displayed to the user, including: - Member counts, visitor counts, subscriber counts - Email engagement metrics (opens, clicks, bounces) - Revenue amounts (combine with `centsToDollars()` for monetary values) - Post analytics (views, link clicks) - Any count or quantity shown in UI ## Correct usage ```tsx <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: ```tsx // 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 - `formatPercentage()` - for percentages (e.g., open rates, click rates) - `abbreviateNumber()` - for compact notation (e.g., 1.2M, 50k) - `centsToDollars()` - convert cents to dollars before passing to `formatNumber` All are imported from `@tryghost/shade/utils`.
在 GitHub 查看