123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports["default"] = isPossiblePhoneNumber;
- exports.isPossibleNumber = isPossibleNumber;
- var _metadata = _interopRequireDefault(require("./metadata.js"));
- var _checkNumberLength = _interopRequireDefault(require("./helpers/checkNumberLength.js"));
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
- function isPossiblePhoneNumber(input, options, metadata) {
-
- if (options === undefined) {
- options = {};
- }
- metadata = new _metadata["default"](metadata);
- if (options.v2) {
- if (!input.countryCallingCode) {
- throw new Error('Invalid phone number object passed');
- }
- metadata.selectNumberingPlan(input.countryCallingCode);
- } else {
- if (!input.phone) {
- return false;
- }
- if (input.country) {
- if (!metadata.hasCountry(input.country)) {
- throw new Error("Unknown country: ".concat(input.country));
- }
- metadata.country(input.country);
- } else {
- if (!input.countryCallingCode) {
- throw new Error('Invalid phone number object passed');
- }
- metadata.selectNumberingPlan(input.countryCallingCode);
- }
- }
- if (metadata.possibleLengths()) {
- return isPossibleNumber(input.phone || input.nationalNumber, metadata);
- } else {
-
-
-
-
-
-
- if (input.countryCallingCode && metadata.isNonGeographicCallingCode(input.countryCallingCode)) {
-
-
- return true;
- } else {
- throw new Error('Missing "possibleLengths" in metadata. Perhaps the metadata has been generated before v1.0.18.');
- }
- }
- }
- function isPossibleNumber(nationalNumber, metadata) {
-
- switch ((0, _checkNumberLength["default"])(nationalNumber, metadata)) {
- case 'IS_POSSIBLE':
- return true;
-
-
-
-
- default:
- return false;
- }
- }
|