platform.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {
  2. backend,
  3. desktop,
  4. frontend,
  5. mobile,
  6. PlatformCategory,
  7. PlatformKey,
  8. serverless,
  9. } from 'sentry/data/platformCategories';
  10. /**
  11. *
  12. * @param platform - a SDK platform, for example `node-express`, `javascript-react`
  13. * @returns - the platform category, for example `backend`, `serverless`
  14. */
  15. export function platformToCategory(platform: PlatformKey | undefined): PlatformCategory {
  16. if (!platform) {
  17. return PlatformCategory.OTHER;
  18. }
  19. if (([...frontend] as string[]).includes(platform)) {
  20. return PlatformCategory.FRONTEND;
  21. }
  22. if (([...backend] as string[]).includes(platform)) {
  23. return PlatformCategory.BACKEND;
  24. }
  25. if (([...serverless] as string[]).includes(platform)) {
  26. return PlatformCategory.SERVERLESS;
  27. }
  28. if (([...mobile] as string[]).includes(platform)) {
  29. return PlatformCategory.MOBILE;
  30. }
  31. if (([...desktop] as string[]).includes(platform)) {
  32. return PlatformCategory.DESKTOP;
  33. }
  34. return PlatformCategory.OTHER;
  35. }
  36. export function isNativePlatform(platform: string | undefined) {
  37. switch (platform) {
  38. case 'cocoa':
  39. case 'objc':
  40. case 'native':
  41. case 'swift':
  42. case 'c':
  43. return true;
  44. default:
  45. return false;
  46. }
  47. }
  48. export function isMobilePlatform(platform: string | undefined) {
  49. if (!platform) {
  50. return false;
  51. }
  52. return ([...mobile] as string[]).includes(platform);
  53. }