智慧水务管理系统 - 精河县供水工程综合管理平台

mention-utils.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { isDigitChar, isAsciiLetterChar } from '../char-utils';
  2. var mentionRegexes = {
  3. twitter: /^@\w{1,15}$/,
  4. instagram: /^@[_\w]{1,30}$/,
  5. soundcloud: /^@[-a-z0-9_]{3,25}$/,
  6. // TikTok usernames are 1-24 characters containing letters, numbers, underscores
  7. // and periods, but cannot end in a period: https://support.tiktok.com/en/getting-started/setting-up-your-profile/changing-your-username
  8. tiktok: /^@[.\w]{1,23}[\w]$/,
  9. // Youtube usernames are 3-30 characters containing letters, numbers, underscores,
  10. // dashes, or latin middle dots ('·').
  11. // https://support.google.com/youtube/answer/11585688?hl=en&co=GENIE.Platform%3DAndroid#tns
  12. youtube: /^@[-.·\w]{3,30}$/,
  13. };
  14. /**
  15. * Determines if the given character can be part of a mention's text characters.
  16. *
  17. * Accepts characters that match the RegExp `/[-\w.]/`, which are the possible
  18. * mention characters for any service.
  19. *
  20. * We'll confirm the match based on the user-configured service name after the
  21. * match is found.
  22. */
  23. export function isMentionTextChar(charCode) {
  24. return (charCode === 45 /* Char.Dash */ || // '-'
  25. charCode === 46 /* Char.Dot */ || // '.'
  26. charCode === 95 /* Char.Underscore */ || // '_'
  27. isAsciiLetterChar(charCode) ||
  28. isDigitChar(charCode));
  29. }
  30. /**
  31. * Determines if the given `mention` text is valid.
  32. */
  33. export function isValidMention(mention, serviceName) {
  34. var re = mentionRegexes[serviceName];
  35. return re.test(mention);
  36. }
  37. export var mentionServices = [
  38. 'twitter',
  39. 'instagram',
  40. 'soundcloud',
  41. 'tiktok',
  42. 'youtube',
  43. ];
  44. //# sourceMappingURL=mention-utils.js.map