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

@erag/phone-number-vue

v1.0.2

Published

Minimal Vue composable for country-aware phone input, masking, calling codes, and validation.

Readme

@erag/phone-number-vue

Vue composable for building country-aware phone number fields without writing phone parsing logic from scratch. It manages selected country state, local digit cleanup, max-length handling, calling codes, masks, and basic phone length validation for custom Vue forms.

Key Features

  • 🌍 Country-aware phone input state.
  • 🔢 Local digit normalization and max-length truncation.
  • ✅ Validation based on selected country phone lengths.
  • 🎭 Mask pattern output without a masking dependency.
  • 📞 Calling code output for the selected country.
  • 🧩 Headless composable that works with any UI.
  • 📦 Built-in country and dial-code metadata.
  • 🛡️ Fully typed TypeScript support.

Installation

npm install @erag/phone-number-vue

Usage

<script setup lang="ts">
import { usePhoneNumber } from '@erag/phone-number-vue'

const { selectedCountry, countryOptions, mask, handleInput, localPhone, callingCode, isValid } =
    usePhoneNumber()
</script>

<template>
    <div>
        <select v-model="selectedCountry">
            <option
                v-for="country in countryOptions"
                :key="country.isoCode2 ?? country.key"
                :value="country"
            >
                {{ country.isoCode2 }} - {{ country.name }}
            </option>
        </select>

        <input
            v-model="localPhone"
            @input="handleInput"
            autocorrect="off"
            autocapitalize="off"
            spellcheck="false"
            inputmode="numeric"
            placeholder="Enter phone number"
        />

        <small>{{ callingCode }}</small>
        <small>{{ mask }}</small>
        <small>{{ isValid ? 'Valid phone number' : 'Enter a valid phone number' }}</small>
    </div>
</template>

Pass custom data or a Vue ref when you want to override the bundled static data:

import { ref } from 'vue'
import { usePhoneNumber, type PhoneNumberSharedData } from '@erag/phone-number-vue'

const customData = ref<PhoneNumberSharedData>({
    countries: [],
    dialCodes: []
})

const phone = usePhoneNumber(customData)

API

usePhoneNumber(dataOrRef) returns:

| Name | Type | Description | | ----------------- | ------------------------------------------------ | --------------------------------------------------------------------------------------------------------- | | selectedCountry | WritableComputedRef<PhoneCountry \| undefined> | Selected country object for object-based selects. | | countryOptions | ComputedRef<PhoneCountry[]> | Country list for select components. | | mask | ComputedRef<string> | Mask pattern for the selected country. | | handleInput | (valueOrEvent: PhoneInputValue) => boolean | Updates local digits or selected country, truncates by country length, and returns the validation result. | | localPhone | Ref<string> | Normalized local phone digits, truncated to the selected country's max length. | | callingCode | ComputedRef<string \| null> | Calling code for the selected country, for example +91. | | isValid | ComputedRef<boolean> | Phone validation result for the selected country. |

For example, India (IN) allows 10 local digits. Extra digits are removed automatically while typing.

Data Shape

type PhoneNumberSharedData = {
    countries?: PhoneCountry[]
    dialCodes?: PhoneDialCode[]
}

The package also exports the bundled data directly:

import { countries, dialCodes, phoneNumberData } from '@erag/phone-number-vue'

Country records can use either snake_case or camelCase phone length fields:

{
  name: 'United States',
  key: 'us',
  isoCode2: 'US',
  countryCodes: ['1'],
  phone_lengths: [10],
}

Scripts

  • npm run build: build ESM output with Vite 8 and TypeScript declarations.
  • npm run type-check: run TypeScript without emitting files.
  • npm run lint: format source files with Prettier.
  • npm run lint:check: verify source formatting.

License

MIT