PATH:
opt
/
bitninja-dispatcher
/
node_modules
/
libphonenumber-js
/
source
import Metadata from './metadata.js' import isPossibleNumber from './isPossibleNumber_.js' import isValidNumber from './validate_.js' import isValidNumberForRegion from './isValidNumberForRegion_.js' import getNumberType from './helpers/getNumberType.js' import formatNumber from './format_.js' const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false export default class PhoneNumber { constructor(countryCallingCode, nationalNumber, metadata) { if (!countryCallingCode) { throw new TypeError('`country` or `countryCallingCode` not passed') } if (!nationalNumber) { throw new TypeError('`nationalNumber` not passed') } if (!metadata) { throw new TypeError('`metadata` not passed') } const _metadata = new Metadata(metadata) // If country code is passed then derive `countryCallingCode` from it. // Also store the country code as `.country`. if (isCountryCode(countryCallingCode)) { this.country = countryCallingCode _metadata.country(countryCallingCode) countryCallingCode = _metadata.countryCallingCode() } else { /* istanbul ignore if */ if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) { if (_metadata.isNonGeographicCallingCode(countryCallingCode)) { this.country = '001' } } } this.countryCallingCode = countryCallingCode this.nationalNumber = nationalNumber this.number = '+' + this.countryCallingCode + this.nationalNumber this.metadata = metadata } setExt(ext) { this.ext = ext } isPossible() { return isPossibleNumber(this, { v2: true }, this.metadata) } isValid() { return isValidNumber(this, { v2: true }, this.metadata) } isNonGeographic() { const metadata = new Metadata(this.metadata) return metadata.isNonGeographicCallingCode(this.countryCallingCode) } isEqual(phoneNumber) { return this.number === phoneNumber.number && this.ext === phoneNumber.ext } // // Is just an alias for `this.isValid() && this.country === country`. // // https://github.com/googlei18n/libphonenumber/blob/master/FAQ.md#when-should-i-use-isvalidnumberforregion // isValidForRegion(country) { // return isValidNumberForRegion(this, country, { v2: true }, this.metadata) // } getType() { return getNumberType(this, { v2: true }, this.metadata) } format(format, options) { return formatNumber( this, format, options ? { ...options, v2: true } : { v2: true }, this.metadata ) } formatNational(options) { return this.format('NATIONAL', options) } formatInternational(options) { return this.format('INTERNATIONAL', options) } getURI(options) { return this.format('RFC3966', options) } } const isCountryCode = (value) => /^[A-Z]{2}$/.test(value)
[-] parsePhoneNumberFromString.test.js
[edit]
[-] metadata.js
[edit]
[-] PhoneNumber.js
[edit]
[-] AsYouTypeFormatter.PatternMatcher.d.ts
[edit]
[-] parsePhoneNumber.js
[edit]
[-] isPossiblePhoneNumber.test.js
[edit]
[-] findNumbers.js
[edit]
[-] isPossibleNumber.js
[edit]
[-] getNumberType.js
[edit]
[-] AsYouTypeFormatter.PatternMatcher.js
[edit]
[-] parse_.js
[edit]
[-] getExampleNumber.test.js
[edit]
[-] AsYouTypeParser.js
[edit]
[+]
..
[-] validate_.js
[edit]
[-] parsePhoneNumberFromString_.js
[edit]
[-] AsYouTypeFormatter.PatternParser.d.ts
[edit]
[-] searchPhoneNumbersInText.test.js
[edit]
[-] getCountries.test.js
[edit]
[-] searchPhoneNumbersInText.js
[edit]
[-] AsYouTypeFormatter.PatternParser.test.js
[edit]
[-] formatNumberForMobileDialing.js
[edit]
[-] getCountryCallingCode.js
[edit]
[-] findPhoneNumbers.test.js
[edit]
[-] parsePhoneNumber.test.js
[edit]
[-] isValidPhoneNumber.test.js
[edit]
[-] AsYouType.test.js
[edit]
[-] getCountries.js
[edit]
[-] validate.test.js
[edit]
[-] AsYouTypeFormatter.js
[edit]
[-] PhoneNumberMatcher.js
[edit]
[-] findNumbers_.js
[edit]
[-] formatIncompletePhoneNumber.test.js
[edit]
[-] format.test.js
[edit]
[-] findPhoneNumbers.js
[edit]
[-] searchNumbers.js
[edit]
[-] findPhoneNumbersInText.js
[edit]
[-] findPhoneNumbersInText.test.js
[edit]
[-] metadata.test.js
[edit]
[-] parse.js
[edit]
[-] validatePhoneNumberLength.test.js
[edit]
[-] findNumbers.test.js
[edit]
[+]
tools
[-] parsePhoneNumberFromString.js
[edit]
[-] getCountryCallingCode.test.js
[edit]
[-] isPossibleNumber.test.js
[edit]
[-] parse.test.js
[edit]
[-] parsePhoneNumber_.js
[edit]
[-] ParseError.js
[edit]
[-] PhoneNumber.test.js
[edit]
[-] AsYouTypeFormatter.PatternMatcher.test.js
[edit]
[-] getNumberType.test.js
[edit]
[-] AsYouTypeFormatter.PatternParser.js
[edit]
[-] validatePhoneNumberLength.js
[edit]
[-] isValidPhoneNumber.js
[edit]
[+]
helpers
[-] parseIncompletePhoneNumber.test.js
[edit]
[-] formatNumberForMobileDialing.test.js
[edit]
[-] isValidNumberForRegion_.js
[edit]
[-] PhoneNumberMatcher.test.js
[edit]
[-] isPossibleNumber_.js
[edit]
[-] AsYouTypeFormatter.util.js
[edit]
[-] format.js
[edit]
[-] isValidNumberForRegion.test.js
[edit]
[-] AsYouType.js
[edit]
[-] AsYouTypeFormatter.complete.js
[edit]
[+]
findNumbers
[-] getExampleNumber.js
[edit]
[-] format_.js
[edit]
[-] isPossiblePhoneNumber.js
[edit]
[-] findPhoneNumbers_.js
[edit]
[-] isValidNumberForRegion.js
[edit]
[-] validate.js
[edit]
[-] AsYouTypeState.js
[edit]
[-] formatIncompletePhoneNumber.js
[edit]
[-] constants.js
[edit]
[-] parseIncompletePhoneNumber.js
[edit]
[-] searchNumbers.test.js
[edit]
[-] AsYouTypeFormatter.util.test.js
[edit]