Feature/7 migrate to typescript #21

Merged
Vylpes merged 6 commits from feature/7-migrate-to-typescript into develop 2021-12-02 10:36:16 +00:00
Showing only changes of commit 4136f9f1ff - Show all commits

View file

@ -4,34 +4,32 @@
## Install ## Install
```bash
npm install --save random-bunny
``` ```
$ npm install --save random-bunny
or if you're using yarn
```bash
yarn add random-bunny
``` ```
## Usage ## Usage
```js ```ts
const { randomBunny } = require('random-bunny'); import randomBunny from "random-bunny";
randomBunny('rabbits', 'new', res => { // ... In an async function
console.log(res.title + ": " + res.url); const result = await randomBunny('rabbits', 'hot', 100);
}); console.log(result);
```
```js
const { promise } = require('random-bunny');
promise('rabbits', 'new').then((res) => {
console.log(res.title);
});
``` ```
## API ## API
### `randomBunny()` ### `randomBunny()`
Returns a `json string` for a random post to the `callback`. Accepts 3 arguments: `subreddit`, `sortby` ('new', 'hot', 'top'), `callback(res)` Returns a `json string` for a random post. Accepts 3 arguments: `subreddit`, `sortby` ('new', 'hot', 'top'), `maxTries?` (default 100)
The json string which gets returned consists of: The json string which gets returned consists of:
- archived - archived
@ -44,11 +42,9 @@ The json string which gets returned consists of:
- ups - ups
- url - url
### `promise()` `sortBy` will default to 'hot' if not given or invalid
Returns a `json string` for a random post in a `promise`. Accepts 2 arguments: `subreddit`, `sortby` ('new', 'hot', 'top'). `maxTries` prevents the script from rerolling too many times. The script rerolls the randomiser if the post its given doesn't contain an image. Default 100.
The json string returned in the promise consists of the same above.
## Notes ## Notes
@ -57,8 +53,8 @@ The json string returned in the promise consists of the same above.
## Links ## Links
* Discord: [Server Link](https://discord.gg/UyAhAVp) * Discord: [Server Link](https://vylpes.xyz/discord)
## License ## License
MIT © [Vylpes](https://gitlab.vylpes.com/Vylpes) MIT © [Vylpes](https://www.vylpes.com)