generateClassName.tsx 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import {defined} from 'sentry/utils';
  2. function generateClassname(name?: string, version?: string): string {
  3. if (!defined(name)) {
  4. return '';
  5. }
  6. const lowerCaseName = name.toLowerCase();
  7. // amazon fire tv device id changes with version: AFTT, AFTN, AFTS, AFTA, AFTVA (alexa), ...
  8. if (lowerCaseName.startsWith('aft')) {
  9. return 'amazon';
  10. }
  11. if (lowerCaseName.startsWith('sm-') || lowerCaseName.startsWith('st-')) {
  12. return 'samsung';
  13. }
  14. if (lowerCaseName.startsWith('moto')) {
  15. return 'motorola';
  16. }
  17. if (lowerCaseName.startsWith('pixel')) {
  18. return 'google';
  19. }
  20. const formattedName = name
  21. .split(/\d/)[0]
  22. .toLowerCase()
  23. .replace(/[^a-z0-9\-]+/g, '-')
  24. .replace(/\-+$/, '')
  25. .replace(/^\-+/, '');
  26. if (formattedName === 'edge' && version) {
  27. const majorVersion = version.split('.')[0];
  28. const isLegacyEdge = majorVersion >= '12' && majorVersion <= '18';
  29. if (isLegacyEdge) {
  30. return 'legacy-edge';
  31. }
  32. }
  33. return formattedName;
  34. }
  35. export default generateClassname;