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

some-random-cat

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

some-random-cat - npm Package Compare versions

Comparing version 1.0.15 to 1.0.20

2

examples/example.js
const random = require('../index')
random.Random.newCat()
random.Random.newJoke(true, true)
.then(res => console.log(res))
.catch(e => console.error(e))
{
"name": "some-random-cat",
"version": "1.0.15",
"version": "1.0.20",
"description": "A utility which generates random cat images with a URL",

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

@@ -1,20 +0,19 @@

��# some-random-cat
A very suitable API to generate random images of cats, dogs and random jokes, facts... A lot more!
**Author:** Aktindo
**Dependencies:** axios
**Versions:** v1.0.0 (current)
## How to use it? (Example)
Generate a random picture of cat:
```javascript
const somethingRandom = require('some-random-cat')
somethingRandom.Random.newCat()
.then(res => console.log(res)) // The function returns a pending promise and can be logged using .then
.catch(e => console.error(e)) // Catch the error
```
## Documentation
It will be soon available in v1.1.0
# some-random-cat
A very suitable API to generate random images of cats, dogs and random jokes, facts... A lot more!
**Author:** Aktindo
**Dependencies:** axios
**Versions:** v1.0.0 (current)
## How to use it? (Example)
Generate a random picture of cat:
```javascript
const somethingRandom = require('some-random-cat')
somethingRandom.Random.newCat()
.then(res => console.log(res)) // The function returns a pending promise and can be logged using .then
.catch(e => console.error(e)) // Catch the error
```
## Documentation
It will be soon available in v1.1.5
const axios = require('axios')
class Random {
/**
* Please do not instantiate this class. You can access it by doing require('some-random-cat').Random
* ⚠ Please do not instantiate this class. You can access it by doing require('some-random-cat').Random
*/
/*
/*
* <warn>Static class</warn>
*/
constructor() {
throw new Error('RandomAPIError: You may not instantiate this class!')
throw new Error('You may not instantiate this class!')
}
/**
* @returns {Promise<Pending>}
*/
static async newCat() {
const res = await axios.get('https://api.thecatapi.com/v1/images/search?format=json')
if (!res) throw new Error('Error fetching a random image from API.')
let data = res.data[0].url
return data
}
/**
* Returns an object by default.
* @param {Boolean} [title] If you want to get the title
* @param {Boolean} [body] If you want to get the body
* @param {Boolean} [url] If you want to get the url
* @returns {Promise<Pending>}
*/
static async newJoke(title, body, url) {
// https://apis.duncte123.me/joke
const res = await axios.get('https://apis.duncte123.me/joke')
if (!res) throw new Error('Error fetching a random joke from API.')
if (title === true) return res.data.data.title
if (body === true) return
if (url === true) return res.data.data.url
else return res.data.data
}
}
module.exports = Random
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