Comparing version 1.1.6 to 1.1.7
@@ -1,1 +0,1 @@ | ||
{"version":2,"languages":{"nodejs-npm":{"specfileHash":"3f85ba38263a4f7c228956a563f60c08","lockfileHash":"16dc80641792622cb20c264de2638a74","guessedImports":["node-fetch"],"guessedImportsHash":"51266e8e25b3d5e637d3474eb13a80d8"}}} | ||
{"version":2,"languages":{"nodejs-npm":{"specfileHash":"6f95d000219ce164f0b9bc6db6163c12","lockfileHash":"29d0959a841c08da52588f62aa98e2bc","guessedImportsHash":"5e056c500a1c4b6a7110b50d807bade5"}}} |
218
index.js
@@ -1,172 +0,52 @@ | ||
const fetch = require("node-fetch") | ||
const { request } = require('https'); | ||
const animals = ["cat", "dog", "bird", "panda", "redpanda", "koala", "fox", "whale", "kangaroo", "bunny"]; | ||
const fetch = async (path) => { | ||
return new Promise(resolve => { | ||
request({ | ||
method: 'GET', | ||
host: 'random-api.nitcord.repl.co', | ||
userAgent: null, | ||
headers: {}, | ||
path, | ||
}, res => { | ||
let data = ''; | ||
res.on('data', chunk => data += chunk); | ||
res.once('error', err => { throw new Error(err) }); | ||
res.once('end', () => { | ||
try { | ||
resolve(JSON.parse(data)); | ||
} catch { | ||
throw new Error('Cannot parse JSON data. Please try again later.'); | ||
} | ||
}); | ||
}).end(); | ||
}); | ||
} | ||
module.exports = { | ||
getAsync : async function(type){ | ||
if(typeof type != "string" && typeof type != "object") throw new TypeError("Invalid type of arguments! Arguments must be a string or an array!") | ||
if(!type) throw new TypeError("No arguments provided!") | ||
let img = `https://random-api.nitcord.repl.co/api/img/${type}` | ||
let fact = `https://random-api.nitcord.repl.co/api/facts/${type}` | ||
if(typeof type == "object"){ | ||
let data = [] | ||
let animals = ["cat", "dog", "bird", "panda", "redpanda", "koala", "fox", "whale", "kangaroo", "bunny"] | ||
for(var i = 0; i < type.length; i++){ | ||
if(animals.includes(type[i])){ | ||
img = `https://random-api.nitcord.repl.co/api/img/${type[i]}` | ||
fact = `https://random-api.nitcord.repl.co/api/facts/${type[i]}` | ||
const imgData = await fetch(img).then(lang => lang.json()) | ||
const factData = await fetch(fact).then(lang => lang.json()) | ||
let factReceived = factData.fact | ||
let imgReceived = imgData.link | ||
let object = {} | ||
object["name"] = type[i] | ||
object["image"] = imgReceived | ||
object["fact"] = factReceived | ||
data[i] = object | ||
} else{ | ||
throw new TypeError("Invalid argument! Invalid Animal Name!") | ||
} | ||
} | ||
return data | ||
/** | ||
* Does a GET request showing the image and fact of an animal. This can be specified or random. | ||
* @param {string} type The animal name, or 'random' for a random response. | ||
* @typedef {Object} [APIResponse] | ||
* @property {string} [APIResponse.name] The animal name. | ||
* @property {string} [APIResponse.image] The animal image URL. | ||
* @property {string} [APIResponse.fact] The animal fact. | ||
* @returns {APIResponse} The APIResponse as an object. | ||
*/ | ||
getAsync: async (type) => { | ||
if (!type || typeof type !== 'string' || (!animals.includes(type.toLowerCase()) && type.toLowerCase() !== 'random')) throw new TypeError(`Invalid type, type must be ${[...animals, 'random'].join(', ')}`); | ||
type = type.toLowerCase(); | ||
if (type === 'random') | ||
type = animals[Math.floor(Math.random() * animals.length)]; | ||
const image = await fetch(`/api/img/${type}`); | ||
const fact = await fetch(`/api/facts/${type}`); | ||
return { | ||
name: type, | ||
image: image.link, | ||
fact: fact.fact | ||
}; | ||
} | ||
if(type == "cat"){ | ||
const imgData = await fetch(img).then(lang => lang.json()) | ||
const factData = await fetch(fact).then(lang => lang.json()) | ||
let factReceived = factData.fact | ||
let imgReceived = imgData.link | ||
const data = {} | ||
data["image"] = imgReceived | ||
data["fact"] = factReceived | ||
return data; | ||
} | ||
if(type == "dog"){ | ||
const imgData = await fetch(img).then(lang => lang.json()) | ||
const factData = await fetch(fact).then(lang => lang.json()) | ||
let factReceived = factData.fact | ||
let imgReceived = imgData.link | ||
const data = {} | ||
data["image"] = imgReceived | ||
data["fact"] = factReceived | ||
return data; | ||
} | ||
if(type == "bird"){ | ||
const imgData = await fetch(img).then(lang => lang.json()) | ||
const factData = await fetch(fact).then(lang => lang.json()) | ||
let factReceived = factData.fact | ||
let imgReceived = imgData.link | ||
const data = {} | ||
data["image"] = imgReceived | ||
data["fact"] = factReceived | ||
return data; | ||
} | ||
if(type == "panda"){ | ||
const imgData = await fetch(img).then(lang => lang.json()) | ||
const factData = await fetch(fact).then(lang => lang.json()) | ||
let factReceived = factData.fact | ||
let imgReceived = imgData.link | ||
const data = {} | ||
data["image"] = imgReceived | ||
data["fact"] = factReceived | ||
return data; | ||
} | ||
if(type == "redpanda"){ | ||
const imgData = await fetch(img).then(lang => lang.json()) | ||
const factData = await fetch(fact).then(lang => lang.json()) | ||
let factReceived = factData.fact | ||
let imgReceived = imgData.link | ||
const data = {} | ||
data["image"] = imgReceived | ||
data["fact"] = factReceived | ||
return data; | ||
} | ||
if(type == "koala"){ | ||
const imgData = await fetch(img).then(lang => lang.json()) | ||
const factData = await fetch(fact).then(lang => lang.json()) | ||
let factReceived = factData.fact | ||
let imgReceived = imgData.link | ||
const data = {} | ||
data["image"] = imgReceived | ||
data["fact"] = factReceived | ||
return data; | ||
} | ||
if(type == "fox"){ | ||
const imgData = await fetch(img).then(lang => lang.json()) | ||
const factData = await fetch(fact).then(lang => lang.json()) | ||
let factReceived = factData.fact | ||
let imgReceived = imgData.link | ||
const data = {} | ||
data["image"] = imgReceived | ||
data["fact"] = factReceived | ||
return data; | ||
} | ||
if(type == "whale"){ | ||
const imgData = await fetch(img).then(lang => lang.json()) | ||
const factData = await fetch(fact).then(lang => lang.json()) | ||
let factReceived = factData.fact | ||
let imgReceived = imgData.link | ||
const data = {} | ||
data["image"] = imgReceived | ||
data["fact"] = factReceived | ||
return data; | ||
} | ||
if(type == "kangaroo"){ | ||
const imgData = await fetch(img).then(lang => lang.json()) | ||
const factData = await fetch(fact).then(lang => lang.json()) | ||
let factReceived = factData.fact | ||
let imgReceived = imgData.link | ||
const data = {} | ||
data["image"] = imgReceived | ||
data["fact"] = factReceived | ||
return data; | ||
} | ||
if(type == "bunny"){ | ||
const imgData = await fetch(img).then(lang => lang.json()) | ||
const factData = await fetch(fact).then(lang => lang.json()) | ||
let factReceived = factData.fact | ||
let imgReceived = imgData.link | ||
const data = {} | ||
data["image"] = imgReceived | ||
data["fact"] = factReceived | ||
return data; | ||
} | ||
if(type == "random"){ | ||
let animals = ["cat", "dog", "bird", "panda", "redpanda", "koala", "fox", "whale", "kangaroo", "bunny"] | ||
let random = animals[Math.floor(Math.random() * animals.length)] | ||
img = `https://random-api.nitcord.repl.co/api/img/${random}` | ||
fact = `https://random-api.nitcord.repl.co/api/facts/${random}` | ||
const imgData = await fetch(img).then(lang => lang.json()) | ||
const factData = await fetch(fact).then(lang => lang.json()) | ||
let factReceived = factData.fact | ||
let imgReceived = imgData.link | ||
const data = {} | ||
data["name"] = random | ||
data["image"] = imgReceived | ||
data["fact"] = factReceived | ||
return data; | ||
} else{ | ||
throw new TypeError("Invalid arguments!") | ||
} | ||
} | ||
} | ||
}; |
{ | ||
"name": "animality", | ||
"version": "1.1.6", | ||
"version": "1.1.7", | ||
"description": "A simple API wrapper that generates images & facts of any animal", | ||
"main": "index.js", | ||
"dependencies": { | ||
"node-fetch": "^2.6.1" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": {}, | ||
@@ -15,12 +13,11 @@ "scripts": { | ||
"type": "git", | ||
"url": "https://github.com/VeryHamburger/animality" | ||
"url": "git+https://github.com/veryhamburger/Animality.git" | ||
}, | ||
"keywords": [ | ||
"animal", | ||
"api", | ||
"random", | ||
"random-api" | ||
], | ||
"author": "Hamburger", | ||
"license": "MIT" | ||
"keywords": [], | ||
"author": "", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/veryhamburger/Animality/issues" | ||
}, | ||
"homepage": "https://github.com/veryhamburger/Animality#readme" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
0
4
4626
48
2
- Removednode-fetch@^2.6.1
- Removednode-fetch@2.7.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)