mention-utils.js 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.mentionServices = exports.isValidMention = exports.isMentionTextChar = void 0;
  4. var 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.
  15. var mentionTextCharRe = /[-\w.]/;
  16. /**
  17. * Determines if the given character can be part of a mention's text characters.
  18. */
  19. function isMentionTextChar(char) {
  20. return mentionTextCharRe.test(char);
  21. }
  22. exports.isMentionTextChar = isMentionTextChar;
  23. /**
  24. * Determines if the given `mention` text is valid.
  25. */
  26. function isValidMention(mention, serviceName) {
  27. var re = mentionRegexes[serviceName];
  28. return re.test(mention);
  29. }
  30. exports.isValidMention = isValidMention;
  31. exports.mentionServices = ['twitter', 'instagram', 'soundcloud', 'tiktok'];
  32. //# sourceMappingURL=mention-utils.js.map