globalism
A TypeScript library for country data, phone number formatting, address formatting, and currency formatting.
npm install globalism
Interactive demos
What's included
- ~250 countries with ISO 3166-1 alpha-2 / alpha-3 codes, flags, and native names
- Phone country codes, format masks, and validation regexes
- Country group memberships (EU, NATO, G7, continents, …)
- 184 languages with ISO 639-1 codes, native names, and RTL flags
- Address format templates (OpenCageData) for country-aware rendering
- Currency codes, symbols, and
Intl.NumberFormathelpers
Quick start
import {
findCountryByAlpha2,
formatPhoneNumber,
formatAddress,
formatCurrency,
} from 'globalism';
const us = findCountryByAlpha2('US')!;
formatPhoneNumber('5551234567', us);
// → "(555) 123-4567"
formatAddress({ house_number: '1600', road: 'Pennsylvania Ave NW',
city: 'Washington', state_code: 'DC', postcode: '20500' }, us);
// → "1600 Pennsylvania Ave NW\nWashington, DC 20500"
formatCurrency(1234.56, us);
// → "$1,234.56"