utils.tsx 837 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. type Status =
  2. | 'found'
  3. | 'unused'
  4. | 'missing'
  5. | 'malformed'
  6. | 'timeout'
  7. | 'fetching_failed'
  8. | 'other'
  9. | null
  10. | undefined;
  11. function getStatusWeight(status: Status) {
  12. switch (status) {
  13. case null:
  14. case undefined:
  15. case 'unused':
  16. return 0;
  17. case 'found':
  18. return 1;
  19. default:
  20. return 2;
  21. }
  22. }
  23. function combineStatus(debugStatus: Status, unwindStatus: Status): Status {
  24. const debugWeight = getStatusWeight(debugStatus);
  25. const unwindWeight = getStatusWeight(unwindStatus);
  26. const combined = debugWeight >= unwindWeight ? debugStatus : unwindStatus;
  27. return combined || 'unused';
  28. }
  29. function getFileName(path: string) {
  30. const directorySeparator = /^([a-z]:\\|\\\\)/i.test(path) ? '\\' : '/';
  31. return path.split(directorySeparator).pop();
  32. }
  33. export {combineStatus, getFileName};