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.
		
		
		
		
		
			
		
			
				
					153 lines
				
				5.8 KiB
			
		
		
			
		
	
	
					153 lines
				
				5.8 KiB
			| 
											3 years ago
										 | "use strict"; | ||
|  | 
 | ||
|  | Object.defineProperty(exports, "__esModule", { | ||
|  |   value: true | ||
|  | }); | ||
|  | exports["default"] = void 0; | ||
|  | 
 | ||
|  | var _metadata2 = _interopRequireDefault(require("./metadata.js")); | ||
|  | 
 | ||
|  | var _isPossibleNumber_ = _interopRequireDefault(require("./isPossibleNumber_.js")); | ||
|  | 
 | ||
|  | var _validate_ = _interopRequireDefault(require("./validate_.js")); | ||
|  | 
 | ||
|  | var _isValidNumberForRegion_ = _interopRequireDefault(require("./isValidNumberForRegion_.js")); | ||
|  | 
 | ||
|  | var _getNumberType = _interopRequireDefault(require("./helpers/getNumberType.js")); | ||
|  | 
 | ||
|  | var _format_ = _interopRequireDefault(require("./format_.js")); | ||
|  | 
 | ||
|  | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
|  | 
 | ||
|  | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
|  | 
 | ||
|  | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
|  | 
 | ||
|  | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
|  | 
 | ||
|  | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
|  | 
 | ||
|  | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
|  | 
 | ||
|  | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
|  | 
 | ||
|  | var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false; | ||
|  | 
 | ||
|  | var PhoneNumber = /*#__PURE__*/function () { | ||
|  |   function PhoneNumber(countryCallingCode, nationalNumber, metadata) { | ||
|  |     _classCallCheck(this, PhoneNumber); | ||
|  | 
 | ||
|  |     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'); | ||
|  |     } | ||
|  | 
 | ||
|  |     var _metadata = new _metadata2["default"](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; | ||
|  |   } | ||
|  | 
 | ||
|  |   _createClass(PhoneNumber, [{ | ||
|  |     key: "setExt", | ||
|  |     value: function setExt(ext) { | ||
|  |       this.ext = ext; | ||
|  |     } | ||
|  |   }, { | ||
|  |     key: "isPossible", | ||
|  |     value: function isPossible() { | ||
|  |       return (0, _isPossibleNumber_["default"])(this, { | ||
|  |         v2: true | ||
|  |       }, this.metadata); | ||
|  |     } | ||
|  |   }, { | ||
|  |     key: "isValid", | ||
|  |     value: function isValid() { | ||
|  |       return (0, _validate_["default"])(this, { | ||
|  |         v2: true | ||
|  |       }, this.metadata); | ||
|  |     } | ||
|  |   }, { | ||
|  |     key: "isNonGeographic", | ||
|  |     value: function isNonGeographic() { | ||
|  |       var metadata = new _metadata2["default"](this.metadata); | ||
|  |       return metadata.isNonGeographicCallingCode(this.countryCallingCode); | ||
|  |     } | ||
|  |   }, { | ||
|  |     key: "isEqual", | ||
|  |     value: function 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)
 | ||
|  |     // }
 | ||
|  | 
 | ||
|  |   }, { | ||
|  |     key: "getType", | ||
|  |     value: function getType() { | ||
|  |       return (0, _getNumberType["default"])(this, { | ||
|  |         v2: true | ||
|  |       }, this.metadata); | ||
|  |     } | ||
|  |   }, { | ||
|  |     key: "format", | ||
|  |     value: function format(_format, options) { | ||
|  |       return (0, _format_["default"])(this, _format, options ? _objectSpread(_objectSpread({}, options), {}, { | ||
|  |         v2: true | ||
|  |       }) : { | ||
|  |         v2: true | ||
|  |       }, this.metadata); | ||
|  |     } | ||
|  |   }, { | ||
|  |     key: "formatNational", | ||
|  |     value: function formatNational(options) { | ||
|  |       return this.format('NATIONAL', options); | ||
|  |     } | ||
|  |   }, { | ||
|  |     key: "formatInternational", | ||
|  |     value: function formatInternational(options) { | ||
|  |       return this.format('INTERNATIONAL', options); | ||
|  |     } | ||
|  |   }, { | ||
|  |     key: "getURI", | ||
|  |     value: function getURI(options) { | ||
|  |       return this.format('RFC3966', options); | ||
|  |     } | ||
|  |   }]); | ||
|  | 
 | ||
|  |   return PhoneNumber; | ||
|  | }(); | ||
|  | 
 | ||
|  | exports["default"] = PhoneNumber; | ||
|  | 
 | ||
|  | var isCountryCode = function isCountryCode(value) { | ||
|  |   return /^[A-Z]{2}$/.test(value); | ||
|  | }; | ||
|  | //# sourceMappingURL=PhoneNumber.js.map
 |