{"id":15416726,"url":"https://github.com/bunlong/libphonenumbers","last_synced_at":"2025-07-25T05:40:22.598Z","repository":{"id":41188423,"uuid":"305740474","full_name":"Bunlong/libphonenumbers","owner":"Bunlong","description":"JavaScript port of Google's libphonenumber library for parsing, formatting, and validating international phone numbers in Node.js.","archived":false,"fork":false,"pushed_at":"2020-10-30T13:41:47.000Z","size":451,"stargazers_count":10,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-08T18:52:22.132Z","etag":null,"topics":["format","libphonenumber","libphonenumbers","node","parser","phone","phonenumber","phonenumbers","phones"],"latest_commit_sha":null,"homepage":"https://libphonenumbers.js.org","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bunlong.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-20T14:47:14.000Z","updated_at":"2024-05-21T15:58:03.000Z","dependencies_parsed_at":"2022-08-25T16:01:32.034Z","dependency_job_id":null,"html_url":"https://github.com/Bunlong/libphonenumbers","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bunlong%2Flibphonenumbers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bunlong%2Flibphonenumbers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bunlong%2Flibphonenumbers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bunlong%2Flibphonenumbers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bunlong","download_url":"https://codeload.github.com/Bunlong/libphonenumbers/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233637703,"owners_count":18706616,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["format","libphonenumber","libphonenumbers","node","parser","phone","phonenumber","phonenumbers","phones"],"created_at":"2024-10-01T17:13:36.631Z","updated_at":"2025-01-12T17:33:07.115Z","avatar_url":"https://github.com/Bunlong.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/Bunlong/libphonenumbers/main/static/images/libphonenumbers-mini.png\" alt=\"libphonenumbers\" /\u003e\n\u003c/p\u003e\n\n# libphonenumbers\n\n\u003e libphonenumbers is JS port of [Google's libphonenumber](https://github.com/google/libphonenumber/tree/master/javascript).\n\nlibphonenumbers – JavaScript port of Google's libphonenumber library for parsing, formatting, and validating international phone numbers in Node.js.\n\n[![NPM](https://img.shields.io/npm/v/libphonenumbers.svg)](https://www.npmjs.com/package/libphonenumbers)\n\n## 🎁 Features\n\n\u003e libphonenumbers is compatible with both \u003cstrong\u003eJavaScript\u003c/strong\u003e and \u003cstrong\u003eTypeScript\u003c/strong\u003e.\n\n* PhoneNumberUtil\n  * [format(number, numberFormat)](#-formatnumber-numberformat) is used to formats a phone number in the specified format using default rules.\n  * [formatInOriginalFormat(number, regionCallingFrom)](#-formatinoriginalformatnumber-regioncallingfrom) is used to formats a phone number using the original phone number format that the number is parsed from.\n  * [formatOutOfCountryCallingNumber(number, regionCallingFrom)](#-formatoutofcountrycallingnumbernumber-regioncallingfrom) is used to formats a phone number for out-of-country dialing purposes.\n  * [getNumberType(number)](#-getnumbertypenumber) is used to gets the type of a valid phone number.\n  * [getRegionCodeForNumber(number)](#-getregioncodefornumbernumber) is used to gets the region where a phone number is from.\n  * [isPossibleNumber(number)](#-ispossiblenumbernumber) is used to checks whether a phone number is possible.\n  * [isValidNumber(number)](#-isvalidnumbernumber) is used to checks whether a phone number matches a valid pattern.\n  * [isValidNumberForRegion(number, regionCode)](#-isvalidnumberforregionnumber-regioncode) is used to checks whether a phone number is valid for a certain region.\n  * [parseAndKeepRawInput(numberToParse, defaultRegion)](#-parseandkeeprawinputnumbertoparse-defaultregion) is used to parses a string and returns it in prototype buffer format while keeping the raw input value.\n  * [parse(numberToParse, defaultRegion)](#-parsenumbertoparse-defaultregion) is used to parses a string and returns it in proto buffer format.\n\n* AsYouTypeFormatter\n  * [inputDigit(digit)](#-inputdigitdigit) is used to formats a phone number on-the-fly as each digit is entered.\n  * [clear()](#-inputdigitdigit) is used to clears the internal state of the formatter, so it can be reused.\n\n* PhoneNumberFormat ( The following enums is used to pass to [format(number, numberFormat)](#-formatnumber-numberformat) )\n  * E164 (value is 0)\n  * INTERNATIONAL (value is 1)\n  * NATIONAL (value is 2)\n  * RFC3966 (value is 3)\n\n* PhoneNumberType ( The following enums is used to compare with the output of [getNumberType(number)](#-getnumbertypenumber) )\n  * FIXED_LINE (value is 0)\n  * MOBILE (value is 1)\n  * FIXED_LINE_OR_MOBILE (value is 2)\n  * TOLL_FREE (value is 3)\n  * PREMIUM_RATE (value is 4)\n  * SHARED_COST (value is 5)\n  * VOIP (value is 6)\n  * PERSONAL_NUMBER (value is 7)\n  * PAGER (value is 8)\n  * UAN (value is 9)\n  * VOICEMAIL (value is 10)\n  * UNKNOWN (value is -1)\n\n* PhoneNumber\n  * [getCountryCode()](#-getcountrycode) is used to gets the value of the country code.\n  * [getCountryCodeSource()](#-getcountrycodesource) is used to gets the value of the country code source.\n  * [getExtension()](#-getextension) is used to gets the value of the extension.\n  * [getItalianLeadingZero()](#-getitalianleadingzero) is used to gets the value of the italian leading zero.\n  * [getNationalNumber()](#-getnationalnumber) is used to gets the value of the national number.\n  * [getRawInput()](#-getrawinput) is used to gets the value of the raw input.\n\n* CountryCodeSource ( The following enums is used to compare with the output of [getCountryCodeSource()](#-getcountrycodesource) )\n  * UNSPECIFIED (value is 0)\n  * FROM_NUMBER_WITH_PLUS_SIGN (value is 1)\n  * FROM_NUMBER_WITH_IDD (value is 5)\n  * FROM_NUMBER_WITHOUT_PLUS_SIGN (value is 10)\n  * FROM_DEFAULT_COUNTRY (value is 20)\n\n* ShortNumberInfo\n  * [connectsToEmergencyNumber(number, regionCode)](#-connectstoemergencynumbernumber-regioncode) is used to checks whether the short number can be used to connect to emergency services when dialed from the given region.\n  * [isPossibleShortNumber(number)](#-ispossibleshortnumbernumber) is used to checks whether a short number is a possible number.\n  * [isPossibleShortNumberForRegion(number, regionDialingFrom)](#-ispossibleshortnumberforregionnumber-regiondialingfrom) is used to checks whether a short number is a possible number when dialed from the given region.\n  * [isValidShortNumber(number)](#-isvalidshortnumbernumber) is used to checks whether a short number is a valid number.\n  * [isValidShortNumberForRegion(number, regionDialingFrom)](#-isvalidshortnumberforregionnumber-regiondialingfrom) is used to checks whether a short number matches a valid pattern in a region.\n\n## ❌ Missing Features:\n\nJS port of Google's libphonenumber does not support the following functions and classes:\n\n* findNumbers\n* PhoneNumberOfflineGeocoder\n* PhoneNumberToTimeZonesMapper\n* PhoneNumberToCarrierMapper\n\n## 🔧 Install\n\nlibphonenumbers is available on npm. It can be installed with the following command:\n\n```\nnpm install libphonenumbers --save\n```\n\nlibphonenumbers is available on yarn as well. It can be installed with the following command:\n\n```\nyarn add libphonenumbers\n```\n\n## 💡 Usage\n\n### 🎀 PhoneNumberUtil\n\n#### 📦 format(number, numberFormat)\n\nUsing Standard JavaScript:\n\n```js\nconst PNF = require('libphonenumbers').PhoneNumberFormat;\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance(); \n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Format number in the RFC3966 format\nconsole.log(phoneUtil.format(number, PNF.RFC3966));\n// tel:+1-202-456-2121\n\n// Format number in the national format\nconsole.log(phoneUtil.format(number, PNF.NATIONAL));\n// (202) 456-2121\n\n// Format number in the international format\nconsole.log(phoneUtil.format(number, PNF.INTERNATIONAL));\n// +1 202-456-2121\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\nconst PNF = libphonenumbers.PhoneNumberFormat;\n\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Format number in the RFC3966 format\nconsole.log(phoneUtil.format(number, PNF.RFC3966));\n// tel:+1-202-456-2121\n\n// Format number in the national format\nconsole.log(phoneUtil.format(number, PNF.NATIONAL));\n// (202) 456-2121\n\n// Format number in the international format\nconsole.log(phoneUtil.format(number, PNF.INTERNATIONAL));\n// +1 202-456-2121\n```\n\n#### 📦 formatInOriginalFormat(number, regionCallingFrom)\n\nUsing Standard JavaScript:\n\n```js\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Format number in the original format\nconsole.log(phoneUtil.formatInOriginalFormat(number, 'US'));\n// =\u003e (202) 456-2121\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Format number in the original format\nconsole.log(phoneUtil.formatInOriginalFormat(number, 'US'));\n// (202) 456-2121\n```\n\n#### 📦 formatOutOfCountryCallingNumber(number, regionCallingFrom)\n\nUsing Standard JavaScript:\n\n```js\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Format number in the out-of-country format from US\nconsole.log(phoneUtil.formatOutOfCountryCallingNumber(number, 'US'));\n// 1 (202) 456-2121\n\n// Format number in the out-of-country format from JP\nconsole.log(phoneUtil.formatOutOfCountryCallingNumber(number, 'JP'));\n// 010 1 202-456-2121\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Format number in the out-of-country format from US\nconsole.log(phoneUtil.formatOutOfCountryCallingNumber(number, 'US'));\n// 1 (202) 456-2121\n\n// Format number in the out-of-country format from JP\nconsole.log(phoneUtil.formatOutOfCountryCallingNumber(number, 'JP'));\n// 010 1 202-456-2121\n```\n\n#### 📦 getNumberType(number)\n\nUsing Standard JavaScript:\n\n```js\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Get type of phone number\nconsole.log(phoneUtil.getNumberType(number));\n// 2 // FIXED_LINE_OR_MOBILE\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Get type of phone number\nconsole.log(phoneUtil.getNumberType(number));\n// 2 // FIXED_LINE_OR_MOBILE\n```\n\n#### 📦 getRegionCodeForNumber(number)\n\nUsing Standard JavaScript:\n\n```js\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Get region code of number\nconsole.log(phoneUtil.getRegionCodeForNumber(number));\n// US\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Get region code of number\nconsole.log(phoneUtil.getRegionCodeForNumber(number));\n// US\n```\n\n#### 📦 isPossibleNumber(number)\n\nUsing Standard JavaScript:\n\n```js\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Check is possible number\nconsole.log(phoneUtil.isPossibleNumber(number));\n// true\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Check is possible number\nconsole.log(phoneUtil.isPossibleNumber(number));\n// true\n```\n\n#### 📦 isValidNumber(number)\n\nUsing Standard JavaScript:\n\n```js\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Get is valid number\nconsole.log(phoneUtil.isValidNumber(number));\n// true\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Get is valid number\nconsole.log(phoneUtil.isValidNumber(number));\n// true\n```\n\n#### 📦 isValidNumberForRegion(number, regionCode)\n\nUsing Standard JavaScript:\n\n```js\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Check number of a region is valid\nconsole.log(phoneUtil.isValidNumberForRegion(number, 'US'));\n// true\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Check number of a region is valid\nconsole.log(phoneUtil.isValidNumberForRegion(number, 'US'));\n// true\n```\n\n#### 📦 parseAndKeepRawInput(numberToParse, defaultRegion)\n\nUsing Standard JavaScript:\n\n```js\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n```\n\n#### 📦 parse(numberToParse, defaultRegion)\n\nUsing Standard JavaScript:\n\n```js\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance();\n\n// Get prototype buffer format\nconsole.log(phoneUtil.parse('123456', 'US'));\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Get proto buffer format\nconsole.log(phoneUtil.parse('123456', 'US'));\n```\n\n### 🎀 AsYouTypeFormatter\n\n#### 📦 inputDigit(digit)\n\nUsing Standard JavaScript:\n\n```js\nconst AsYouTypeFormatter = require('libphonenumbers').AsYouTypeFormatter;\n\n// Create an instance object of AsYouTypeFormatter\nconst formatter = new AsYouTypeFormatter('US');\n\nconsole.log(formatter.inputDigit('2')); // =\u003e 2\nconsole.log(formatter.inputDigit('0')); // =\u003e 20\nconsole.log(formatter.inputDigit('2')); // =\u003e 202\nconsole.log(formatter.inputDigit('-')); // =\u003e 202-\nconsole.log(formatter.inputDigit('4')); // =\u003e 202-4\nconsole.log(formatter.inputDigit('5')); // =\u003e 202-45\nconsole.log(formatter.inputDigit('6')); // =\u003e 202-456\nconsole.log(formatter.inputDigit('-')); // =\u003e 202-456-\nconsole.log(formatter.inputDigit('2')); // =\u003e 202-456-2\nconsole.log(formatter.inputDigit('1')); // =\u003e 202-456-21\nconsole.log(formatter.inputDigit('2')); // =\u003e 202-456-212\nconsole.log(formatter.inputDigit('1')); // =\u003e 202-456-2121\n\n// Clear all input digits from instance\nformatter.clear();\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\nconst AsYouTypeFormatter = libphonenumbers.AsYouTypeFormatter;\n\n// Create an instance object of AsYouTypeFormatter\nconst formatter = new AsYouTypeFormatter('US');\n\nconsole.log(formatter.inputDigit('2')); // 2\nconsole.log(formatter.inputDigit('0')); // 20\nconsole.log(formatter.inputDigit('2')); // 202\nconsole.log(formatter.inputDigit('-')); // 202-\nconsole.log(formatter.inputDigit('4')); // 202-4\nconsole.log(formatter.inputDigit('5')); // 202-45\nconsole.log(formatter.inputDigit('6')); // 202-456\nconsole.log(formatter.inputDigit('-')); // 202-456-\nconsole.log(formatter.inputDigit('2')); // 202-456-2\nconsole.log(formatter.inputDigit('1')); // 202-456-21\nconsole.log(formatter.inputDigit('2')); // 202-456-212\nconsole.log(formatter.inputDigit('1')); // 202-456-2121\n\n// Clear all input digits from instance\nformatter.clear();\n```\n\n### 🎀 PhoneNumber\n\n#### 📦 getCountryCode()\n\nUsing Standard JavaScript:\n\n```js\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance(); \n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Get the phone's country code\nconsole.log(number.getCountryCode());\n// 1\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Get the phone's country code\nconsole.log(number.getCountryCode());\n// 1\n```\n\n#### 📦 getCountryCodeSource()\n\nUsing Standard JavaScript:\n\n```js\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance(); \n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Get the phone's extension\nconsole.log(number.getCountryCodeSource());\n// FROM_DEFAULT_COUNTRY\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Print the phone's extension\nconsole.log(number.getCountryCodeSource());\n// FROM_DEFAULT_COUNTRY\n```\n\n#### 📦 getExtension()\n\nUsing Standard JavaScript:\n\n```js\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance(); \n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Print the phone's extension\nconsole.log(number.getExtension());\n// null\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Print the phone's extension\nconsole.log(number.getExtension());\n// =\u003e null\n```\n\n#### 📦 getItalianLeadingZero()\n\nUsing Standard JavaScript:\n\n```js\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance(); \n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Get phone's italian leading zero\nconsole.log(number.getItalianLeadingZero());\n// null\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Get phone's italian leading zero\nconsole.log(number.getItalianLeadingZero());\n// null\n```\n\n#### 📦 getNationalNumber()\n\nUsing Standard JavaScript:\n\n```js\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance(); \n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Get the phone's national number\nconsole.log(number.getNationalNumber());\n// 2024562121\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Get the phone's national number\nconsole.log(number.getNationalNumber());\n// 2024562121\n```\n\n#### 📦 getRawInput()\n\nUsing Standard JavaScript:\n\n```js\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance(); \n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Get the phone's raw input\nconsole.log(number.getRawInput());\n// 202-456-2121\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Get the phone's raw input\nconsole.log(number.getRawInput());\n// 202-456-2121\n```\n\n### 🎀 ShortNumberInfo\n\n#### 📦 connectsToEmergencyNumber(number, regionCode)\n\nUsing Standard JavaScript:\n\n```js\n// Get an instance of ShortNumberInfo\nconst shortInfo = require('libphonenumbers').ShortNumberInfo.getInstance();\n\n// Check 911 is emergency number in US\nconsole.log(shortInfo.connectsToEmergencyNumber('911', 'US'));\n// true\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Get an instance of ShortNumberInfo\nconst shortInfo = libphonenumbers.ShortNumberInfo.getInstance();\n\n// Check 911 is emergency number in US\nconsole.log(shortInfo.connectsToEmergencyNumber('911', 'US'));\n// true\n```\n\n#### 📦 isPossibleShortNumber(number)\n\nUsing Standard JavaScript:\n\n```js\n// Get an instance of ShortNumberInfo\nconst shortInfo = require('libphonenumbers').ShortNumberInfo.getInstance();\n\n// Get an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance();\n\n// Check 123456 is possible short number in FR\nconsole.log(shortInfo.isPossibleShortNumber(phoneUtil.parse('123456', 'FR')));\n// true\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Get an instance of ShortNumberInfo\nconst shortInfo = libphonenumbers.ShortNumberInfo.getInstance();\n\n// Get an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Check 123456 is possible short number in FR\nconsole.log(shortInfo.isPossibleShortNumber(phoneUtil.parse('123456', 'FR')));\n// true\n```\n\n#### 📦 isPossibleShortNumberForRegion(number, regionDialingFrom)\n\nUsing Standard JavaScript:\n\n```js\n// Get an instance of ShortNumberInfo\nconst shortInfo = require('libphonenumbers').ShortNumberInfo.getInstance();\n\n// Get an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance();\n\n// Check 123456 is possible short number for region in FR\nconsole.log(shortInfo.isPossibleShortNumberForRegion(phoneUtil.parse('123456', 'FR'), 'FR'));\n// true\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Get an instance of ShortNumberInfo\nconst shortInfo = libphonenumbers.ShortNumberInfo.getInstance();\n\n// Get an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Check 123456 is possible short number for region in FR\nconsole.log(shortInfo.isPossibleShortNumberForRegion(phoneUtil.parse('123456', 'FR'), 'FR'));\n// true\n```\n\n#### 📦 isValidShortNumber(number)\n\nUsing Standard JavaScript:\n\n```js\n// Get an instance of ShortNumberInfo\nconst shortInfo = require('libphonenumbers').ShortNumberInfo.getInstance();\n\n// Get an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Check 202-456-2121 is valid short number\nconsole.log(shortInfo.isValidShortNumber(number));\n// false\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Get an instance of ShortNumberInfo\nconst shortInfo = libphonenumbers.ShortNumberInfo.getInstance();\n\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Check 202-456-2121 is valid short number\nconsole.log(shortInfo.isValidShortNumber(number));\n// false\n```\n\n#### 📦 isValidShortNumberForRegion(number, regionDialingFrom)\n\nUsing Standard JavaScript:\n\n```js\n// Get an instance of ShortNumberInfo\nconst shortInfo = require('libphonenumbers').ShortNumberInfo.getInstance();\n\n// Get an instance of PhoneNumberUtil\nconst phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Check 202-456-2121 is valid short number for US region\nconsole.log(shortInfo.isValidShortNumberForRegion(number, 'US'));\n// false\n```\n\nUsing ECMAScript (ES):\n\n```js\nimport libphonenumbers from 'libphonenumbers';\n\n// Get an instance of ShortNumberInfo\nconst shortInfo = libphonenumbers.ShortNumberInfo.getInstance();\n\n// Create an instance of PhoneNumberUtil\nconst phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();\n\n// Parse number with US country code and keep raw input\nconst number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');\n\n// Check 202-456-2121 is valid short number for US region\nconsole.log(shortInfo.isValidShortNumberForRegion(number, 'US'));\n// false\n```\n\n## 🦄 Credits and Inspiration\n\nInspired by [Google's libphonenumber](https://github.com/google/libphonenumber).\n\n## ⚖️ License\n\nThe MIT License [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbunlong%2Flibphonenumbers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbunlong%2Flibphonenumbers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbunlong%2Flibphonenumbers/lists"}