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

globalism

v0.2.1

Published

Comprehensive country data and utilities for phone numbers, addresses, and more

Readme

globalism

npm version License: MIT

Country data and utilities for phone validation, address formatting, and currency display — fully typed, zero runtime dependencies.

Install

npm install globalism
# or
yarn add globalism

Quick start

import {
  findCountryByAlpha2,
  analyzePhoneNumber,
  formatAddressLines,
  formatCurrency,
} from 'globalism';

const us = findCountryByAlpha2('US');

// Phone
analyzePhoneNumber('4155552671', us);
// → { status: 'complete', formatted: '(415) 555-2671', international: '+1 (415) 555-2671', ... }

// Address
formatAddressLines(
  { recipient: 'Jane Smith', house_number: '123', road: 'Main St',
    city: 'Springfield', state_code: 'IL', postcode: '62701' },
  us
);
// → ['Jane Smith', '123 Main St', 'Springfield, IL 62701', 'United States']

// Currency
formatCurrency(1234.56, us); // → '$1,234.56'

API

Data

| Export | Description | |---|---| | countries | Array of 250 Country objects | | countryGroups | Regional/political groupings (UN regions, EU, etc.) | | languages | ISO 639-1 language list (184 languages) |

Lookups

| Export | Description | |---|---| | findCountryByAlpha2(code) | Look up a country by 2-letter ISO code | | findCountryByAlpha3(code) | Look up a country by 3-letter ISO code | | findCountriesByGroup(groupId) | All countries belonging to a group | | findGroupById(id) | Look up a country group by ID | | findLanguageByCode(code) | Look up a language by ISO 639-1 code |

Phone

| Export | Description | |---|---| | analyzePhoneNumber(number, country) | Returns PhoneNumberState with status, formatted, and international forms | | validatePhoneNumber(number, country) | Returns boolean | | formatPhoneNumber(number, country) | Returns formatted string | | generatePhonePlaceholder(country) | Returns a #-masked placeholder string |

PhoneNumberState

{
  status: 'empty' | 'partial' | 'complete' | 'invalid';
  formatted: string;      // e.g. "(415) 555-2671"
  original: string;       // original input
  international: string;  // e.g. "+1 (415) 555-2671"
}

Address

| Export | Description | |---|---| | formatAddress(components, country) | Format as a newline-joined string | | formatAddressLines(components, country) | Format as string[], one line per element | | getRequiredAddressComponents(country) | Fields required by the country's template |

Address templates are sourced from OpenCageData address-formatting and use a Handlebars-style subset with {{field}}, {{{field}}}, and {{#first}}a || b{{/first}} syntax.

AddressComponents (all fields optional)

{
  recipient?, house_number?, house?, road?, neighbourhood?, suburb?,
  city_district?, city?, postal_town?, county?, state_code?, state?,
  postcode?, country?, country_code?
}

Currency

| Export | Description | |---|---| | formatCurrency(amount, country) | Format using Intl.NumberFormat | | formatCurrencyWithOptions(amount, country, options?) | With custom Intl.NumberFormatOptions | | getCurrencySymbol(country) | Return the currency symbol | | formatCurrencyParts(amount, country) | Return Intl.NumberFormatPart[] for custom rendering |

Country shape

{
  alpha2: string;           // 'US'
  alpha3: string;           // 'USA'
  name: string;             // 'United States'
  officialName: string;     // 'United States of America'
  flag: string;             // '🇺🇸'
  currency: string;         // 'USD'
  currencySymbol: string;   // '$'
  languages: string[];      // ['en']
  phoneCountryCode: string; // '+1'
  phoneRegexp?: string;     // national number pattern (libphonenumber-js)
  phoneFormat?: string;     // '#'-masked template, e.g. '(###) ###-####'
  tld: string;              // '.us'
  addressFormat?: string[]; // OpenCageData Mustache template lines
  groups: string[];         // group IDs this country belongs to
  postalCodeRegexp?: string;
  postalCodeFormat?: string;
}

Data sources

License

The library code is MIT. The published package bundles data from the sources above — the REST Countries data is CC BY-SA 4.0 (ShareAlike), meaning redistribution of that data must carry the same license. Packages that re-export the countries array should note this.