以整数最小单位表示金额:ISO 货币、安全解析、舍入、无损分摊、.99 定价和格式化
代码4 个文件上下文约 423 个 token扫描通过
安装
$
genpm add @core/money你将获得
- 源代码位于 src/lib/money/,共 4 个文件。 (9.6 kB)
- AI 规则位于 src/lib/money/AGENTS.md,另附 IDE 规则文件。
- 自动为你解析 @core/contracts。
README
此包没有 README。
约 423 个 token→ src/lib/money/AGENTS.md→ .cursor/rules/genpm-core-money.mdc
这正是你的 AI 在 src/lib/money 中工作时读取的内容。不会向其上下文添加其他任何内容。
@core/money — rules for AI agents
Purpose
Money as { amount, currency } with amount an integer of minor units (cents) and an ISO 4217 code, so commerce
modules never use floats. Parsing from decimal strings, safe arithmetic that refuses mixed currencies, rounding,
percentages, lossless allocation (splitting a discount across lines), charm prices (.99, never below the input; …9 in zero-decimal currencies), formatting with Intl
and conversion with a rates table. Pure functions: no tables, no network.
Map
index.ts— public API:money,parseMoney,add,sub,sum,multiply,percent,allocate,charmPrice,format,toDecimalString,convert,currencyDecimals.money.ts— implementation. TheMoneytype comes from @core/contracts.
Integration
- Nothing to configure. Store money in two columns:
amount integer(minor units) andcurrency text. - User input:
parseMoney('19,99', 'EUR')(neverNumber(input) * 100). - Display:
format(price, locale); APIs/JSON-LD:toDecimalString(price). - Split amounts:
allocate(discount, lines.map((l) => l.subtotal.amount)). - Verify:
add(money(1, 'EUR'), money(1, 'USD'))throws.
Conventions
- All arithmetic through these helpers; JPY has 0 decimals and KWD 3, so never assume 100.
- Percentages round half-up by default; pass
'half-even'where your accounting requires it. - Exchange rates are inputs (store the rate used with each order); this module does not fetch them.
Don't
- Don't use floats for prices, totals or taxes, and don't add amounts of different currencies.
- Don't round intermediate results before the final step unless the business rule says so.
# @core/money — rules for AI agents
## Purpose
Money as `{ amount, currency }` with `amount` an integer of minor units (cents) and an ISO 4217 code, so commerce
modules never use floats. Parsing from decimal strings, safe arithmetic that refuses mixed currencies, rounding,
percentages, lossless allocation (splitting a discount across lines), charm prices (`.99`, never below the input; `…9` in zero-decimal currencies), formatting with `Intl`
and conversion with a rates table. Pure functions: no tables, no network.
## Map
- `index.ts` — public API: `money`, `parseMoney`, `add`, `sub`, `sum`, `multiply`, `percent`, `allocate`, `charmPrice`, `format`, `toDecimalString`, `convert`, `currencyDecimals`.
- `money.ts` — implementation. The `Money` type comes from @core/contracts.
## Integration
1. Nothing to configure. Store money in two columns: `amount integer` (minor units) and `currency text`.
2. User input: `parseMoney('19,99', 'EUR')` (never `Number(input) * 100`).
3. Display: `format(price, locale)`; APIs/JSON-LD: `toDecimalString(price)`.
4. Split amounts: `allocate(discount, lines.map((l) => l.subtotal.amount))`.
5. Verify: `add(money(1, 'EUR'), money(1, 'USD'))` throws.
## Conventions
- All arithmetic through these helpers; JPY has 0 decimals and KWD 3, so never assume 100.
- Percentages round half-up by default; pass `'half-even'` where your accounting requires it.
- Exchange rates are inputs (store the rate used with each order); this module does not fetch them.
## Don't
- Don't use floats for prices, totals or taxes, and don't add amounts of different currencies.
- Don't round intermediate results before the final step unless the business rule says so.
应用 .genpmignore 后将被注入的确切目录树。固定于
此包未声明 MCP 服务器。
| 版本 | 提交 | 发布时间 | 扫描 |
|---|---|---|---|
| 1.0.1 | e980a84 | 2小时前 | 扫描通过 |
- npm
- 无
- 建议
- GenPM 会给出 npm 命令建议,只有你同意时才会运行。
- 扫描
- 扫描通过 · 0 个问题
- 提交
- v1.0.1 → e980a84e69bda3afce0d0d5e1637a985e11a8dd0 · 获取后已校验
- 脚本
- 无。GenPM 从不运行包中的代码。
- 许可证
- MIT
- 质量
- 100/100
- 可识别的许可证已满足
- AGENTS.md 说明了用途已满足
- AGENTS.md 包含集成步骤已满足
- AGENTS.md 列出约定或禁止事项已满足
- 包含测试已满足
- 通过安全扫描已满足
- 最近 6 个月内发布已满足
- 已验证的发布者已满足
- 摘要和关键词已满足
- 举报
- 发现问题了吗?