1.0.3 • Published 3 years ago

check-is-image v1.0.3

Weekly downloads
4
License
MIT
Repository
-
Last release
3 years ago

check-is-image

A module to check if the input is a valid* image

* If the image is a URL the module cannot check if the URL is a image

API

const isImage = require('check-is-image')

isImage('https://i.imgur.com/YkU9QCI.jpeg')
// true
isImage(`${__dirname}/./img.png`)
//true
isImage(<ImageBuffer>)
//true

Example with Discord.js

const {Client} = require('discord.js'),
isImage = require('check-is-image'),
Bot = new Client();//We declare Client of discord.js, the module and we create a new Client of discord

Bot.on('ready', () => {
console.log('Ready')
});//When the bot be ready we put in console 'Ready'

Bot.on('message', message => {
if(message.author.bot)return;//if the author is a bot we return

const prefix = '!'//declare the prefix

if(!message.content.startsWith(prefix))return;//if the message dont starts with the prefix we return

const args = message.content.slice(prefix.length).trim().split(/ +/g),
command = args.shift().toLowerCase();//we declare args and command to make the things easier

if(command === 'checkimage'){//if the command is checkimage
	const options = {false:'Is not a image',true:'Is a image'},
	check = options[isImage(args[0])]//we declare options and we make that if the check returns false or true put the designated option
	
	message.reply(check)//we reply the message with the result
}
});

Bot.login('token')//we login the bot with his token
1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago