country-code-enum
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

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.

Package Sidebar

Install

npm i country-code-enum

Weekly Downloads

238

Version

1.0.5

License

MIT

Unpacked Size

57.2 kB

Total Files

11

Last publish

Collaborators

  • ninthsun91