dadjoke.js
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -1,47 +0,18 @@ | ||
/** | ||
* The base class of the DadJokeClient | ||
*/ | ||
class DadJokeClient | ||
{ | ||
/** | ||
* Creates a new DadJoke instance | ||
*/ | ||
constructor(userAgent) | ||
{ | ||
/** | ||
* Snekfetch | ||
* | ||
* @type {Snekfetch} | ||
* @private | ||
*/ | ||
this._snek = require('snekfetch'); | ||
/** | ||
* The base url | ||
* | ||
* @type {String} | ||
*/ | ||
this.baseURL = require('./util/Constants').BASE_URL; | ||
this.userAgent = userAgent; | ||
module.exports = class DadJokeClient { | ||
constructor(userAgent = 'dadjoke.js/Production/v0.1.0') { | ||
this.userAgent = userAgent; | ||
this.snek = require('snekfetch'); | ||
this.baseURL = require('../util/Constants').URL; | ||
} | ||
/** | ||
* Gets a Dad Joke! | ||
* | ||
* @returns {Promise<String>} The URL | ||
*/ | ||
async getDadJoke() | ||
{ | ||
return new Promise((res, rej) => | ||
{ | ||
return this._snek.get(this.baseURL) | ||
.set('User-Agent', this.userAgent || `dadjoke.js (v${require('../../package.json').version} https://github.com/ohlookitsAugust/dadjoke.js)`) | ||
get() { | ||
return new Promise((resolve, reject) => { | ||
this.snek | ||
.get(this.baseURL) | ||
.set('Accept', 'application/json') | ||
.then((result) => res(result.body)) | ||
.catch((err) => rej(err)); | ||
.set('User-Agent', this.userAgent) | ||
.then((res) => resolve(res.body)) | ||
.catch((err) => reject(err)); | ||
}); | ||
} | ||
} | ||
module.exports = DadJokeClient; | ||
}; |
module.exports = { | ||
DadJokeClient: require('./core/DadJokeClient'), | ||
Constants: require('./core/util/Constants'), | ||
Client: require('./core/DadJokeClient'), | ||
Constants: require('./util/Constants'), | ||
version: require('../package.json').version | ||
}; |
{ | ||
"name": "dadjoke.js", | ||
"description": "An API wrapper for a dad joke! I mean, who doesn't love them?!", | ||
"version": "0.0.2", | ||
"description": "dadjoke.js is an API Wrapper that handles http requests for Dad Jokes.", | ||
"version": "0.1.0", | ||
"dependencies": { | ||
"snekfetch": "3.6.4" | ||
"snekfetch": "4.0.4" | ||
}, | ||
"author": "August (Chris)", | ||
"bugs": { | ||
"url": "https://github.com/ohlookitsAugust/dadjoke.js/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ohlookitsAugust/dadjoke.js" | ||
}, "main": "./lib/index.js" } | ||
"main": "./lib/index.js", | ||
"typings": "./typings/index.d.ts", | ||
"author": { | ||
"name": "August (Chris)", | ||
"url": "https://augu.me", | ||
"email": "august@augu.me" | ||
} | ||
} |
# dadjoke.js | ||
dadjoke.js is a Dad Joke wrapper. | ||
[`dadjoke.js`](https://npmjs.com/package/dadjoke.js) is an API Wrapper that handles http requests for Dad Jokes. | ||
## API | ||
```js | ||
const { DadJokeClient } = require('dadjoke.js'); | ||
const client = new DadJokeClient(); | ||
**You can add dadjoke.js as an dependency by:** | ||
```sh | ||
# Yarn | ||
$ yarn add dadjoke.js | ||
client.getDadJoke().then((body) => { | ||
console.log(`📣 ${body.joke}`); | ||
}); | ||
# NPM | ||
$ npm install dadjoke.js | ||
``` |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
2772
24
11
1
+ Addedsnekfetch@4.0.4(transitive)
- Removedsnekfetch@3.6.4(transitive)
Updatedsnekfetch@4.0.4