UNPKG

xchange-rates

Version:

A lightweight Node.js package to get real-time currency exchange rates for any base currency using a pivot currency, fetched directly from a CDN for fast and reliable access.

350 lines (288 loc) โ€ข 9.54 kB
# ๐Ÿ“ˆ xchange-rates [![View on npm](https://img.shields.io/badge/npm-xchange--rates-red?logo=npm)](https://www.npmjs.com/package/xchange-rates) [![npm version](https://img.shields.io/npm/v/xchange-rates)](https://www.npmjs.com/package/xchange-rates) [![npm downloads](https://img.shields.io/npm/dm/xchange-rates)](https://www.npmjs.com/package/xchange-rates) A lightweight Node.js package and CLI tool to fetch **real-time currency exchange rates** between any two currencies. Exchange rate data is updated daily and served directly via **CDN** for **fast and reliable access**. --- โ˜• _This package runs on caffeine. If it helped you, consider buying me a coffee._ <a href="https://www.buymeacoffee.com/jayadevpanthaplavil" target="_blank"> <img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height:60px;width:auto;"> </a> --- ## โœจ Features - Fetch live exchange rates between **any two supported currencies** - Data refreshed **daily** via CDN - Works both as **Node.js library** and **CLI tool** - Simple, lightweight, no API key required ๐Ÿš€ - Unlimited data fetches --- ## ๐Ÿ“ฆ Installation ```bash npm install xchange-rates ``` Or with yarn: ```bash yarn add xchange-rates ``` --- ## ๐Ÿš€ Usage ### In Node.js ```js import { xchangerate } from "xchange-rates"; (async () => { const result = await xchangerate("USD", "INR"); console.log(result); })(); ``` **Output:** ```json { "date": "2025-08-17", "base": "USD", "target": "INR", "rate": 87.51385 } ``` --- ### In CLI ```bash xchangerate USD INR ``` **Output:** ```json { "date": "2025-08-17", "base": "USD", "target": "INR", "rate": 87.51385 } ``` --- ## ๐ŸŒ Supported Currencies This package supports **~180 currency codes** including **official national currencies, regional currencies, financial instruments, precious metals, and cryptocurrencies**. ## ๐Ÿ“Š At a Glance - **๐ŸŒ Total codes listed:** ~180 - **๐Ÿณ๏ธ Country & territory currencies:** ~150 - **๐Ÿค Regional/shared currencies:** 5+ - **๐Ÿ’ฐ Precious metals / commodities:** 3 (Gold, Silver, etc.) - **โ‚ฟ Cryptocurrencies:** 1 (Bitcoin) - **๐Ÿฆ Supranational / financial instruments:** 1 (IMF SDR) - **๐Ÿ“œ Obsolete / replaced codes:** 5+ --- ## ๐Ÿณ๏ธ National & Territory Currencies Most of the list are official national or territory currencies. Examples: - **USD** โ€“ United States Dollar ๐Ÿ‡บ๐Ÿ‡ธ - **INR** โ€“ Indian Rupee ๐Ÿ‡ฎ๐Ÿ‡ณ - **JPY** โ€“ Japanese Yen ๐Ÿ‡ฏ๐Ÿ‡ต - **GBP** โ€“ British Pound Sterling ๐Ÿ‡ฌ๐Ÿ‡ง - **AUD** โ€“ Australian Dollar ๐Ÿ‡ฆ๐Ÿ‡บ - **CAD** โ€“ Canadian Dollar ๐Ÿ‡จ๐Ÿ‡ฆ - โ€ฆand 140+ more, including currencies of smaller nations and overseas territories (e.g., **AWG** โ€“ Aruban Florin, **FKP** โ€“ Falkland Islands Pound). --- ## ๐Ÿค Regional / Shared Currencies - **EUR** โ€“ Euro (27 EU countries and territories) ๐Ÿ‡ช๐Ÿ‡บ - **XAF** โ€“ CFA Franc BEAC (Central Africa) - **XOF** โ€“ CFA Franc BCEAO (West Africa) - **XPF** โ€“ CFP Franc (French overseas territories) - **XCD** โ€“ East Caribbean Dollar --- ## ๐Ÿ’ฐ Precious Metals / Commodities - **XAU** โ€“ Gold (troy ounce) - **XAG** โ€“ Silver (troy ounce) - **XDR** โ€“ IMF Special Drawing Rights (supranational reserve asset) --- ## โ‚ฟ Cryptocurrency - **BTC** โ€“ Bitcoin --- ## ๐Ÿ“œ Obsolete / Replaced Some codes are obsolete or updated: - **BYR** โ€“ Old Belarusian Ruble โ†’ replaced by **BYN** - **STD** โ€“ Old Sรฃo Tomรฉ and Prรญncipe Dobra โ†’ replaced by **STN** - **ZMK** โ€“ Old Zambian Kwacha โ†’ replaced by **ZMW** - **SLL** โ€“ Old Sierra Leonean Leone โ†’ replaced by **SLE** - **PEN** โ€“ Nuevo Sol โ†’ now **Sol**, still uses PEN --- ## ๐Ÿ“– Standard Reference All codes follow **ISO 4217**: - 3-letter codes (e.g., **USD, INR, EUR**). - The first two letters usually represent the country (per ISO 3166), and the third the currency (e.g., **IN** + **R** = INR). - Codes beginning with **X** are reserved for **non-sovereign currencies, precious metals, supranational assets, or crypto**. --- <details> <summary>Click to expand</summary> **AED** โ€“ United Arab Emirates Dirham **AFN** โ€“ Afghan Afghani **ALL** โ€“ Albanian Lek **AMD** โ€“ Armenian Dram **ANG** โ€“ Netherlands Antillean Guilder **AOA** โ€“ Angolan Kwanza **ARS** โ€“ Argentine Peso **AUD** โ€“ Australian Dollar **AWG** โ€“ Aruban Florin **AZN** โ€“ Azerbaijani Manat **BAM** โ€“ Bosnia-Herzegovina Convertible Mark **BBD** โ€“ Barbadian Dollar **BDT** โ€“ Bangladeshi Taka **BGN** โ€“ Bulgarian Lev **BHD** โ€“ Bahraini Dinar **BIF** โ€“ Burundian Franc **BMD** โ€“ Bermudan Dollar **BND** โ€“ Brunei Dollar **BOB** โ€“ Bolivian Boliviano **BRL** โ€“ Brazilian Real **BSD** โ€“ Bahamian Dollar **BTC** โ€“ Bitcoin **BTN** โ€“ Bhutanese Ngultrum **BWP** โ€“ Botswanan Pula **BYN** โ€“ New Belarusian Ruble **BYR** โ€“ Belarusian Ruble **BZD** โ€“ Belize Dollar **CAD** โ€“ Canadian Dollar **CDF** โ€“ Congolese Franc **CHF** โ€“ Swiss Franc **CLF** โ€“ Chilean Unit of Account (UF) **CLP** โ€“ Chilean Peso **CNY** โ€“ Chinese Yuan **CNH** โ€“ Chinese Yuan Offshore **COP** โ€“ Colombian Peso **CRC** โ€“ Costa Rican Colรณn **CUC** โ€“ Cuban Convertible Peso **CUP** โ€“ Cuban Peso **CVE** โ€“ Cape Verdean Escudo **CZK** โ€“ Czech Republic Koruna **DJF** โ€“ Djiboutian Franc **DKK** โ€“ Danish Krone **DOP** โ€“ Dominican Peso **DZD** โ€“ Algerian Dinar **EGP** โ€“ Egyptian Pound **ERN** โ€“ Eritrean Nakfa **ETB** โ€“ Ethiopian Birr **EUR** โ€“ Euro **FJD** โ€“ Fijian Dollar **FKP** โ€“ Falkland Islands Pound **GBP** โ€“ British Pound Sterling **GEL** โ€“ Georgian Lari **GGP** โ€“ Guernsey Pound **GHS** โ€“ Ghanaian Cedi **GIP** โ€“ Gibraltar Pound **GMD** โ€“ Gambian Dalasi **GNF** โ€“ Guinean Franc **GTQ** โ€“ Guatemalan Quetzal **GYD** โ€“ Guyanese Dollar **HKD** โ€“ Hong Kong Dollar **HNL** โ€“ Honduran Lempira **HRK** โ€“ Croatian Kuna **HTG** โ€“ Haitian Gourde **HUF** โ€“ Hungarian Forint **IDR** โ€“ Indonesian Rupiah **ILS** โ€“ Israeli New Sheqel **IMP** โ€“ Manx Pound **INR** โ€“ Indian Rupee **IQD** โ€“ Iraqi Dinar **IRR** โ€“ Iranian Rial **ISK** โ€“ Icelandic Krรณna **JEP** โ€“ Jersey Pound **JMD** โ€“ Jamaican Dollar **JOD** โ€“ Jordanian Dinar **JPY** โ€“ Japanese Yen **KES** โ€“ Kenyan Shilling **KGS** โ€“ Kyrgystani Som **KHR** โ€“ Cambodian Riel **KMF** โ€“ Comorian Franc **KPW** โ€“ North Korean Won **KRW** โ€“ South Korean Won **KWD** โ€“ Kuwaiti Dinar **KYD** โ€“ Cayman Islands Dollar **KZT** โ€“ Kazakhstani Tenge **LAK** โ€“ Laotian Kip **LBP** โ€“ Lebanese Pound **LKR** โ€“ Sri Lankan Rupee **LRD** โ€“ Liberian Dollar **LSL** โ€“ Lesotho Loti **LYD** โ€“ Libyan Dinar **MAD** โ€“ Moroccan Dirham **MDL** โ€“ Moldovan Leu **MGA** โ€“ Malagasy Ariary **MKD** โ€“ Macedonian Denar **MMK** โ€“ Myanma Kyat **MNT** โ€“ Mongolian Tugrik **MOP** โ€“ Macanese Pataca **MRU** โ€“ Mauritanian Ouguiya **MUR** โ€“ Mauritian Rupee **MVR** โ€“ Maldivian Rufiyaa **MWK** โ€“ Malawian Kwacha **MXN** โ€“ Mexican Peso **MYR** โ€“ Malaysian Ringgit **MZN** โ€“ Mozambican Metical **NAD** โ€“ Namibian Dollar **NGN** โ€“ Nigerian Naira **NIO** โ€“ Nicaraguan Cรณrdoba **NOK** โ€“ Norwegian Krone **NPR** โ€“ Nepalese Rupee **NZD** โ€“ New Zealand Dollar **OMR** โ€“ Omani Rial **PAB** โ€“ Panamanian Balboa **PEN** โ€“ Peruvian Nuevo Sol **PGK** โ€“ Papua New Guinean Kina **PHP** โ€“ Philippine Peso **PKR** โ€“ Pakistani Rupee **PLN** โ€“ Polish Zloty **PYG** โ€“ Paraguayan Guarani **QAR** โ€“ Qatari Rial **RON** โ€“ Romanian Leu **RSD** โ€“ Serbian Dinar **RUB** โ€“ Russian Ruble **RWF** โ€“ Rwandan Franc **SAR** โ€“ Saudi Riyal **SBD** โ€“ Solomon Islands Dollar **SCR** โ€“ Seychellois Rupee **SDG** โ€“ South Sudanese Pound **SEK** โ€“ Swedish Krona **SGD** โ€“ Singapore Dollar **SHP** โ€“ Saint Helena Pound **SLE / SLL** โ€“ Sierra Leonean Leone **SOS** โ€“ Somali Shilling **SRD** โ€“ Surinamese Dollar **STD / STN** โ€“ Sรฃo Tomรฉ and Prรญncipe Dobra **SVC** โ€“ Salvadoran Colรณn **SYP** โ€“ Syrian Pound **SZL** โ€“ Swazi Lilangeni **THB** โ€“ Thai Baht **TJS** โ€“ Tajikistani Somoni **TMT** โ€“ Turkmenistani Manat **TND** โ€“ Tunisian Dinar **TOP** โ€“ Tongan Paสปanga **TRY** โ€“ Turkish Lira **TTD** โ€“ Trinidad and Tobago Dollar **TWD** โ€“ New Taiwan Dollar **TZS** โ€“ Tanzanian Shilling **UAH** โ€“ Ukrainian Hryvnia **UGX** โ€“ Ugandan Shilling **USD** โ€“ United States Dollar **UYU** โ€“ Uruguayan Peso **UZS** โ€“ Uzbekistan Som **VES** โ€“ Sovereign Bolivar **VND** โ€“ Vietnamese Dong **VUV** โ€“ Vanuatu Vatu **WST** โ€“ Samoan Tala **XAF** โ€“ CFA Franc BEAC **XAG** โ€“ Silver (troy ounce) **XAU** โ€“ Gold (troy ounce) **XCD** โ€“ East Caribbean Dollar **XCG** โ€“ Caribbean Guilder **XDR** โ€“ Special Drawing Rights **XOF** โ€“ CFA Franc BCEAO **XPF** โ€“ CFP Franc **YER** โ€“ Yemeni Rial **ZAR** โ€“ South African Rand **ZMK / ZMW** โ€“ Zambian Kwacha **ZWL** โ€“ Zimbabwean Dollar </details> --- ## ๐Ÿ”— Data Source All exchange rates are updated daily and served from CDN: ๐Ÿ‘‰ [https://cdn.jsdelivr.net/npm/xchange-rates@latest/v1/currencies.json](https://cdn.jsdelivr.net/npm/xchange-rates@latest/v1/currencies.json) --- ## ๐Ÿ“œ License [ISC](./LICENSE) โ€“ ยฉ Jayadev Panthaplavil