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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@shabsfr/i18n-iso-countries

v1.0.1

Published

Convert ISO 3166-1 country codes and retrieve localized country names in multiple languages with full TypeScript support

Readme

i18n-countries-ts

TypeScript library for converting ISO 3166-1 country codes and retrieving country names in multiple languages.

Based on: node-i18n-iso-countries but completely rewritten in TypeScript with Vite for a modern development experience.

Features

  • Code conversions: Convert between Alpha-2, Alpha-3, and numeric ISO codes
  • Localized names: Get country names in multiple languages
  • Name search: Find country codes by name in any registered language
  • Type-safe: Fully typed in TypeScript
  • Immutability: Loaded locales are immutable, preventing accidental mutations
  • Zero external dependencies: Only diacritics for normalization

Installation

npm install @shabsfr/i18n-countries

Usage

Register locales

You can load locales dynamically without explicitly importing JSON files:

import { loadLocale } from "@shabsfr/i18n-countries";

await loadLocale("es");
await loadLocale("en");

Or register them directly if you prefer:

import { registerLocale } from "@shabsfr/i18n-countries";
import esLocale from "@shabsfr/i18n-countries/locales/es.json";
import enLocale from "@shabsfr/i18n-countries/locales/en.json";

registerLocale(esLocale);
registerLocale(enLocale);

Convert codes

import {
  alpha2ToAlpha3,
  alpha3ToAlpha2,
  toAlpha2,
  toAlpha3,
} from "@shabsfr/i18n-countries";

alpha2ToAlpha3("ES"); // 'ESP'
alpha3ToAlpha2("USA"); // 'US'
toAlpha2("840"); // 'US' (numeric code)
toAlpha3("FR"); // 'FRA'

Get country names

import { getName } from "@shabsfr/i18n-countries";

getName("ES", "es"); // 'España'
getName("US", "en"); // 'United States'
getName("FR", "es"); // 'Francia'

// Advanced options
getName("ES", "es", { select: "all" }); // ['España', 'Reino de España']
getName("ES", "es", { select: "official" }); // 'España'
getName("ES", "es", { select: "alias" }); // 'Reino de España'

Search code by name

import { getCode } from "@shabsfr/i18n-countries";

getCode("España", "es"); // 'ES'
getCode("España", "es", { type: "alpha3" }); // 'ESP'
getCode("Spain", "en", { simple: true }); // 'ES' (ignores accents)

Utilities

import { isValid, langs, getSupportedLanguages } from "@shabsfr/i18n-countries";

isValid("ES"); // true
isValid("XX"); // false
isValid("840"); // true (numeric code)

langs(); // Array of registered languages
getSupportedLanguages(); // Array of supported languages by default

API

Main functions

registerLocale(localeData: LocaleData): void Registers localization data for a specific language.

alpha2ToAlpha3(code: Alpha2Code): Alpha3Code | undefined Converts Alpha-2 code to Alpha-3.

alpha3ToAlpha2(code: Alpha3Code): Alpha2Code | undefined Converts Alpha-3 code to Alpha-2.

toAlpha2(code: string | number): Alpha2Code | undefined Normalizes any code format to Alpha-2.

toAlpha3(code: string | number): Alpha3Code | undefined Normalizes any code format to Alpha-3.

getName(code: string | number, lang: string, options?: GetNameOptions): CountryName | undefined Gets the name of a country in a specific language.

getCode(name: string, lang: string, options?: { type?: CodeType; simple?: boolean }): Alpha2Code | Alpha3Code | undefined Searches for a country code by its name.

isValid(code: string | number): boolean Validates if a code is valid.

langs(): string[] Returns array of registered languages.

getSupportedLanguages(): string[] Returns array of supported languages by default.

Improvements over the original

  • Native TypeScript: Written in TypeScript for full type safety
  • Immutability: Registered locales cannot be modified after loading
  • Vite: Modern build tooling
  • Better validation: Runtime validation for data integrity
  • Modular architecture: Well-organized and maintainable code

License

MIT