Dinero en enteros (céntimos): monedas ISO, parseo seguro, redondeo, reparto sin pérdidas, precios .99 y formato
Instalar
genpm add @core/moneyQué obtienes
- Código en src/lib/money/, 4 archivos. (9,6 kB)
- Reglas de IA en src/lib/money/AGENTS.md, más archivos de reglas para tu IDE.
- Resuelve @core/contracts por ti.
README
Este paquete no tiene README.
Esto es exactamente lo que lee tu IA cuando trabaja en src/lib/money. No se añade nada más a su contexto.
@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.
El árbol exacto que se inyectará, tras aplicar .genpmignore. Anclado a
MIT License
Copyright (c) 2026 GenPM
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Este paquete no declara servidores MCP.
| Versión | Commit | Publicado | Escaneo |
|---|---|---|---|
| 1.0.1 | e980a84 | hace 3 horas | escaneo superado |
- npm
- ninguno
- propuesta
- GenPM propone el comando npm y solo lo ejecuta si dices que sí.
- escaneo
- escaneo superado · 0 hallazgos
- commit
- v1.0.1 → e980a84e69bda3afce0d0d5e1637a985e11a8dd0 · verificado tras la descarga
- scripts
- Ninguno. GenPM nunca ejecuta código del paquete.
- licencia
- MIT
- Calidad
- 100/100
- Licencia reconocidacumplido
- AGENTS.md explica su propósitocumplido
- AGENTS.md tiene pasos de integracióncumplido
- AGENTS.md lista convenciones o prohibicionescumplido
- Incluye testscumplido
- Escaneo de seguridad superadocumplido
- Publicado en los últimos 6 mesescumplido
- Publicador verificadocumplido
- Resumen y palabras clavecumplido
- reporte
- ¿Ves algo raro?