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

central-bank-russia

v1.0.1

Published

Library for fetching currency rates from Central Bank of Russia

Downloads

274

Readme

Central Bank of Russia (CBR) Rates

A lightweight, type-safe TypeScript library for fetching and processing official currency exchange rates from the Central Bank of Russia (CBR) API.

Features

  • Direct API Integration: Fetches real-time data from cbr.ru.
  • Automatic Encoding: Built-in Windows-1251 (CP1251) decoding for CBR's XML responses.
  • Strict Typing: Full TypeScript support with enums for currency codes.
  • Strict Mode: Optional strict mode that throws errors if a currency is missing, ensuring runtime safety.
  • Conversion Utilities: Easy-to-use methods for converting between foreign currencies and Russian Rubles (RUB).

Installation

npm install central-bank-russia
# or
bun add central-bank-russia

Quick Start

import { CBR } from 'central-bank-russia';

const cbr = new CBR(); // Strict mode enabled by default

// Get USD rate
const usd = await cbr.getCurrency('USD');
console.log(`1 USD = ${usd.course} RUB`);

// Convert 100 USD to Rubles
const rubles = usd.convert(100);
console.log(`100 USD is ${rubles} RUB`);

// Convert 1000 Rubles to USD
const amountInUsd = usd.convertFromRubles(1000);
console.log(`1000 RUB is ${amountInUsd.toFixed(2)} USD`);

Detailed Usage

Strict vs Non-Strict Mode

By default, the CBR class operates in Strict Mode. This provides:

  • Autocomplete for all currency codes (USD, EUR, etc.).
  • Guaranteed return values (throws an error if the currency is not found in the CBR response).
// Non-strict mode
const cbr = new CBR(false);

const rate = await cbr.getCurrency('ANY_CODE'); // returns Currency | undefined

Fetching Multiple Rates

const currencies = await cbr.getCurrencies();
currencies.forEach(cur => {
  console.log(`${cur.code}: ${cur.course}`);
});

Manual Cache Refresh

The library caches the rates after the first fetch. You can manually refresh them:

await cbr.refresh();

Recommended Resources

For more detailed metadata about currencies (names in multiple languages, symbols, countries, etc.), we highly recommend using:

👉 currency-codes-ts — A comprehensive database of ISO 4217 currency codes and metadata.

License

MIT