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

@phragon-util/phone-state

v0.0.4

Published

`@phragon-util/phone-state` is a library for handling user-entered phone numbers, taking country codes into account. It provides convenient methods for working with phone numbers, including validation, formatting, country detection by code, and retrieving

Downloads

6

Readme

@phragon-util/phone-state

@phragon-util/phone-state is a library for handling user-entered phone numbers, taking country codes into account. It provides convenient methods for working with phone numbers, including validation, formatting, country detection by code, and retrieving additional country information.

Installation

npm install @phragon-util/phone-state

Key Features

  • Processing and validating phone numbers
  • Auto-detecting country code
  • Formatting phone numbers
  • Retrieving additional country information (flag, code, name)
  • Checking the existence of a country code

Code verification logic:

If the phone code starts with the + symbol, the library attempts to determine the country by code. If the + symbol is not specified, the library tries to determine the country based on the default country setting.

Usage

Creating a phone number state

import { createPhoneState } from "@phragon-util/phone-state";

const phoneState = createPhoneState("+14155552671");

console.log(phoneState);

// { 
//   input: "111 123-6969",
//   value: "+1 111 123-6969",
//   valid: true,
//   country: "US",
//   countryCallingCode: "+1"
// }

Updating the phone number state

As the first argument, the function can accept an input value, which is what the user enters without considering the country code.

import { reloadPhoneState } from "@phragon-util/phone-state";

const phoneState = reloadPhoneState("1111232671", phoneState);
console.log(phoneState);

Checking the existence of a country code

import { hasCountryCode } from "@phragon-util/phone-state";

console.log(hasCountryCode("US")); // true
console.log(hasCountryCode("XX")); // false

Retrieving country information by code

import { getPhoneTool } from "@phragon-util/phone-state";

const countryInfo = getPhoneTool("US");
console.log(countryInfo);

API

createPhoneState(phoneNumber: string, defaultCode?: string): PhoneState

Creates a phone number state, determining the country code and performing validation.

reloadPhoneState(phoneNumber: string, state: PhoneState): PhoneState

Updates the phone number state considering the current state.

hasCountryCode(value: string, strict?: boolean): boolean

Checks if the country code exists in the database.

getPhoneTool(code: string): PhoneTool | null

Returns country information (code, name, flag, phone code) by its code.

Types

PhoneState

Represents the state of a phone number, including country, calling code, input, value, and validity.

EmptyStateOptions

Options for creating an empty phone state.

PhoneTool

Represents detailed information about a country's phone number format.

Dependencies

libphonenumber-js: For parsing and formatting phone numbers.
iso-3166-1: For country code and name data.

Support

If you have any questions or suggestions, create an issue in the project repository.

License

MIT