image.ts 356 B

12345678910111213
  1. export function getImageUrl(path: string) {
  2. const url = new URL(`/src/assets/${path}`, import.meta.url);
  3. return url.href;
  4. }
  5. export const isImage = (url: string) => {
  6. const last = url.lastIndexOf(".");
  7. const fileExt = url.substring(last + 1);
  8. if (["jpg", "jpeg", "png", "gif", "webp"].includes(fileExt)) {
  9. return true;
  10. }
  11. return false;
  12. };