npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

docusaurus-plugin-unirate

v0.1.0

Published

Docusaurus v3 plugin for UniRate — fetch currency exchange rates, currencies, and VAT rates at build time and expose them as global plugin data plus a bundled <ExchangeRate /> theme component.

Readme

docusaurus-plugin-unirate

Docusaurus v3 plugin for UniRate — fetches a currency exchange-rate snapshot (and optionally the currency catalogue + VAT rates) at build time, exposes it as global plugin data, and ships a small <ExchangeRate /> theme component.

  • Build-time snapshot: rates resolve to constants in your static HTML; no client-side API key, no runtime fetch.
  • Zero runtime dependencies (uses native fetch).
  • Cross-pair conversion derived from a single base, so the payload stays small.
  • Full typed error mapping surfaced from the UniRate API.

Install

npm install docusaurus-plugin-unirate

You'll need a free UniRate API key — grab one at https://unirateapi.com.

Configure

// docusaurus.config.js
module.exports = {
  // ...
  plugins: [
    [
      "docusaurus-plugin-unirate",
      {
        apiKey: process.env.UNIRATE_API_KEY,
        baseCurrency: "USD",
        currencies: ["EUR", "GBP", "JPY", "CAD", "AUD"],
      },
    ],
  ],
};

If apiKey is omitted the plugin reads UNIRATE_API_KEY from the environment.

Options

| Option | Type | Default | Description | |---|---|---|---| | apiKey | string | process.env.UNIRATE_API_KEY | UniRate API key. | | baseCurrency | string | "USD" | Base the build-time snapshot is keyed against. | | currencies | string[] | all UniRate currencies | Optional allowlist to shrink the exposed payload. | | includeVat | boolean | false | Also fetch VAT rates and expose them as vatRates in the snapshot. | | apiBaseUrl | string | "https://api.unirateapi.com" | API host. Override for self-hosted or testing. | | failOnFetchError | boolean | true | Fail the build if the snapshot fetch fails. Set to false to ship an empty snapshot and let pages fall back gracefully. |

The <ExchangeRate /> component

import ExchangeRate from "@theme/ExchangeRate";

100 USD ≈ <ExchangeRate amount={100} from="USD" to="EUR" />
USD → GBP rate: <ExchangeRate from="USD" to="GBP" rateOnly />

| Prop | Type | Default | Description | |---|---|---|---| | to | string | — | Target currency (required). | | from | string | snapshot base | Source currency. | | amount | number | 1 | Amount to convert (ignored when rateOnly). | | rateOnly | boolean | false | Render the raw to-per-1-from rate instead of a formatted amount. | | ratePrecision | number | 4 | Decimals for the raw rate. | | fallback | string | "—" | Shown if a code isn't in the snapshot. |

minimumFractionDigits, maximumFractionDigits, currencyDisplay, and locale are forwarded to Intl.NumberFormat.

Reading the snapshot directly

The snapshot is registered as global plugin data:

import { usePluginData } from "@docusaurus/useGlobalData";

const snapshot = usePluginData("docusaurus-plugin-unirate");
// { base, rates, currencies, vatRates?, fetchedAt }

It's also written to unirate-snapshot.json via createData, so route/theme modules can import it statically.

Runtime helpers

import { convertCurrency, getRate, formatCurrency } from "docusaurus-plugin-unirate";

const snap = { base: "USD", rates: { USD: 1, EUR: 0.925 }, currencies: ["USD", "EUR"], fetchedAt: null };
formatCurrency(convertCurrency(snap, 100, "USD", "EUR"), "EUR"); // → "€92.50"

How the build works

The plugin's loadContent hook calls /api/rates?from=<baseCurrency> (plus /api/currencies and, with includeVat, /api/vat/rates) once per build. In contentLoaded, the resulting snapshot is published two ways: setGlobalData(snapshot) (readable with useGlobalData/usePluginData) and createData("unirate-snapshot.json", …) (importable JSON).

Cross-pair rates are derived: rate(from → to) = rate(base → to) / rate(base → from), so a USD-keyed snapshot can convert EUR → GBP without an extra fetch.

Error handling

The bundled client maps HTTP status codes to typed errors, all extending UniRateError:

| Status | Error | |---|---| | 400 | InvalidDateError | | 401 | AuthenticationError | | 403 | APIError (Pro subscription required) | | 404 | InvalidCurrencyError | | 429 | RateLimitError | | 503 / other | APIError | | network / transport | UniRateError |

By default a hard error fails the build; set failOnFetchError: false to warn and ship an empty snapshot instead.

Other UniRate clients

UniRate ships official client libraries and framework integrations across the ecosystem, all maintained under the UniRate-API org.

Get a free API key at unirateapi.com.

License

MIT