Debian Codegraph @

node/autolinker/dist/es2015/match/hashtag-match.js

raw
1 import { __extends } from "tslib";
2 import { Match } from './match';
3 /**
4 * @class Autolinker.match.Hashtag
5 * @extends Autolinker.match.Match
6 *
7 * Represents a Hashtag 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 HashtagMatch = /** @class */ (function (_super) {
14 __extends(HashtagMatch, _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 HashtagMatch(cfg) {
21 var _this = _super.call(this, cfg) || this;
22 /**
23 * @cfg {String} serviceName
24 *
25 * The service to point hashtag matches to. See {@link Autolinker#hashtag}
26 * for available values.
27 */
28 _this.serviceName = ''; // default value just to get the above doc comment in the ES5 output and documentation generator
29 /**
30 * @cfg {String} hashtag (required)
31 *
32 * The HashtagMatch that was matched, without the '#'.
33 */
34 _this.hashtag = ''; // default value just to get the above doc comment in the ES5 output and documentation generator
35 _this.serviceName = cfg.serviceName;
36 _this.hashtag = cfg.hashtag;
37 return _this;
38 }
39 /**
40 * Returns a string name for the type of match that this class represents.
41 * For the case of HashtagMatch, returns 'hashtag'.
42 *
43 * @return {String}
44 */
45 HashtagMatch.prototype.getType = function () {
46 return 'hashtag';
47 };
48 /**
49 * Returns the configured {@link #serviceName} to point the HashtagMatch to.
50 * Ex: 'facebook', 'twitter'.
51 *
52 * @return {String}
53 */
54 HashtagMatch.prototype.getServiceName = function () {
55 return this.serviceName;
56 };
57 /**
58 * Returns the matched hashtag, without the '#' character.
59 *
60 * @return {String}
61 */
62 HashtagMatch.prototype.getHashtag = function () {
63 return this.hashtag;
64 };
65 /**
66 * Returns the anchor href that should be generated for the match.
67 *
68 * @return {String}
69 */
70 HashtagMatch.prototype.getAnchorHref = function () {
71 var serviceName = this.serviceName, hashtag = this.hashtag;
72 switch (serviceName) {
73 case 'twitter':
74 return 'https://twitter.com/hashtag/' + hashtag;
75 case 'facebook':
76 return 'https://www.facebook.com/hashtag/' + hashtag;
77 case 'instagram':
78 return 'https://instagram.com/explore/tags/' + hashtag;
79 case 'tiktok':
80 return 'https://www.tiktok.com/tag/' + hashtag;
81 default:
82 // Shouldn't happen because Autolinker's constructor should block any invalid values, but just in case.
83 throw new Error('Unknown service name to point hashtag to: ' + serviceName);
84 }
85 };
86 /**
87 * Returns the anchor text that should be generated for the match.
88 *
89 * @return {String}
90 */
91 HashtagMatch.prototype.getAnchorText = function () {
92 return '#' + this.hashtag;
93 };
94 return HashtagMatch;
95 }(Match));
96 export { HashtagMatch };
97 //# sourceMappingURL=hashtag-match.js.map