A simple browser-side phone number formatter for HTML input elements. Current version 1.3.0 is stable but appears to have no recent updates. It only supports 10-digit US-style numbers and does not provide validation beyond formatting. Unlike robust libraries like libphonenumber, this package is minimal and targeted at basic input masking.
npm install phonenumber-formatterNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates how to import the default function and apply it to an input element after DOM ready.
Consider using libphonenumber-js or google-libphonenumber for international support.
Pass the DOM element directly: formatPhonenumbers(document.getElementById('phone')).Create a .d.ts file: declare module 'phonenumber-formatter' { const formatPhonenumbers: (el: HTMLInputElement, callback?: () => void) => void; export default formatPhonenumbers; }Add your own validation before or after formatting using a regex or validation library.
Use 'import formatPhonenumbers from 'phonenumber-formatter'' instead of 'import { formatPhonenumbers } from 'phonenumber-formatter''.Ensure default import: const formatPhonenumbers = require('phonenumber-formatter') and do not destructure.Guarantee the input exists and the DOM is loaded, e.g., by placing script at end of body or using DOMContentLoaded event.
No dependency data recorded yet.