{"id":41717,"library":"phoneformat.js","title":"PhoneFormat.js","description":"A JavaScript telephone number formatting library based on Google's libphonenumber and compiled via Google Closure. Version 1.0.9 is the latest, last synced with libphonenumber v8.10.6. Provides formatting (E164, international, local), validation, country code lookup, and examples. Note: it may lag behind the latest libphonenumber; users can manually update the source via the Closure compiler. Provides AMD, CommonJS, and global builds. Lightweight alternative to libphonenumber-js or google-libphonenumber.","status":"maintenance","version":"1.0.9","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install phoneformat.js","lang":"bash","label":"npm"},{"cmd":"yarn add phoneformat.js","lang":"bash","label":"yarn"},{"cmd":"pnpm add phoneformat.js","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"In Node.js or bundlers, the package exports a single object with all methods. Use default import (ESM) or require (CJS). In browsers, use the global build and access `phoneFormat` on window.","wrong":"const phoneFormat = require('phoneformat.js');","symbol":"default","correct":"import phoneFormat from 'phoneformat.js'"},{"note":"All functions are properties of the default export object. Named exports are not available.","wrong":"import { countryForE164Number } from 'phoneformat.js';\nconst result = countryForE164Number('+14155552671');","symbol":"countryForE164Number","correct":"import phoneFormat from 'phoneformat.js';\nconst result = phoneFormat.countryForE164Number('+14155552671');"},{"note":"In CommonJS, the default export is the entire module. Do not append `.default`.","wrong":"const phoneFormat = require('phoneformat.js').default;\nconst formatted = phoneFormat.formatE164('US', '4155552671');","symbol":"formatE164","correct":"import phoneFormat from 'phoneformat.js';\nconst formatted = phoneFormat.formatE164('US', '4155552671');"}],"quickstart":{"code":"import phoneFormat from 'phoneformat.js';\n\n// Validate and format a US number\nconst number = '4155552671';\nconst country = 'US';\n\n// Check if valid\nconst isValid = phoneFormat.isValidNumber(number, country);\nconsole.log('Is valid:', isValid);\n\n// Format to E164\nconst e164 = phoneFormat.formatE164(country, number);\nconsole.log('E164:', e164);\n\n// Format to international\nconst international = phoneFormat.formatInternational(country, number);\nconsole.log('International:', international);\n\n// Format to local\nconst local = phoneFormat.formatLocal(country, number);\nconsole.log('Local:', local);\n\n// Phone number for mobile dialing\nconst mobileDial = phoneFormat.formatNumberForMobileDialing(country, number);\nconsole.log('Mobile dial:', mobileDial);\n\n// Clean phone (strip non-digits)\nconst cleaned = phoneFormat.cleanPhone('+1 (415) 555-2671');\nconsole.log('Cleaned:', cleaned);","lang":"javascript","description":"Demonstrates importing phoneFormat.js and using its key functions: validation, E164/international/local formatting, mobile dialing, and cleaning."},"warnings":[{"fix":"Manually update source via Closure compiler per README or switch to actively maintained library like libphonenumber-js or google-libphonenumber.","message":"Not compatible with latest libphonenumber; last synced v8.10.6.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Use default import: import phoneFormat from 'phoneformat.js'; then access methods as properties.","message":"All functions are on the default export object; named imports do not work.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use const phoneFormat = require('phoneformat.js'); not require(...).default.","message":"CommonJS require does not need .default; the module.exports is the phoneFormat object directly.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always provide country codes in uppercase (e.g., 'US' not 'us').","message":"Country codes must be uppercase ISO 3166-1 alpha-2 (e.g., 'US', 'GB'). Lowercase may not work.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.9':19 'altern':64 'amd':58 'base':8 'behind':43 'build':62 'closur':17,55 'code':35 'commonj':59 'compil':14,56 'countri':34 'e164':30 'exampl':38 'format':6,29 'global':61 'googl':10,16,71 'google-libphonenumb':70 'intern':31 'javascript':3,73 'js':68 'lag':42 'last':23 'latest':22,45 'libphonenumb':12,26,46,67,72 'libphonenumber-j':66 'librari':7 'lightweight':63 'local':32 'lookup':36 'manual':49 'may':41 'note':39 'number':5 'phoneformat.js':1 'provid':28,57 'sourc':52 'sync':24 'telephon':4 'updat':50 'user':47 'v8.10.6':27 'valid':33 'version':18 'via':15,53","created_at":"2026-06-04T18:53:45.925889+00:00","updated_at":"2026-06-04T18:53:45.925889+00:00","problems":[{"fix":"Change import statement to: import phoneFormat from 'phoneformat.js'; then use phoneFormat.isValidNumber().","cause":"Using named import instead of default import.","error":"TypeError: phoneFormat.isValidNumber is not a function"},{"fix":"Use the global build (phone-format-global.js) instead of the CommonJS one.","cause":"Using CommonJS build in a browser environment without a bundler.","error":"phoneformat.js:1 Uncaught ReferenceError: module is not defined"},{"fix":"Ensure the phone number is in E164 format (e.g., +14155552671) and valid.","cause":"Passing a national number without country code or invalid number.","error":"Error: countryForE164Number expects a valid international number string"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"phoneformat.js","openapi_spec":null,"status_page":null,"smithery":null,"categories":["communication"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}