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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@holm/currency-codes-ts

v3.1.10

Published

A TypeScript library for ISO 4217 currency codes. Efficiently lookup and validate currency codes, retrieve associated countries, and more.

Downloads

4,527

Readme

Currency Codes TS

A TypeScript library for ISO 4217 currency codes. Efficiently lookup and validate currency codes, retrieve associated countries, and more.

This library is inspired by and originally forked from currency-codes. This version adds TypeScript support and will be periodically updated with the latest currency data.

Installation

npm install currency-codes-ts

Examples

Here's how you can use the library:

Code lookup

import { codes } from 'currency-codes-ts';

// get currency details
const euroInfo: CurrencyCodeRecord = codes('EUR');
console.log(euroInfo);  

/*
  {
    code: 'EUR',
    number: '978',
    digits: 2,
    currency: 'Euro',
    countries: [
      'Åland Islands', 'Andorra', 'Austria', 'Belgium', 'Croatia',
      'Cyprus', 'Estonia', 'European Union', 'Finland', 'France',
      'French Guiana', 'French Southern Territories (The)', 'Germany',
      'Greece', 'Guadeloupe', 'Holy See (The)', 'Ireland', 'Italy',
      'Latvia', 'Lithuania', 'Luxembourg', 'Malta', 'Martinique',
      'Mayotte', 'Monaco', 'Montenegro', 'Netherlands (The)',
      'Portugal', 'Réunion', 'Saint Barthélemy', 'Saint Martin (French Part)',
      'Saint Pierre and Miquelon', 'San Marino', 'Slovakia', 'Slovenia',
      'Spain'
    ]
  }
*/

Number Lookup

import { number } from 'currency-codes-ts';

console.log(number(967));

/*
  {
    code: 'ZMW',
    number: '967',
    digits: 2,
    currency: 'Zambian Kwacha',
    countries: [ 'Zambia' ]
  }
*/

Country Lookup

import { country } from 'currency-codes-ts';

console.log(country('Columbia'));

/*
  [
    {
      code: 'COP',
      number: '170',
      digits: 2,
      currency: 'Colombian Peso',
      countries: [ 'Colombia' ]
    },
    {
      code: 'COU',
      number: '970',
      digits: 2,
      currency: 'Unidad de Valor Real',
      countries: [ 'Colombia' ]
    }
  ]
*/

Get all Currency Codes

import { codes } from 'currency-codes-ts';

console.log(codes());

/*
  [
    'AED',
    'AFN',
    ...
    'ZAR',
    'ZMW'
  ]
*/

Get all Currency Numbers

import { numbers } from 'currency-codes-ts';

console.log(numbers());

/*
[
	'784',
	'971',
	...
	'710',
	'967'
]
*/

Get all Countries

import { countries } from 'currency-codes-ts';

console.log(countries());

/*
[ 
	'united arab emirates',
	'afghanistan',
	...
]
*/

Get all currency records

import { data } from 'currency-codes-ts';

console.log(data);

/*
[{
	code: 'AED',
	number: '784',
	digits: 2,
	currency: 'United Arab Emirates dirham',
	countries: ['united arab emirates']
}, {
	code: 'AFN',
	number: '971',
	digits: 2,
	currency: 'Afghan afghani',
	countries: ['afghanistan']
}, {
	...
}]
*/

Functions

  • code(code: string): Returns a CurrencyCodeRecord object based on ISO 4217 currency code. Returns undefined if not found.
  • country(country: string): Returns an array of CurrencyCodeRecord objects used in the given country.
  • number(number: number | string): Returns a CurrencyCodeRecord object based on ISO 4217 currency number. Returns undefined if not found.
  • codes(): Returns an array of ISO 4217 currency codes.
  • numbers(): Returns an array of ISO 4217 currency numbers.
  • countries(): Returns an array of country names.

Properties

  • data: Returns a CurrencyCodeRecord[] array containing all the available currency records.
  • publishDate: Returns the ISO formatted date the currencies were last updated.

Types

  • CurrencyCodeRecord: Defines the object returned on currency lookup. Includes properties like currency, code, countries, and digits.
interface CurrencyCodeRecord {
  code: CurrencyCode;
  number: string;
  digits: number;
  currency: string;
  countries: Country[];
}
  • CurrencyCode: The three-letter ISO 4217 code representing a currency (e.g., USD, EUR).
type CurrencyCode = "AED" | "AFN" | "ALL" | "AMD" | "[...]" | "ZMW" | "ZWL";
  • Country: A string representing the name of a country.
type Country = "United Arab Emirates (The)" | "Afghanistan" | "Albania" | "Armenia" | "[...]" | "Zambia" | "Zimbabwe";

Contributing

You can update the package with the latest currency data by running

npm run iso

This will update the data.ts and types.ts file based on the ingested data.

To build simply run tsc. This will create a build in the dist/ folder.

For contributions feel free to raise issues and pull requests.

License

MIT