validatePhoneNumberLength.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = validatePhoneNumberLength;
  6. var _normalizeArguments2 = _interopRequireDefault(require("./normalizeArguments.js"));
  7. var _parsePhoneNumberWithError_ = _interopRequireDefault(require("./parsePhoneNumberWithError_.js"));
  8. var _ParseError = _interopRequireDefault(require("./ParseError.js"));
  9. var _metadata = _interopRequireDefault(require("./metadata.js"));
  10. var _checkNumberLength = _interopRequireDefault(require("./helpers/checkNumberLength.js"));
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  12. 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; }
  13. 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; }
  14. 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; }
  15. function validatePhoneNumberLength() {
  16. var _normalizeArguments = (0, _normalizeArguments2["default"])(arguments),
  17. text = _normalizeArguments.text,
  18. options = _normalizeArguments.options,
  19. metadata = _normalizeArguments.metadata;
  20. options = _objectSpread(_objectSpread({}, options), {}, {
  21. extract: false
  22. }); // Parse phone number.
  23. try {
  24. var phoneNumber = (0, _parsePhoneNumberWithError_["default"])(text, options, metadata);
  25. metadata = new _metadata["default"](metadata);
  26. metadata.selectNumberingPlan(phoneNumber.countryCallingCode);
  27. var result = (0, _checkNumberLength["default"])(phoneNumber.nationalNumber, metadata);
  28. if (result !== 'IS_POSSIBLE') {
  29. return result;
  30. }
  31. } catch (error) {
  32. /* istanbul ignore else */
  33. if (error instanceof _ParseError["default"]) {
  34. return error.message;
  35. } else {
  36. throw error;
  37. }
  38. }
  39. }
  40. //# sourceMappingURL=validatePhoneNumberLength.js.map