UNPKG

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