Skip to content

ninthsun91/country-code-enum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Country and Currency code in const Enum

last updated: 2024-03-30

This package contains const enums for,

  • Country code (ISO 3166-1 alpha-2) from Wikipedia
    • 249 officially assigned codes
    • 13 exceptionally reserved codes
    • 7 transitional reservations
  • Currency code (ISO 4217) from Wikipedia
    • 157 active currency codes

Usage

Both Country and Currency can be used as enum or union string type.

import { Country, Currency } from 'country-code-enum';

const country: Country = getCountry();
let currency: Currency;

switch (country) {
    // use as enum
    case Country.US:
        currency = Currency.USD;
        break;

    // use as union type - you still get auto-complete
    case 'EU':
        currency = 'EUR';

        // ERROR: Type '"Hello"' is not assignable to type 'Currency' .ts(2322)
        // currency = 'Hello';
        break;
}

Contribution

Any effort to make this package invaluable is appreciated.

Leave issues or PRs if there is any updates in standard codes or if you have suggestions.

About

Country and Currency code in const enum

Resources

Stars

Watchers

Forks