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