applyInternationalSeparatorStyle.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = applyInternationalSeparatorStyle;
  6. var _constants = require("../constants.js");
  7. // Removes brackets and replaces dashes with spaces.
  8. //
  9. // E.g. "(999) 111-22-33" -> "999 111 22 33"
  10. //
  11. // For some reason Google's metadata contains `<intlFormat/>`s with brackets and dashes.
  12. // Meanwhile, there's no single opinion about using punctuation in international phone numbers.
  13. //
  14. // For example, Google's `<intlFormat/>` for USA is `+1 213-373-4253`.
  15. // And here's a quote from WikiPedia's "North American Numbering Plan" page:
  16. // https://en.wikipedia.org/wiki/North_American_Numbering_Plan
  17. //
  18. // "The country calling code for all countries participating in the NANP is 1.
  19. // In international format, an NANP number should be listed as +1 301 555 01 00,
  20. // where 301 is an area code (Maryland)."
  21. //
  22. // I personally prefer the international format without any punctuation.
  23. // For example, brackets are remnants of the old age, meaning that the
  24. // phone number part in brackets (so called "area code") can be omitted
  25. // if dialing within the same "area".
  26. // And hyphens were clearly introduced for splitting local numbers into memorizable groups.
  27. // For example, remembering "5553535" is difficult but "555-35-35" is much simpler.
  28. // Imagine a man taking a bus from home to work and seeing an ad with a phone number.
  29. // He has a couple of seconds to memorize that number until it passes by.
  30. // If it were spaces instead of hyphens the man wouldn't necessarily get it,
  31. // but with hyphens instead of spaces the grouping is more explicit.
  32. // I personally think that hyphens introduce visual clutter,
  33. // so I prefer replacing them with spaces in international numbers.
  34. // In the modern age all output is done on displays where spaces are clearly distinguishable
  35. // so hyphens can be safely replaced with spaces without losing any legibility.
  36. //
  37. function applyInternationalSeparatorStyle(formattedNumber) {
  38. return formattedNumber.replace(new RegExp("[".concat(_constants.VALID_PUNCTUATION, "]+"), 'g'), ' ').trim();
  39. }
  40. //# sourceMappingURL=applyInternationalSeparatorStyle.js.map