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

@mdfrough/country-phonenumber

v1.0.7

Published

A utility package for managing country phone numbers

Readme

🌍 CountryUtils

A TypeScript utility library for working with country data, flags, and phone number validations.


📦 Features

  • Get all country data or search by:
    • name, code, short_code
    • partial match or exact match
  • Generate flag image URLs (SVG, PNG, JPG, WEBP)
  • Validate phone number lengths against country rules

📥 Installation

npm i @mdfrough/country-phonenumber

📄 Usage

import { CountryUtils, FlagImageFormat, FlagSize, FlagSizeJpg} from '@mdfrough/country-phonenumber';


// Get all countries
const all = CountryUtils.getAll();

// Get flag
const svgFlag = CountryUtils.getCountryFlagSVG('US');
const pngFlag = CountryUtils.getCountryFlagPNG('US', FlagSize.Size_64x48);

// Validate number length
const isValid = CountryUtils.isNumberValidLength('+1 234-567-8901', 10, 10);

🧩 API

📘 Country Queries

| Method | Description | |--------|-------------| | getAll() | Returns all country data | | getCountryCodes() | Returns an array of all country codes | | getCountryByCode(code) | Finds a country by ISO code | | getCountryByShortCode(short) | Finds a country by lowercase short code | | getCountryByName(name) | Finds a country by name | | getCountryByNameOrCode(value) | Finds a country by matching name or code | | getCountryByShortCodeOrName(value) | Finds by short code or name |

🔍 Partial Match Search

| Method | Description | |--------|-------------| | getCountriesByName(name) | Partial match by name | | getCountriesByCode(code) | Partial match by ISO code | | getCountriesByShortCode(shortCode) | Partial match by short_code | | getCountriesByNameOrCode(value) | Partial match by name or code | | getCountriesByShortCodeOrName(value) | Partial match by short_code or name |

🧮 Length Filtering

| Method | Description | |--------|-------------| | getCountriesByMinLength(min) | Countries with min_length >= min | | getCountriesByMaxLength(max) | Countries with max_length <= max | | getCountriesByLength(min, max) | Countries with length between range |

🧠 Compound Filters

| Method | Description | |--------|-------------| | getCountriesByShortCodeAndName(short, name) | Exact match for both | | getCountriesByCodeAndName(code, name) | Exact match for both | | getCountriesByShortCodeAndCode(short, code) | Exact match for both | | getCountriesByNameAndCode(name, code) | Exact match for both | | getCountriesByNameAndShortCode(name, short) | Exact match for both |

| Match Combo | Description | |-------------|-------------| | getCountriesByShortCodeAndNameOrCode(short, nameOrCode) | Match short_code AND name/code (partial) | | getCountriesByCodeAndNameOrShortCode(code, nameOrShort) | Match code AND name/short_code (partial) | | getCountriesByShortCodeAndNameOrShortCode(short, nameOrShort) | Match short_code AND name/short_code (partial) |


🏁 Flag URLs

| Method | Description | |--------|-------------| | getCountryFlags(shortCode, format, size?) | Universal flag generator | | getCountryFlagSVG(shortCode) | Returns .svg URL | | getCountryFlagPNG(shortCode, size) | Returns .png URL | | getCountryFlagJPG(shortCode, size) | Returns .jpg URL | | getCountryFlagWEBP(shortCode, size) | Returns .webp URL |

🔢 Enums

  • FlagImageFormat: svg, png, webp, jpg
  • FlagSize: e.g. Size_32x24, Size_64x48
  • FlagSizeJpg: e.g. Size_160, Size_320, ..., Size_1280

✅ Phone Number Validation

utils.isNumberValidLength('+1 (123) 456-7890', 10, 10); // true
utils.isNumberValidLength('123456789', 10, 12); // false

Strips non-digit characters and checks if the cleaned number length is within range.


🧪 Tests

Run all unit tests using:

npm test
# or
vitest run

📁 Structure

src/
├── country.data.ts       # JSON-like list of countries
├── country.model.ts      # CountryData interface
├── flag.enum.ts          # Flag image enums
└── index.ts              # CountryUtils class

🛠 Author

Made with ❤️ by MDFrough



🌐 Flag Image Source

This package uses country flag images from FlagCDN.

📄 License

MIT