Skip to content

Utility functions to map currency code to symbol and vice versa with TypeScript ๐Ÿ’™

Notifications You must be signed in to change notification settings

sirajalam049/currency-code-symbol-map

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Currency Code Symbol Map

Utility functions for currency symbols and codes.


Install

$ npm i currency-code-symbol-map

or

$ yarn install currency-code-symbol-map

Usage

It contains four utility functions along with a mapping of currency codes and symbols.

1. Map Codes from Symbol

A Symbol may belong to multiple codes. For example symbol for USD (US Dollar) and CAD (Canadian Dollar) is same, which is $. So this method returns an array of codes.

    import { getCodesFromSymbol } from "currency-code-symbol-map";

    console.log(getCodesFromSymbol('โ‚น')) 
    // INR

If

2. Map currency Symbol from Code

import { getSymbolFromCode } from "currency-code-symbol-map";

console.log(getSymbolFromCode('USD')) 
// $

console.log(getCodeFromSymbol('SOME INVALID SYMBOL'));
// undefined

3. Validate currency currency symbol

import { isValidCurrencySymbol } from "currency-code-symbol-map";

console.log(isValidCurrencySymbol('$')) 
// true

console.log(isValidCurrencySymbol('%'));
// false

4. Validate currency code

import { isValidCurrencyCode } from "currency-code-symbol-map";

console.log(isValidCurrencyCode('USD')) 
// true

console.log(isValidCurrencyCode('XYZ'));
// false

About

Utility functions to map currency code to symbol and vice versa with TypeScript ๐Ÿ’™

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published