libphonenumber-js is a JavaScript and TypeScript library designed for parsing, formatting, and validating international phone numbers. It serves as a significantly smaller and simpler rewrite of Google's original `libphonenumber` library. Currently at version 1.12.41, this package prioritizes a reduced bundle size (approximately 145 kB vs. 550 kB for the Google port) by focusing solely on personal phone numbers. It deliberately omits support for less common categories such as emergency numbers, short codes, numbers prefixed with `*`, Australian `13`-smart numbers, and alphabetic phone numbers like `1-800-GOT-MILK`. The library ships with comprehensive TypeScript definitions and uniquely offers functionality to search for phone numbers within text, a feature absent in Google's official JavaScript port. While a specific release cadence isn't detailed, the version history suggests active and ongoing development.
npm install libphonenumber-jsVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing, formatting, and validating phone numbers, including checking country-specific validity and retrieving calling codes.
Review your requirements; if special number types are critical, consider using the official (larger) Google `libphonenumber` JavaScript port or a different library that specifically supports them.
Wrap calls to `parsePhoneNumber` in a conditional check: `const phoneNumber = parsePhoneNumber(number); if (phoneNumber) { /* use phoneNumber */ }`.Consult the `libphonenumber-js` documentation or TypeScript types for the exact accepted format strings for `phoneNumber.format()`.
Always check if the result of `parsePhoneNumber(string)` is not `undefined` before attempting to access its properties. For example: `const num = parsePhoneNumber(str); if (num) { console.log(num.country); }`.Ensure `libphonenumber-js` is installed (`npm install libphonenumber-js`) and that your `tsconfig.json` includes `node_modules/@types` or has `"moduleResolution": "node"` set correctly.
Use ESM `import` statements instead: `import { parsePhoneNumber } from 'libphonenumber-js';`. If using CommonJS, ensure your file is a `.js` file or configured as such, and `require()` is appropriate for your environment.No dependency data recorded yet.