Installations
npm install fullstack-phone
Developer Guide
Typescript
No
Module System
N/A
Min. Node Version
>=4.0.0
Node Version
16.20.2
NPM Version
8.19.4
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (90.25%)
Shell (9.75%)
Developer
paypal
Download Statistics
Total Downloads
49,620
Last Day
11
Last Week
69
Last Month
410
Last Year
7,267
GitHub Statistics
91 Stars
478 Commits
18 Forks
18 Watching
5 Branches
19 Contributors
Package Meta Information
Latest Version
1.168.0
Package Id
fullstack-phone@1.168.0
Unpacked Size
1.06 MB
Size
94.78 kB
File Count
11
NPM Version
8.19.4
Node Version
16.20.2
Publised On
14 Dec 2024
Total Downloads
Cumulative downloads
Total Downloads
49,620
Last day
-70.3%
11
Compared to previous day
Last week
-59.9%
69
Compared to previous week
Last month
-49.4%
410
Compared to previous month
Last year
-22.7%
7,267
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
fullstack-phone ☎️
npm | Libphonenumber version |
---|---|
v8.13.52 |
fullstack-phone provides formatting, validation, and parsing of phone numbers per-region. The system is optimized for use as two modules:
- a metadata server providing dynamic regional metadata
- a lightweight, Closure-compiled phone client (27KB, 10KB gzipped)
This project was extended from Nathan Hammond's project, which itself is an adaptation of Google's libphonenumber library.
Contents
Installation
1npm install fullstack-phone
Usage
Demo App: fullstack-phone-demo
The modules are optimized for use in two environments.
On the server (requires Node 4+):
1// Node.js: 2var phoneServer = require('fullstack-phone/server'); 3 4var metadata = phoneServer.loadMeta(['US', 'RU']); // load US and RU phone metadata 5// now serve the metadata via some REST API or write it to a file for bundling with client code
On the client (assuming a client-side bundler that provides require
, like webpack):
1// Browser: 2var phoneClient = require('fullstack-phone/client'); 3 4// fetch the metadata somehow, then pass to createPhoneHandler to instantiate a handler: 5var phoneHandler = phoneClient.createPhoneHandler(metadata);
Once initialized, the phone handler can be used to process phone numbers:
1// phone handler functions: 2 3phoneHandler.getSupportedRegions(); // > ['US', 'RU'] 4 5phoneHandler.formatPhoneNumber( 6 { countryCode: '1', nationalNumber: '5101234567'}, 7 { style: 'national'} 8); 9// > '(510) 123-4567' 10 11phoneHandler.parsePhoneNumber('5101234567', 'US'); 12// > { countryCode: '1', nationalNumber: '5101234567' } 13 14phoneHandler.validatePhoneNumber( 15 { countryCode: '1', nationalNumber: '5101234567'}, 16 'US' 17); 18// > [Error: PHONE_INVALID_FOR_REGION]
It's also possible to use both within the same environment. Using the server module in the browser, however, nullifies the advantages of the per-region metadata slicing.
Why
Google’s libphonenumber library is the de-facto industry standard for processing international phone numbers, providing support for formatting, validating, and normalizing phone numbers in 250+ regions. However, the default phone metadata is quite heavy. Various custom JS packages have reduced the code & metadata footprint by:
- Simplifying the API and pre-compiling with Closure (grantila/awesome-phonenumber)
- Providing individually compiled code+metadata bundles for each region (leodido/i18n.phonenumbers.js, nathanhammond/libphonenumber)
- Rewriting the entire library without Closure and providing the option to dynamically load metadata for groups of regions (catamphetamine/libphonenumber-js)
This package fills a different niche by providing:
- The official libphonenumber code (not a pure JS re-write)
- A small, static code base that doesn’t change for different regions
- Pluggable metadata bundles for individual regions
Canonical Phone Object
When using Google libphonenumber directly, processing a phone number requires parsing a string or initializing a protocol buffer phone number object and calling setters for its various properties.
In contrast, fullstack-phone provides a more idiomatic JavaScript phone object, removing the need to call multiple setters. Most of the phone number functions here operate on a canonical phoneObj
, as follows:
1{ 2 countryCode : '1', 3 nationalNumber : '5105551234', 4 extension : '999' 5}
-
countryCode
- Required. A number or string of digits representing a country phone code, e.g.,
'1'
.
- Required. A number or string of digits representing a country phone code, e.g.,
-
nationalNumber
- Required. A number or string of digits representing a phone number, as defined by E.164, e.g.,
'4085551212'
. - Note that this excludes the leading national prefix (or "trunk code"), which is 0 or 1 in most territories.
- Italian leading zeros should be included here.
- Required. A number or string of digits representing a phone number, as defined by E.164, e.g.,
-
extension
- Optional. A string representing the phone number extension, e.g.,
'123'
.
- Optional. A string representing the phone number extension, e.g.,
Notes
For proper formatting and validation results, nationalNumber
and countryCode
must only contain digits. In addition, countryCode
must be the calling code of a country for which the phone handler was initialized. (For example, if a phoneObj
is passed with countryCode: 44
, the phone handler must have been loaded with GB metadata for proper results.)
The phoneObj
object can be created by calling parsePhoneNumber
on a phone number string.
APIs
Server
1var phoneServer = require('fullstack-phone/server');
The phone server exposes only one function:
loadMeta
phoneServer.loadMeta(regionCodeArray)
Given an array of two-letter region codes (ISO 3166-1 alpha-2), return a metadata bundle for those regions, to be passed to phoneClient.createPhoneHandler()
.
Notes:
- If
regionCodeArray
is undefined, all regional metadata is returned. loadMeta
adds support for the following regions to Google libphonenumber:- PN: Pitcairn Islands (copied from New Zealand metadata)
- AN: Netherlands Antilles (copied from Bonaire, Sint Eustatius and Saba)
- Some regions depend on metadata of other regions. For example, the Bahamas (BS) shares a telephone country code (1) with the United States (US). Since the US is considered the main region for country code 1, the US metadata must be included to support processing of Bahamas phone numbers.
loadMeta
takes care of this automatically.
The full list of region codes supported is:
1['001', 'AC', 'AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AN', 'AO', 'AR', 'AS', 'AT', 'AU', 'AW', 'AX', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BL', 'BM', 'BN', 'BO', 'BQ', 'BR', 'BS', 'BT', 'BW', 'BY', 'BZ', 'CA', 'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN', 'CO', 'CR', 'CU', 'CV', 'CW', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG', 'EH', 'ER', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM', 'FO', 'FR', 'GA', 'GB', 'GD', 'GE', 'GF', 'GG', 'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR', 'GT', 'GU', 'GW', 'GY', 'HK', 'HN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IM', 'IN', 'IO', 'IQ', 'IR', 'IS', 'IT', 'JE', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KP', 'KR', 'KW', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'ME', 'MF', 'MG', 'MH', 'MK', 'ML', 'MM', 'MN', 'MO', 'MP', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NC', 'NE', 'NF', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA', 'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PM', 'PN', 'PR', 'PS', 'PT', 'PW', 'PY', 'QA', 'RE', 'RO', 'RS', 'RU', 'RW', 'SA', 'SB', 'SC', 'SD', 'SE', 'SG', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'SS', 'ST', 'SV', 'SX', 'SY', 'SZ', 'TA', 'TC', 'TD', 'TG', 'TH', 'TJ', 'TK', 'TL', 'TM', 'TN', 'TO', 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'US', 'UY', 'UZ', 'VA', 'VC', 'VE', 'VG', 'VI', 'VN', 'VU', 'WF', 'WS', 'XK', 'YE', 'YT', 'ZA', 'ZM', 'ZW']
Note that '001'
is used to load metadata for global numbers, such as 1-800 numbers.
Examples
1var meta = phoneServer.loadMeta(['DE', 'AU']); 2// > metadata object for DE and AU 3 4var meta = phoneServer.loadMeta(); 5// > metadata object for all regions
Client
1var phoneClient = require('fullstack-phone/client');
The phone client exposes only one function:
createPhoneHandler
phoneClient.createPhoneHandler(metadata)
Given a metadata bundle from phoneServer.loadMeta()
, return a phone handler instantiated for that metadata.
Phone Handler
1var phoneHandler = phoneClient.createPhoneHandler(metadata);
The phone handler returned by createPhoneHandler
provides the following methods:
- getSupportedRegions
- countryCodeToRegionCodeMap
- getCountryCodeForRegion
- formatPhoneNumber
- validatePhoneNumber
- validateLength
- parsePhoneNumber
- getExampleNumberForType
- inferPhoneNumberRegion
- inferPhoneNumberType
- getAsYouTypeFormatter
Exceptions
Any method that takes a phoneObj
parameter can throw the following exception if called with an invalid canonical phone object:
1phoneHandler.inferPhoneNumberType(123); 2// Uncaught Error: Phone object conversion failed 3 4phoneHandler.inferPhoneNumberType({ countryCode: 1, nationalNumber: false }); 5// Uncaught Error: Phone object conversion failed
Any method that takes a regionCode
string can throw the following exception if called with a region code for which the handler has not been initialized:
1phoneHandler.getCountryCodeForRegion(); 2// Uncaught Error: Metadata not loaded for region: undefined 3 4phoneHandler.getCountryCodeForRegion('XX'); 5// Uncaught Error: Metadata not loaded for region: XX
getSupportedRegions
phoneHandler.getSupportedRegions()
Return array of supported region codes.
Note that if a dependent region was loaded (such as the Bahamas), the main region for the shared country code is also reported a supported region (e.g., US).
Example
1phoneHandler.getSupportedRegions(); 2// > ['US', 'RU']
countryCodeToRegionCodeMap
phoneHandler.countryCodeToRegionCodeMap()
Return map from country calling codes to array of supported regions.
Example
1phoneHandler.countryCodeToRegionCodeMap(); 2// > { '1': [ 'US', 'BS' ], '7': [ 'RU' ] }
getCountryCodeForRegion
phoneHandler.getCountryCodeForRegion(regionCode)
Return a country calling code as a number, given a regionCode
string (assuming metadata has already been loaded for that region).
Example
1phoneHandler.getCountryCodeForRegion('RU'); 2// > 7
formatPhoneNumber
phoneHandler.formatPhoneNumber(phoneObj, options)
Return a formatted phone number as a string, given a phoneObj
object and options
object with a valid style
property ('national'
, 'international'
, 'e164'
, or 'rfc3966'
).
The options
object has a single string property to indicate the formatting style desired:
1{ 2 style: 'national' // or 'international', 'e164', 'rfc3966' 3}
Examples
1var phone = { countryCode: '1', nationalNumber: '5101234567' }; 2 3phoneHandler.formatPhoneNumber(phone, { style: 'international' }); 4// > '+1 510-123-4567' 5 6phoneHandler.formatPhoneNumber(phone, { style: 'national' }); 7// > '(510) 123-4567' 8 9phoneHandler.formatPhoneNumber(phone, { style: 'e164' }); 10// > '+15101234567' 11 12phoneHandler.formatPhoneNumber(phone, { style: 'rfc3966' }) 13// > 'tel:+1-510-123-4567'
validatePhoneNumber
phoneHandler.validatePhoneNumber(phoneObj, ?regionCode)
Perform full validation on a phone number: Given a phoneObj
object and optional regionCode
string, return an Error object indicating any problems with the phone object (or true
if it passed validation).
If regionCode
is provided, the phone number is validated for the given region. If it is omitted, the phone number is validated for the region inferred from the number itself. In both cases, the handler needs to have already been instantiated with metadata for the expected region(s).
The possible error messages are:
'PHONE_INVALID_FOR_REGION'
- Phone number is not valid for some reason. (See the examples below.)
'PHONE_INVALID_COUNTRY_CODE'
- The
phoneObj.countryCode
is not recognized for one of these reasons:- It's completely invalid (like '9999'),
- Metadata has not been loaded for the region corresponding to
phoneObj.countryCode
, or - It does not correspond to to the
regionCode
passed.
- The
'PHONE_NUMBER_TOO_LONG'
'PHONE_NUMBER_TOO_SHORT'
'PHONE_NUMBER_INVALID_LENGTH'
- Phone number is not too long, not too short, but not just right, either. For example, Andorra (AD) numbers are 6, 8, or 9 digits, so a 7-digit number yields this error.
Examples
1// valid US phone number 2phoneHandler.validatePhoneNumber({ countryCode: '1', nationalNumber: '5105261234' }, 'US'); 3// > true 4 5// regionCode is optional 6phoneHandler.validatePhoneNumber({ countryCode: '1', nationalNumber: '5105261234' }); 7// > true 8 9phoneHandler.validatePhoneNumber({ countryCode: '1', nationalNumber: '5' }, 'US'); 10// > [Error: PHONE_NUMBER_TOO_SHORT] 11 12phoneHandler.validatePhoneNumber({ countryCode: '1', nationalNumber: '51052612341' }, 'US'); 13// > [Error: PHONE_NUMBER_TOO_LONG] 14 15// 10 digits (like a US phone number), but not an actual valid number 16phoneHandler.validatePhoneNumber({ countryCode: '1', nationalNumber: '1234567890' }, 'US'); 17// > [Error: PHONE_INVALID_FOR_REGION] 18phoneHandler.validatePhoneNumber({ countryCode: '1', nationalNumber: '1234567890' }); 19// > [Error: PHONE_INVALID_FOR_REGION] 20 21// completely invalid countryCode 22phoneHandler.validatePhoneNumber({ countryCode: '999', nationalNumber: '5105261234' }, 'US'); 23// > [Error: PHONE_INVALID_COUNTRY_CODE] 24 25// countryCode 44 is for GB, but US regionCode was passed 26phoneHandler.validatePhoneNumber({ countryCode: '44', nationalNumber: '1212345678' }, 'US'); 27// > [Error: PHONE_INVALID_COUNTRY_CODE] 28 29// valid GB number 30phoneHandler.validatePhoneNumber({ countryCode: '44', nationalNumber: '1212345678' }, 'GB'); 31// > true 32phoneHandler.validatePhoneNumber({ countryCode: '44', nationalNumber: '1212345678' }); 33// > true
validateLength
phoneHandler.validateLength(phoneObj, ?regionCode)
Perform minimal validation (length check only) on a phone number: Given a phoneObj
object and optional regionCode
string, return an Error object indicating any length problems with the phone object (or true
if it passed the length validation).
If regionCode
is provided, the phone number is validated for the given region. If it is omitted, the phone number is validated for the region inferred from the number itself. In both cases, the handler needs to have already been instantiated with metadata for the expected region(s).
The possible error messages are:
'PHONE_INVALID_COUNTRY_CODE'
- The
phoneObj.countryCode
is not recognized for one of these reasons:- It's completely invalid (like '9999'),
- Metadata has not been loaded for the region corresponding to
phoneObj.countryCode
, or - It does not correspond to to the
regionCode
passed.
- The
'PHONE_NUMBER_TOO_LONG'
'PHONE_NUMBER_TOO_SHORT'
'PHONE_NUMBER_INVALID_LENGTH'
- The phone number is not too long, not too short, but not just right, either. For example, Andorra (AD) numbers are 6, 8, or 9 digits, so a 7-digit number yields this error.
'PHONE_NUMBER_POSSIBLE_LOCAL_ONLY'
- The phone number could be dialed within a local area (e.g., US numbers without the area code) but is not long enough to be a full phone number dialable from anywhere.
'PHONE_INVALID_FOR_REGION
'- Fallback error: This error would only be returned if libphonenumber adds a new enum member to ValidationResult.
Examples
1// any 10-digit phone number in the US passes validateLength 2phoneHandler.validateLength({ countryCode: '1', nationalNumber: '1234567890' }, 'US'); 3// > true 4 5// regionCode is optional 6phoneHandler.validateLength({ countryCode: '1', nationalNumber: '1234567890' }); 7// > true 8 9// 7-digit numbers are only possible locally in the US 10phoneHandler.validateLength({ countryCode: '1', nationalNumber: '1234567' }, 'US'); 11// > [Error: PHONE_NUMBER_POSSIBLE_LOCAL_ONLY] 12 13// 6-digit numbers are too short in the US 14phoneHandler.validateLength({ countryCode: '1', nationalNumber: '123456' }, 'US'); 15// > [Error: PHONE_NUMBER_TOO_SHORT] 16 17// 11-digit numbers are too long in the US 18phoneHandler.validateLength({ countryCode: '1', nationalNumber: '12345678901' }, 'US'); 19// > [Error: PHONE_NUMBER_TOO_LONG] 20 21// wrong regionCode yields PHONE_INVALID_COUNTRY_CODE (regionCode AD does not match countryCode 1) 22phoneHandler.validateLength({ countryCode: '1', nationalNumber: '1234567890' }, 'AD'); 23// > [Error: PHONE_INVALID_COUNTRY_CODE] 24 25// a completely invalid countryCode (999) also yields PHONE_INVALID_COUNTRY_CODE 26phoneHandler.validateLength({ countryCode: '999', nationalNumber: '1234567890' }); 27// > [Error: PHONE_INVALID_COUNTRY_CODE] 28 29// 7-digit number in Andorra (regionCode AD, countryCode 376) is in between valid number lengths 30phoneHandler.validateLength({ countryCode: '376', nationalNumber: '1234567' }, 'AD'); 31// > [Error: PHONE_NUMBER_INVALID_LENGTH]
parsePhoneNumber
phoneHandler.parsePhoneNumber(phoneNumberToParse, ?regionCode)
Parse a string and return a phoneObj
object (or an Error object if parsing failed), given the string parameters phoneNumberToParse
and optional regionCode
.
The optional regionCode
parameter provides a fallback if the country code cannot be extracted from the phoneNumberToParse
string. If the string contains +
followed by the country code, then regionCode
can be safely omitted. In both cases, however, the handler needs to have already been instantiated with metadata for the expected region(s).
The possible error messages are:
'PHONE_INVALID_COUNTRY_CODE'
'PHONE_NUMBER_TOO_SHORT'
'PHONE_NUMBER_TOO_LONG'
'PHONE_NOT_A_NUMBER'
'PHONE_TOO_SHORT_AFTER_IDD'
Examples
1phoneHandler.parsePhoneNumber('5101234567', 'US'); 2// > { countryCode: '1', nationalNumber: '5101234567' } 3 4phoneHandler.parsePhoneNumber('ABC', 'US'); 5// > [Error: PHONE_NOT_A_NUMBER] 6 7// regionCode is optional if string has '+' followed by country code 8phoneHandler.parsePhoneNumber('+1 510-123-4567'); // international format 9phoneHandler.parsePhoneNumber('+15101234567'); // E.164 format 10phoneHandler.parsePhoneNumber('tel:+1-510-123-4567'); // RFC 3966 format 11// > { countryCode: '1', nationalNumber: '5101234567' } 12 13// Do not omit regionCode if phoneNumberString is missing '+' 14phoneHandler.parsePhoneNumber('15101234567'); 15// > [Error: PHONE_INVALID_COUNTRY_CODE] 16h.parsePhoneNumber("15101234567", "US"); 17// > { countryCode: '1', nationalNumber: '5101234567' }
getExampleNumberForType
phoneHandler.getExampleNumberForType(type, regionCode)
Return an example phoneObj
object, given the string parameters type
and regionCode
.
The type
parameter is an enum based on libphonenumber i18n.phonenumbers.PhoneNumberType and can be any of the following strings:
'FIXED_LINE'
'MOBILE'
'FIXED_LINE_OR_MOBILE'
'TOLL_FREE'
'PREMIUM_RATE'
'SHARED_COST'
'VOIP'
'PERSONAL_NUMBER'
'PAGER'
'UAN'
'VOICEMAIL'
'UNKNOWN'
Example
1phoneHandler.getExampleNumberForType('MOBILE', 'US'); 2// > { countryCode: '1', nationalNumber: '2015550123' }
inferPhoneNumberType
phoneHandler.inferPhoneNumberType(phoneObj)
Return a string indicating the phone number type (see getExampleNumberForType
), given a valid phoneobj
. Returns 'UNKNOWN'
if metadata has not been loaded for the region of the phone number or the number type otherwise cannot be inferred.
Examples
1phoneHandler.inferPhoneNumberType({ countryCode: '1', nationalNumber: '5105261568' }); 2// > 'FIXED_LINE_OR_MOBILE' 3 4// GB landline 5phoneHandler.inferPhoneNumberType({ countryCode: '44', nationalNumber: '1212345678' }); 6// > 'FIXED_LINE' 7 8// GB mobile number 9phoneHandler.inferPhoneNumberType({ countryCode: '44', nationalNumber: '7400123456' }) 10// > 'MOBILE' 11 12// invalid GB phone number 13phoneHandler.inferPhoneNumberType({ countryCode: '44', nationalNumber: '999999' }); 14// > 'UNKNOWN'
inferPhoneNumberRegion
phoneHandler.inferPhoneNumberRegion(phoneObj)
Return the two letter region code associated with a valid phoneObj
.
Returns null
if the region cannot be determined. (This can happen if metadata has not been loaded for the region associated with the phoneObj.countryCode
.)
Important: This method only guarantees correct results for valid phone numbers. (See the libphonenumber source code.)
1phoneHandler.inferPhoneNumberRegion({ countryCode: '44', nationalNumber: '1212345678' }); 2// > 'GB' 3 4phoneHandler.inferPhoneNumberRegion({ countryCode: '99', nationalNumber: '1212345678' }); 5// > null
getAsYouTypeFormatter
phoneHandler.getAsYouTypeFormatter(regionCode)
Return a new AsYouTypeFormatter object instantiated for the given regionCode
.
Example
1var formatter = phoneHandler.getAsYouTypeFormatter('GB'); 2// > AsYouTypeFormatter object initialized to Great Britain
AsYouTypeFormatter methods
The initialized AsYouTypeFormatter object itself exposes the following methods:
inputDigit
formatter.inputDigit(digit)
Given a digit (number or string), output the phone number formatted thus far (given the history of inputted digits).
Note that digit
can also be '+'
or '*'
Example
1formatter.inputDigit('5'); // > '5' 2formatter.inputDigit('1'); // > '51' 3formatter.inputDigit('0'); // > '510' 4formatter.inputDigit('1'); // > '510-1' 5formatter.inputDigit('2'); // > '510-12' 6formatter.inputDigit('3'); // > '510-123' 7formatter.inputDigit('4'); // > '510-1234' 8formatter.inputDigit('5'); // > '(510) 123-45' 9formatter.inputDigit('6'); // > '(510) 123-456' 10formatter.inputDigit('7'); // > '(510) 123-4567'
clear
formatter.clear()
Clear the formatter state.
Example
1formatter.inputDigit('5'); // > '5' 2formatter.inputDigit('1'); // > '51' 3formatter.inputDigit('0'); // > '510' 4formatter.inputDigit('1'); // > '510-1' 5formatter.inputDigit('2'); // > '510-12' 6formatter.clear(); 7formatter.inputDigit('9'); // > '9' 8formatter.inputDigit('1'); // > '91' 9formatter.inputDigit('9'); // > '919' 10formatter.inputDigit('4'); // > '919-4' 11formatter.inputDigit('8'); // > '919-48' 12...
inputDigitAndRememberPosition
formatter.inputDigitAndRememberPosition(digit)
Same as inputDigit, but remembers the (1-indexed) position where the digit was entered, to be retrieved later by getRememberedPosition. This position can update as formatting characters are inserted by the AsYouTypeFormatter.
getRememberedPosition
formatter.getRememberedPosition()
Returns the (1-indexed) position (as a number) of the digit previously passed to inputDigitAndRememberPosition.
Example
1// getRememberedPosition starts out as 0 2formatter.getRememberedPosition(); // > 0 3 4formatter.inputDigitAndRememberPosition(5); // > '5' 5 6// the 5 was inputted at position 1 7formatter.getRememberedPosition(); // > 1 8 9// input additional digits until parens are inserted 10formatter.inputDigit(1); // > '51' 11formatter.inputDigit(0); // > '510' 12formatter.inputDigit(1); // > '510-1' 13formatter.inputDigit(2); // > '510-12' 14formatter.inputDigit(3); // > '510-123' 15formatter.inputDigit(4); // > '510-1234' 16formatter.inputDigit(5); // > '(510) 123-45' 17 18// now the original 5 is at position 2, since an open paren was inserted before it 19formatter.getRememberedPosition(); // 2
Development
see DEVELOPMENT.md
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
14 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/node.js.yml:1
- Warn: no topLevel permission defined: .github/workflows/upgrade.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/paypal/fullstack-phone/node.js.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/paypal/fullstack-phone/node.js.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/upgrade.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/paypal/fullstack-phone/upgrade.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/upgrade.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/paypal/fullstack-phone/upgrade.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/upgrade.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/paypal/fullstack-phone/upgrade.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/upgrade.yml:35: update your workflow using https://app.stepsecurity.io/secureworkflow/paypal/fullstack-phone/upgrade.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: bin/upgrade.sh:82
- Warn: npmCommand not pinned by hash: .github/workflows/node.js.yml:29
- Warn: npmCommand not pinned by hash: .github/workflows/upgrade.yml:22
- Info: 0 out of 5 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 0 out of 3 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 1 are checked with a SAST tool
Score
4.4
/10
Last Scanned on 2024-12-16
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