phone-match.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { __extends } from "tslib";
  2. import { AbstractMatch } from './abstract-match';
  3. /**
  4. * @class Autolinker.match.Phone
  5. * @extends Autolinker.match.AbstractMatch
  6. *
  7. * Represents a Phone number match found in an input string which should be
  8. * Autolinked.
  9. *
  10. * See this class's superclass ({@link Autolinker.match.Match}) for more
  11. * details.
  12. */
  13. var PhoneMatch = /** @class */ (function (_super) {
  14. __extends(PhoneMatch, _super);
  15. /**
  16. * @method constructor
  17. * @param {Object} cfg The configuration properties for the Match
  18. * instance, specified in an Object (map).
  19. */
  20. function PhoneMatch(cfg) {
  21. var _this = _super.call(this, cfg) || this;
  22. /**
  23. * @public
  24. * @property {'phone'} type
  25. *
  26. * A string name for the type of match that this class represents. Can be
  27. * used in a TypeScript discriminating union to type-narrow from the
  28. * `Match` type.
  29. */
  30. _this.type = 'phone';
  31. /**
  32. * @protected
  33. * @property {String} number (required)
  34. *
  35. * The phone number that was matched, without any delimiter characters.
  36. *
  37. * Note: This is a string to allow for prefixed 0's.
  38. */
  39. _this.number = ''; // default value just to get the above doc comment in the ES5 output and documentation generator
  40. /**
  41. * @protected
  42. * @property {Boolean} plusSign (required)
  43. *
  44. * `true` if the matched phone number started with a '+' sign. We'll include
  45. * it in the `tel:` URL if so, as this is needed for international numbers.
  46. *
  47. * Ex: '+1 (123) 456 7879'
  48. */
  49. _this.plusSign = false; // default value just to get the above doc comment in the ES5 output and documentation generator
  50. _this.number = cfg.number;
  51. _this.plusSign = cfg.plusSign;
  52. return _this;
  53. }
  54. /**
  55. * Returns a string name for the type of match that this class represents.
  56. * For the case of PhoneMatch, returns 'phone'.
  57. *
  58. * @return {String}
  59. */
  60. PhoneMatch.prototype.getType = function () {
  61. return 'phone';
  62. };
  63. /**
  64. * Returns the phone number that was matched as a string, without any
  65. * delimiter characters.
  66. *
  67. * Note: This is a string to allow for prefixed 0's.
  68. *
  69. * @return {String}
  70. */
  71. PhoneMatch.prototype.getPhoneNumber = function () {
  72. return this.number;
  73. };
  74. /**
  75. * Alias of {@link #getPhoneNumber}, returns the phone number that was
  76. * matched as a string, without any delimiter characters.
  77. *
  78. * Note: This is a string to allow for prefixed 0's.
  79. *
  80. * @return {String}
  81. */
  82. PhoneMatch.prototype.getNumber = function () {
  83. return this.getPhoneNumber();
  84. };
  85. /**
  86. * Returns the anchor href that should be generated for the match.
  87. *
  88. * @return {String}
  89. */
  90. PhoneMatch.prototype.getAnchorHref = function () {
  91. return 'tel:' + (this.plusSign ? '+' : '') + this.number;
  92. };
  93. /**
  94. * Returns the anchor text that should be generated for the match.
  95. *
  96. * @return {String}
  97. */
  98. PhoneMatch.prototype.getAnchorText = function () {
  99. return this.matchedText;
  100. };
  101. return PhoneMatch;
  102. }(AbstractMatch));
  103. export { PhoneMatch };
  104. //# sourceMappingURL=phone-match.js.map