source: node_modules/autolinker/dist/commonjs/match/mention-match.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 3.8 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.MentionMatch = void 0;
4var tslib_1 = require("tslib");
5var match_1 = require("./match");
6/**
7 * @class Autolinker.match.Mention
8 * @extends Autolinker.match.Match
9 *
10 * Represents a Mention match found in an input string which should be Autolinked.
11 *
12 * See this class's superclass ({@link Autolinker.match.Match}) for more details.
13 */
14var MentionMatch = /** @class */ (function (_super) {
15 (0, tslib_1.__extends)(MentionMatch, _super);
16 /**
17 * @method constructor
18 * @param {Object} cfg The configuration properties for the Match
19 * instance, specified in an Object (map).
20 */
21 function MentionMatch(cfg) {
22 var _this = _super.call(this, cfg) || this;
23 /**
24 * @cfg {String} serviceName
25 *
26 * The service to point mention matches to. See {@link Autolinker#mention}
27 * for available values.
28 */
29 _this.serviceName = 'twitter'; // default value just to get the above doc comment in the ES5 output and documentation generator
30 /**
31 * @cfg {String} mention (required)
32 *
33 * The Mention that was matched, without the '@' character.
34 */
35 _this.mention = ''; // default value just to get the above doc comment in the ES5 output and documentation generator
36 _this.mention = cfg.mention;
37 _this.serviceName = cfg.serviceName;
38 return _this;
39 }
40 /**
41 * Returns a string name for the type of match that this class represents.
42 * For the case of MentionMatch, returns 'mention'.
43 *
44 * @return {String}
45 */
46 MentionMatch.prototype.getType = function () {
47 return 'mention';
48 };
49 /**
50 * Returns the mention, without the '@' character.
51 *
52 * @return {String}
53 */
54 MentionMatch.prototype.getMention = function () {
55 return this.mention;
56 };
57 /**
58 * Returns the configured {@link #serviceName} to point the mention to.
59 * Ex: 'instagram', 'twitter', 'soundcloud'.
60 *
61 * @return {String}
62 */
63 MentionMatch.prototype.getServiceName = function () {
64 return this.serviceName;
65 };
66 /**
67 * Returns the anchor href that should be generated for the match.
68 *
69 * @return {String}
70 */
71 MentionMatch.prototype.getAnchorHref = function () {
72 switch (this.serviceName) {
73 case 'twitter':
74 return 'https://twitter.com/' + this.mention;
75 case 'instagram':
76 return 'https://instagram.com/' + this.mention;
77 case 'soundcloud':
78 return 'https://soundcloud.com/' + this.mention;
79 case 'tiktok':
80 return 'https://www.tiktok.com/@' + this.mention;
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 mention to: ' + this.serviceName);
84 }
85 };
86 /**
87 * Returns the anchor text that should be generated for the match.
88 *
89 * @return {String}
90 */
91 MentionMatch.prototype.getAnchorText = function () {
92 return '@' + this.mention;
93 };
94 /**
95 * Returns the CSS class suffixes that should be used on a tag built with
96 * the match. See {@link Autolinker.match.Match#getCssClassSuffixes} for
97 * details.
98 *
99 * @return {String[]}
100 */
101 MentionMatch.prototype.getCssClassSuffixes = function () {
102 var cssClassSuffixes = _super.prototype.getCssClassSuffixes.call(this), serviceName = this.getServiceName();
103 if (serviceName) {
104 cssClassSuffixes.push(serviceName);
105 }
106 return cssClassSuffixes;
107 };
108 return MentionMatch;
109}(match_1.Match));
110exports.MentionMatch = MentionMatch;
111//# sourceMappingURL=mention-match.js.map
Note: See TracBrowser for help on using the repository browser.