mention-utils.js 1.0 KB

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