Gathering detailed insights and metrics for awesome-phonenumber-fork
Gathering detailed insights and metrics for awesome-phonenumber-fork
Gathering detailed insights and metrics for awesome-phonenumber-fork
Gathering detailed insights and metrics for awesome-phonenumber-fork
Google's libphonenumber pre-compiled with the closure compiler
npm install awesome-phonenumber-fork
Typescript
Module System
Node Version
NPM Version
JavaScript (92.73%)
TypeScript (6.35%)
Shell (0.93%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
682 Stars
315 Commits
56 Forks
5 Watchers
2 Branches
7 Contributors
Updated on Jul 02, 2025
Latest Version
1.0.4
Package Id
awesome-phonenumber-fork@1.0.4
Unpacked Size
270.51 kB
Size
65.07 kB
File Count
7
NPM Version
6.11.3
Node Version
10.16.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
This library is a pre-compiled version of Google's libphonenumber
, with a slightly simpler interface. It has a minimal footprint - is by far the smallest libphonenumber-based library available on npmjs, and has no dependencies.
TypeScript typings are provided within the package.
Uses libphonenumber v8.12.1
Since this library is pre-compiled, it doesn't depend on the closure compiler, and needs not load it on start. This makes the library faster and saves you a lot of space. It also means this library is trivial to use in any browserify
project (or using any other means to run in the browser).
Among all the phone number libraries using Google's libphonenumber
, only this one, google-libphonenumber
(2.0.0) and node-phonenumber
(0.2.2) had decent README's with examples. Other libraries embedding the closure compiler should get comparable figures.
Loading the closure compiler also adds to the application memory usage (RSS is measured here). The library footprints are also bigger, making npm install
slower and increasing deploy times.
A test program loading a library, then parsing a phone number is called 100 times for each library, the mean values are:
Action | awesome-phonenumber (7.5.2) | google-libphonenumber (7.6.1) | node-phonenumber (7.5.2) |
---|---|---|---|
Load library first time | 20.84 ms | 60.99ms | 99.27 ms |
Parse first phone number | 5.79 ms | 6.51 ms | 8.15 ms |
Parse second phone number | 0.33 ms | 0.67 ms | 0.80 ms |
Increased memory usage | 7.3 M | 13.8 M | 22.5 M |
node_modules size | 248 K | 436 K | 57 M |
node_modules files | 7 | 7 | 4525 |
time npm install | 667 ms | 700 ms | 4077 ms |
1var PhoneNumber = require( 'awesome-phonenumber' ); 2 3var pn = new PhoneNumber( '0707123456', 'SE' ); 4pn.isValid( ); // -> true 5pn.isMobile( ); // -> true 6pn.canBeInternationallyDialled( ); // -> true 7pn.getNumber( ); // -> '+46707123456' 8pn.getNumber( 'e164' ); // -> '+46707123456' (default) 9pn.getNumber( 'international' ); // -> '+46 70 712 34 56' 10pn.getNumber( 'national' ); // -> '070-712 34 56' 11pn.getNumber( 'rfc3966' ); // -> 'tel:+46-70-712-34-56' 12pn.getNumber( 'significant' ); // -> '707123456' 13pn.getRegionCode( ); // -> 'SE' 14pn.getCountryCode( ); // -> 46 15 16pn.toJSON( ); // -> json blob, so that: 17JSON.stringify( pn, null, 4 ); // -> This: 18// { 19// "canBeInternationallyDialled": true, 20// "number": { 21// "input": "0707123456", 22// "international": "+46 70 712 34 56", 23// "national": "070-712 34 56", 24// "e164": "+46707123456", 25// "rfc3966": "tel:+46-70-712-34-56", 26// "significant": "707123456" 27// }, 28// "regionCode": "SE", 29// "valid": true, 30// "possible": true, 31// "type": "mobile", 32// "possibility": "is-possible" 33// }
When constructed with a phone number on e164
format (i.e. prefixed with a +
), awesome-phonenumber will auto-detect the country:
1PhoneNumber( '+46707123456' ).getRegionCode( ); // -> 'SE'
The API consists of the PhoneNumber
class which sometimes uses enums. These are:
1'fixed-line' 2'fixed-line-or-mobile' 3'mobile' 4'pager' 5'personal-number' 6'premium-rate' 7'shared-cost' 8'toll-free' 9'uan' 10'voip' 11'unknown'
1'is-possible' 2'invalid-country-code' 3'too-long' 4'too-short' 5'unknown'
1'international' 2'national' 3'e164' 4'rfc3966' 5'significant'
1var PhoneNumber = require( 'awesome-phonenumber' );
There are conversion functions between the 2-character ISO 3166-1 region codes (e.g. 'SE' for Sweden) and the corresponding country calling codes.
1PhoneNumber.getCountryCodeForRegionCode( regionCode ); // -> countryCode
2PhoneNumber.getRegionCodeForCountryCode( countryCode ); // -> regionCode
1PhoneNumber.getCountryCodeForRegionCode( 'SE' ); // -> 46
2PhoneNumber.getRegionCodeForCountryCode( 46 ); // -> 'SE'
1PhoneNumber.getSupportedCallingCodes( ); // -> [ calling codes... ]
1PhoneNumber.getSupportedRegionCodes( ); // -> [ region codes... ]
An instance of the PhoneNumber
class will be created even if PhoneNumber
is called as a function.
1var pn = PhoneNumber( number, regionCode );
2// is the same as
3var pn = new PhoneNumber( number, regionCode );
PhoneNumber objects can also be created using the getExample( regionCode[, type ] )
function, see section Example phone numbers for country below.
1pn.toJSON( ); // -> json blob as seen in "Basic usage" above 2pn.isValid( ); // -> Boolean 3pn.isPossible( ); // -> Boolean 4pn.getType( ); // -> Any of the "Phone number types" defined above 5pn.isMobile( ); // -> true if type is 'mobile' or 'fixed-line-or-mobile' 6pn.isFixedLine( ); // -> true if type is 'fixed-line' or 'fixed-line-or-mobile' 7pn.getNumber( [ format ] ); // -> Formatted number, see "Basic usage" for examples 8 9// Returns the number formatted to how to dial it from another region. 10pn.getNumberFrom( fromRegionCode );
1// Calling the Swedish number 0707123456 from Japan: 2PhoneNumber( '0707123456', 'SE' ).getNumberFrom( 'JP' ); // '010 46 70 712 34 56'
Sometimes you want to display a formatted example phone number for a certain country (and maybe also a certain type of phone number). The getExample
function is used for this.
1PhoneNumber.getExample( regionCode[, phoneNumberType] ); // PhoneNumber object
The phoneNumberType
is any of the types defined above.
1PhoneNumber.getExample( 'SE' ).getNumber( ); // '+468123456'
2PhoneNumber.getExample( 'SE', 'mobile' ).getNumber( ); // '+46701234567'
3PhoneNumber.getExample( 'SE', 'mobile' ).getNumber( 'national' ); // '070 123 45 67'
You can use an AsYouType
class to format a phone number as it is being typed. An instance of this class is retrieved by var ayt = PhoneNumber.getAsYouType( regionCode )
, and has the following methods:
1// Add a character to the end of the number 2ayt.addChar( nextChar ); 3 4// Get the current formatted number 5ayt.number( ); 6 7// Remove the last character 8ayt.removeChar( ); 9 10// Replace the whole number with a new number (or an empty number if null) 11ayt.reset( [ number ] ); 12 13// Get a PhoneNumber object representing the current number 14ayt.getPhoneNumber( );
All the functions above except getPhoneNumber( )
return the current formatted number (as a String of course, as it may include spaces and other characters).
1var ayt = PhoneNumber.getAsYouType( 'SE' ); 2ayt.addChar( '0' ); // -> '0' 3ayt.addChar( '7' ); // -> '07' 4ayt.addChar( '0' ); // -> '070' 5ayt.addChar( '7' ); // -> '070 7' 6ayt.addChar( '1' ); // -> '070 71' 7ayt.addChar( '2' ); // -> '070 712' 8ayt.addChar( '3' ); // -> '070 712 3' 9ayt.addChar( '4' ); // -> '070 712 34' 10ayt.addChar( '5' ); // -> '070 712 34 5' 11ayt.addChar( '6' ); // -> '070 712 34 56' 12ayt.removeChar( ); // -> '070 712 34 5' 13ayt.addChar( '7' ); // -> '070 712 34 57'
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
3 existing vulnerabilities detected
Details
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More