Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

animality

Package Overview
Dependencies
Maintainers
2
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

animality - npm Package Compare versions

Comparing version 1.2.2 to 1.2.3

2

.upm/store.json

@@ -1,1 +0,1 @@

{"version":2,"languages":{"nodejs-npm":{"specfileHash":"8cd789dafd4814f8cdc97e6b118e6fbe","lockfileHash":"c36cafe14ff3c50ab66e083ea1cadd83","guessedImports":["node-fetch"],"guessedImportsHash":"51266e8e25b3d5e637d3474eb13a80d8"}}}
{"version":2,"languages":{"nodejs-npm":{"specfileHash":"d9ce5de62186c7a0e348fb9bdcf9cbd5","lockfileHash":"6a0189fd81ccf2fca4ca857f45e2f9d6","guessedImports":["node-fetch"],"guessedImportsHash":"51266e8e25b3d5e637d3474eb13a80d8"}}}

@@ -1,47 +0,58 @@

const fetch = require('node-fetch');
const animals = [
'cat',
'dog',
'bird',
'panda',
'redpanda',
'koala',
'fox',
'whale',
'kangaroo',
'bunny'
];
const base = 'https://random-api.nitcord.repl.co';
const fetch = require("node-fetch")
/**
* @typedef {Object} APIResponse
* @property {string} [name] The animal name.
* @property {string} [image] The animal image URL.
* @property {string} [fact] The animal fact.
*/
let animals = ["cat", "dog", "bird", "panda", "redpanda", "koala", "fox", "whale", "kangaroo", "bunny"]
module.exports = {
/**
* Does a GET request showing the image and fact of an animal. This can be specified or random.
* @param {string} [type='random'] The animal name, or 'random' for a random response.
* @returns {APIResponse} The APIResponse as an object.
*/
async getAsync(type = 'random') {
if (typeof type !== 'string' || ((type = type.toLowerCase(), true) && !animals.includes(type) && type !== 'random')) throw new TypeError(`Invalid type, type must be ${animals.join(', ')}, random`);
if (type === 'random') type = animals[Math.floor(Math.random() * animals.length)];
const [{ link: image }, { fact }] = await Promise.all([
fetch(`${base}/api/img/${type}`).then(res => res.json()),
fetch(`${base}/api/facts/${type}`).then(res => res.json())
]).catch(() => {
throw new Error(`Failed to do a GET request to the '${base}' API`);
});
getAsync : async function(type){
if(!type) throw new TypeError("No arguments provided!")
if(typeof type != "string" && typeof type != "object") throw new TypeError("Invalid type of arguments! Arguments must be a string or an array!")
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 = []
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 object = {}
object["name"] = type[i]
object["image"] = imgData.link
object["fact"] = factData.fact
data[i] = object
} else{
throw new TypeError("Invalid argument! Invalid Animal Name Found in the object!")
}
}
return data
}
if(type == "random"){
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())
return {
name: type,
image,
fact
};
const data = {}
data["name"] = random
data["image"] = imgData.link
data["fact"] = factData.fact
return data;
}
if(animals.includes(type)){
const imgData = await fetch(img).then(lang => lang.json())
const factData = await fetch(fact).then(lang => lang.json())
const data = {}
data["name"] = type
data["image"] = imgData.link
data["fact"] = factData.fact
return data;
} else{
throw new TypeError("Invalid Arguments found! Please enter a valid animal as the type!")
}
}
};
}
{
"name": "animality",
"version": "1.2.2",
"version": "1.2.3",
"description": "A simple API wrapper that generates images & facts of any animal",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -7,3 +7,3 @@ # animality

Use the package manager [npm](https://www.npmjs.com/) to install random-api
Use the package manager [npm](https://www.npmjs.com/) to install `animality`

@@ -10,0 +10,0 @@ ```bash

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc