1.0.1 • Published 7 years ago
validate-image-url v1.0.1
Validate Image URL
Checks asynchronously whether an image URL is valid or not.
By default, if an image URL is invalid, the browser would show the following image:
In that case, you might want show a different image such as:
This package tells you whether the image URL is valid or not.
Installation:
$ npm install --save validate-image-url
Usage:
import validator from 'validate-image-url'
const promise = validator({url: '<image-url>', timeout: 10000})
.then(({image, url}) => {
console.log('Image URL is valid.', 'URL:', url, 'image:', image)
})
.catch((err) => {
console.error('Invalid image URL or image could not be fetched within 10000 milliseconds.', 'error:', err)
})
// NOTE: the promise can be canceled by calling
// promise.cancel()
Options:
- url - (required) image URL.
- timeout - (optional) timeout in milliseconds before canceling request and rejecting the promise. Default: 5000 milliseconds.