degmods.com/src/utils/url.ts

23 lines
428 B
TypeScript
Raw Normal View History

export const isValidUrl = (url: string) => {
try {
new URL(url)
return true
} catch (_) {
return false
}
}
export const isValidImageUrl = (url: string) => {
const regex = /\.(jpeg|jpg|gif|png)$/
return regex.test(url)
}
export const isReachable = async (url: string) => {
try {
const response = await fetch(url, { method: 'HEAD' })
return response.ok
} catch (error) {
return false
}
}