UNPKG

1.31 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.mentionServices = exports.isValidMention = exports.isMentionTextChar = void 0;
4var mentionRegexes = {
5 twitter: /^@\w{1,15}$/,
6 instagram: /^@[_\w]{1,30}$/,
7 soundcloud: /^@[-a-z0-9_]{3,25}$/,
8 // TikTok usernames are 1-24 characters containing letters, numbers, underscores
9 // and periods, but cannot end in a period: https://support.tiktok.com/en/getting-started/setting-up-your-profile/changing-your-username
10 tiktok: /^@[.\w]{1,23}[\w]$/,
11};
12// Regex that allows for all possible mention characters for any service. We'll
13// confirm the match based on the user-configured service name after a match is
14// found.
15var mentionTextCharRe = /[-\w.]/;
16/**
17 * Determines if the given character can be part of a mention's text characters.
18 */
19function isMentionTextChar(char) {
20 return mentionTextCharRe.test(char);
21}
22exports.isMentionTextChar = isMentionTextChar;
23/**
24 * Determines if the given `mention` text is valid.
25 */
26function isValidMention(mention, serviceName) {
27 var re = mentionRegexes[serviceName];
28 return re.test(mention);
29}
30exports.isValidMention = isValidMention;
31exports.mentionServices = ['twitter', 'instagram', 'soundcloud', 'tiktok'];
32//# sourceMappingURL=mention-utils.js.map
\No newline at end of file