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

@tamtamchik/exchanger

v4.0.1

Published

Simple and free npm library to get realtime currency exchange rates.

Readme

Exchanger fetches currency exchange rates from Yahoo Finance without an API key. It supports ES modules and CommonJS, includes TypeScript types, and provides optional in-memory caching and typed errors. Node.js 20 or later is required.

Quick Start

Install with npm:

npm install @tamtamchik/exchanger

Or with yarn:

yarn add @tamtamchik/exchanger

Fetch a rate:

import { getExchangeRate } from "@tamtamchik/exchanger";

const rate = await getExchangeRate("USD", "EUR");
console.log(`1 USD = ${rate} EUR`);

Usage

Pass the source and target currency codes to getExchangeRate. It returns a Promise<number> containing the rate for the pair. The Yahoo Finance request uses uppercase currency codes.

ES Modules

import { getExchangeRate } from "@tamtamchik/exchanger";

const rate = await getExchangeRate("USD", "EUR");
console.log(`1 USD = ${rate} EUR`);

CommonJS

const { getExchangeRate } = require("@tamtamchik/exchanger");

getExchangeRate("USD", "EUR")
  .then((rate) => console.log(`1 USD = ${rate} EUR`))
  .catch((error) => console.error(error));

Caching

Caching is disabled by default. Set cacheDurationMs to reuse a fetched rate for the same currency pair:

const rate = await getExchangeRate("USD", "EUR", {
  cacheDurationMs: 3_600_000, // One hour, in milliseconds.
});

The cache lives in memory and is lost when the process exits. Calls must enable caching to read cached rates. Use consistent letter case for currency codes; cache keys preserve the case you pass.

Error Handling

Exchanger exports three error classes, each extending Error:

| Error | Cause | | -------------- | ------------------------------------------------------------------ | | NetworkError | The request fails or the response cannot be parsed as JSON. | | ServerError | Yahoo Finance returns an unsuccessful HTTP status. | | DataError | The parsed response has a missing or invalid regularMarketPrice. |

import {
  DataError,
  NetworkError,
  ServerError,
  getExchangeRate,
} from "@tamtamchik/exchanger";

try {
  const rate = await getExchangeRate("USD", "EUR");
  console.log(`1 USD = ${rate} EUR`);
} catch (error) {
  if (error instanceof NetworkError) {
    console.error("Network or JSON parsing problem:", error.message);
  } else if (error instanceof ServerError) {
    console.error("Yahoo Finance HTTP error:", error.message);
  } else if (error instanceof DataError) {
    console.error("Unexpected response data:", error.message);
  } else {
    console.error("Unknown error:", error);
  }
}

Development Setup

Prerequisite: Node.js 24 (24.11 or later) or Node.js 26+ and its bundled npm. CI tests Node.js 24 and 26. The .nvmrc file selects Node.js 24; npm enforces the development runtime through devEngines. The published library retains its Node.js 20+ runtime requirement.

Install dependencies:

npm ci

Run the checks used in CI:

npm run check
npm run build
npm test

Biome checks and formats TypeScript and JSON files. Markdown and YAML files are not formatted by these commands. Coverage uses unit tests; npm test also runs acceptance tests against Yahoo Finance.

Useful focused commands:

npm run fix      # Format, organize imports, and apply safe lint fixes.
npm run dev      # Rebuild when source files change.
npm run coverage # Run unit tests and generate coverage reports.

Documentation

  • npm package: published versions and installation details.
  • Source: exchange-rate requests and cache behavior.
  • Tests: rate retrieval, caching, errors, and package acceptance checks.
  • Security policy: vulnerability reporting.
  • CI: formatting, lint, build, and test results.

Security Notes

Rates depend on Yahoo Finance availability and data. Exchanger returns a numeric rate; it does not execute currency exchanges.

Report vulnerabilities through GitHub's private vulnerability reporting. See SECURITY.md for the reporting policy.

Contributing

Pull requests are welcome. For major changes, open an issue first to discuss the proposal.

Support

License

MIT.