You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							83 lines
						
					
					
						
							2.6 KiB
						
					
					
				
			
		
		
	
	
							83 lines
						
					
					
						
							2.6 KiB
						
					
					
				"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) {
 | 
						|
  /* istanbul ignore if */
 | 
						|
  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);
 | 
						|
    }
 | 
						|
  } // Old metadata (< 1.0.18) had no "possible length" data.
 | 
						|
 | 
						|
 | 
						|
  if (metadata.possibleLengths()) {
 | 
						|
    return isPossibleNumber(input.phone || input.nationalNumber, metadata);
 | 
						|
  } else {
 | 
						|
    // There was a bug between `1.7.35` and `1.7.37` where "possible_lengths"
 | 
						|
    // were missing for "non-geographical" numbering plans.
 | 
						|
    // Just assume the number is possible in such cases:
 | 
						|
    // it's unlikely that anyone generated their custom metadata
 | 
						|
    // in that short period of time (one day).
 | 
						|
    // This code can be removed in some future major version update.
 | 
						|
    if (input.countryCallingCode && metadata.isNonGeographicCallingCode(input.countryCallingCode)) {
 | 
						|
      // "Non-geographic entities" did't have `possibleLengths`
 | 
						|
      // due to a bug in metadata generation process.
 | 
						|
      return true;
 | 
						|
    } else {
 | 
						|
      throw new Error('Missing "possibleLengths" in metadata. Perhaps the metadata has been generated before v1.0.18.');
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
function isPossibleNumber(nationalNumber, metadata) {
 | 
						|
  //, isInternational) {
 | 
						|
  switch ((0, _checkNumberLength["default"])(nationalNumber, metadata)) {
 | 
						|
    case 'IS_POSSIBLE':
 | 
						|
      return true;
 | 
						|
    // This library ignores "local-only" phone numbers (for simplicity).
 | 
						|
    // See the readme for more info on what are "local-only" phone numbers.
 | 
						|
    // case 'IS_POSSIBLE_LOCAL_ONLY':
 | 
						|
    // 	return !isInternational
 | 
						|
 | 
						|
    default:
 | 
						|
      return false;
 | 
						|
  }
 | 
						|
}
 | 
						|
//# sourceMappingURL=isPossibleNumber_.js.map
 |