fileExtension.tsx 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. vb: 'visualbasic',
  25. kt: 'kotlin',
  26. dart: 'dart',
  27. sc: 'scala',
  28. scala: 'scala',
  29. clj: 'clojure',
  30. };
  31. /**
  32. * Takes in path (/Users/test/sentry/something.jsx) and returns file extension (jsx)
  33. */
  34. export function getFileExtension(fileName: string): string | undefined {
  35. // this won't work for something like .spec.jsx
  36. const segments = fileName.split('.');
  37. if (segments.length > 1) {
  38. return segments.pop();
  39. }
  40. return undefined;
  41. }
  42. /**
  43. * Takes in file extension and returns a platform string that can be passed into platformicons
  44. */
  45. export function fileExtensionToPlatform(fileExtension: string): string | undefined {
  46. return FILE_EXTENSION_TO_PLATFORM[fileExtension];
  47. }