23 lines
428 B
TypeScript
23 lines
428 B
TypeScript
|
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
|
||
|
}
|
||
|
}
|