validatePhoneNumberLength.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 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; }
  2. 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; }
  3. 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; }
  4. import normalizeArguments from './normalizeArguments.js';
  5. import parsePhoneNumberWithError from './parsePhoneNumberWithError_.js';
  6. import ParseError from './ParseError.js';
  7. import Metadata from './metadata.js';
  8. import checkNumberLength from './helpers/checkNumberLength.js';
  9. export default function validatePhoneNumberLength() {
  10. var _normalizeArguments = normalizeArguments(arguments),
  11. text = _normalizeArguments.text,
  12. options = _normalizeArguments.options,
  13. metadata = _normalizeArguments.metadata;
  14. options = _objectSpread(_objectSpread({}, options), {}, {
  15. extract: false
  16. }); // Parse phone number.
  17. try {
  18. var phoneNumber = parsePhoneNumberWithError(text, options, metadata);
  19. metadata = new Metadata(metadata);
  20. metadata.selectNumberingPlan(phoneNumber.countryCallingCode);
  21. var result = checkNumberLength(phoneNumber.nationalNumber, metadata);
  22. if (result !== 'IS_POSSIBLE') {
  23. return result;
  24. }
  25. } catch (error) {
  26. /* istanbul ignore else */
  27. if (error instanceof ParseError) {
  28. return error.message;
  29. } else {
  30. throw error;
  31. }
  32. }
  33. }
  34. //# sourceMappingURL=validatePhoneNumberLength.js.map