fileExtension.tsx 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const FILE_EXTENSION_TO_PLATFORM = {
  2. jsx: 'react',
  3. tsx: 'react',
  4. js: 'javascript',
  5. ts: 'javascript',
  6. php: 'php',
  7. py: 'python',
  8. vue: 'vue',
  9. go: 'go',
  10. java: 'java',
  11. perl: 'perl',
  12. rb: 'ruby',
  13. rs: 'rust',
  14. rlib: 'rust',
  15. swift: 'swift',
  16. h: 'apple',
  17. m: 'apple',
  18. mm: 'apple',
  19. M: 'apple',
  20. ex: 'elixir',
  21. exs: 'elixir',
  22. cs: 'csharp',
  23. fs: 'fsharp',
  24. kt: 'kotlin',
  25. dart: 'dart',
  26. sc: 'scala',
  27. scala: 'scala',
  28. clj: 'clojure',
  29. };
  30. /**
  31. * Takes in path (/Users/test/sentry/something.jsx) and returns file extension (jsx)
  32. */
  33. export function getFileExtension(fileName: string): string | undefined {
  34. // this won't work for something like .spec.jsx
  35. const segments = fileName.split('.');
  36. if (segments.length > 1) {
  37. return segments.pop();
  38. }
  39. return undefined;
  40. }
  41. /**
  42. * Takes in file extension and returns a platform string that can be passed into platformicons
  43. */
  44. export function fileExtensionToPlatform(fileExtension: string): string | undefined {
  45. return FILE_EXTENSION_TO_PLATFORM[fileExtension];
  46. }