moneyify:兼容 cashify 並內置即時匯率的貨幣轉換器
moneyify: A cashify-compatible currency converter with built-in live rates
moneyify 是兼容 cashify API 的貨幣轉換器,新增 Moneyify.live(),可從 AllRatesToday API 自動取得匯率,免去自行維護匯率表。它支援解析貨幣換算表達式、160+ 種貨幣及可選 big.js 精度計算,並提供 TypeScript、ESM、CJS 和 .d.ts。
If you've ever used cashify, you know the appeal: a tiny synchronous API for converting money, with expression parsing ("10 USD to EUR") and optional big.js precision.
The catch is that cashify stops there — you bring your own rates. In a real app, that means writing yet another fetch job, caching layer, and rate-refresh scheduler.
moneyify is a drop-in replacement that keeps the cashify API exactly the same, then adds one superpower: Moneyify.live() auto-fetches rates from the AllRatesToday API so you never need to maintain a rate table yourself.
What you get
- 💡 Drop-in cashify replacement — same sync
convert, same expression parsing, samebig.jssupport - 🌍 Auto-fetch 160+ currencies at mid-market rates, no retail spread
- 📦 Zero runtime dependencies
- 🧮 Optional
big.jsintegration for arbitrary-precision math - 💬 Parses expressions:
"10 USD to EUR","€10 EUR in GBP","1,250.5 usd in gbp" - 🟦 Written in TypeScript, ships ESM + CJS +
.d.ts
Install
npm install moneyify
1. Bring your own rates (identical to cashify)
import { Moneyify } from "moneyify";
const rates = { EUR: 1.00, GBP: 0.85, USD: 1.08 };
const m = new Moneyify({ base: "EUR", rates });
m.convert(10, { from: "EUR", to: "GBP" }); // 8.5
m.convert("10 EUR to GBP"); // 8.5
m.convert("€10 EUR in USD"); // 10.8
If you're already a cashify user, that's exactly the code you're used to — migrating is a rename.
2. Auto-fetch from AllRatesToday (the moneyify moat)
import { Moneyify } from "moneyify";
// Rates are fetched and cached on construction.
const m = await Moneyify.live({
base: "USD",
apiKey: process.env.ALLRATESTODAY_API_KEY,
});
m.convert(100, { from: "USD", to: "INR" }); // e.g. 8320.5
m.convert("50 USD to EUR"); // e.g. 46.17
One call, fresh rates, no manual table maintenance. Get a free API key at allratestoday.com/register — no credit card required.
3. Functional style (also cashify-compatible)
import { convert } from "moneyify";
convert(10, {
from: "EUR",
to: "GBP",
base: "EUR",
rates: { GBP: 0.85, EUR: 1.0 },
}); // 8.5
4. Parse expressions without converting
Useful for building chat bots, Slack commands, or any UI where users type free-form money strings:
import { parse } from "moneyify";
parse("10 EUR to GBP"); // { amount: 10, from: "EUR", to: "GBP" }
parse("€10 EUR"); // { amount: 10, from: "EUR" }
parse("1,250.5 usd in gbp"); // { amount: 1250.5, from: "USD", to: "GBP" }
Supported separators: to, in, as (case-insensitive). Supported symbols: $, €, £, ¥, ₹, ₽, ₺, ₩, ₪, R$, A$, C$, HK$, NZ$, S$.
5. Precision math with big.js
Float drift becomes painful when you're adding up thousands of line items. Plug in big.js and precision is preserved:
import Big from "big.js";
import { Moneyify } from "moneyify";
const m = new Moneyify({
base: "USD",
rates: { EUR: 0.923456789 },
BigJs: Big,
});
m.convert(100, { from: "USD", to: "EUR" }); // 92.3456789 (no float drift)
Why moneyify instead of cashify?
Short answer: when you don't want to own the rate-fetching problem.
- cashify — great library, but assumes you already have rates
-
moneyify — same API, plus a
live()constructor that handles rates for you
If your app is already fetching rates from somewhere, stay on cashify. If you want one package that does conversion and rate fetching, moneyify is the simpler surface.
Next steps
- npm:
moneyify - Free API key: allratestoday.com/register
- Docs: allratestoday.com
Tried it out? Let me know what you built — expressions parser gotchas especially welcome.
Written by the team behind AllRatesToday — a free, keyless
exchange rate API with real-time mid-market rates for 160+ currencies and
official central-bank rates from 120+ sources. Browse the API docs or
grab a free key to start building.
Open source: official SDKs for JavaScript, Python, PHP and Rust,
plus an MCP server (@allratestoday/mcp-server) for AI agents.
Follow along: LinkedIn ·
X / Twitter · GitHub
來源:DEV Community · dev.to