Skip to content

Commit

Permalink
Merge pull request #41 from kyrea/staging
Browse files Browse the repository at this point in the history
Changed api URL, getFact params, funding.yml and much more..!
  • Loading branch information
kyrea committed Jun 24, 2022
2 parents 06412af + 6d9d96a commit 5cb2482
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ko_fi: aetrnyx
ko_fi: aeryk
27 changes: 4 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<h3 align="center"><strong>Generate random anime facts with a huge database.</strong></h3>
<center><strong>Powered by <a href="https://airi.kyoyo.me/" target="_blank">Airi</a></strong></center>
<center><strong>Powered by <a href="https://animu.ml/" target="_blank">Animu</a></strong></center>
<br>

Need support? _[Click here](https://discord.gg/yyW389c)_

### First make sure you have a [Airi](https://airi.kyoyo.me/) API Token. Join _[this](https://discord.gg/yyW389c)_ discord server to get one.
### First make sure you have a [Animu](https://animu.ml/) API Token. Join _[this](https://discord.gg/yyW389c)_ discord server to get one.

## Installation:

Expand All @@ -18,15 +18,7 @@ $ npm install anime-facts

```bash
$ yarn add anime-facts
```

### Query parameters _[ OPTIONAL ]_

| Parameters | Type | Description |
| :-------- | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| tags | `String` | Filter random fact by tag(s). Takes a list of one or more tag names, separated by a comma (meaning `AND`) or a pipe (meaning `OR`). A comma separated list will match facts that have **_all_** of the given tags. While a pipe (`\|`) separated list will match facts that have **_either_** of the provided tags.| |
| minLength | `Int` | The minimum Length in characters ( can be combined with `maxLength` ) | |
| maxLength | `Int` | The maximum Length in characters ( can be combined with `minLength` ) |
```

## Usage:

Expand All @@ -35,25 +27,15 @@ const AnimeFact = require("anime-facts");
const api = new AnimeFact("YOUR TOKEN");

api.getFact().then((res) => console.log(res));
```

### Using Query:

```javascript
const AnimeFact = require("anime-facts");
const api = new AnimeFact("YOUR TOKEN");
// Note currently there are only fews tags, length available in the database. So, it might return the same data multiple times.
api.getFact(null, 1, 100).then((res) => console.log(res));

// Returns with:
{
id: 5,
tags: [ 'TEZUKA Osamu', 'Artist' ],
fact: 'TEZUKA Osamu is the most famous manga artist in Japan.',
length: 54
}
```


## Functions

| **Functions** | **Description** |
Expand All @@ -65,4 +47,3 @@ api.getFact(null, 1, 100).then((res) => console.log(res));
[@LamkasDev](https://github.com/LamkasDev) for adding facts to prior database\
[@xMercyTheDeveloper](https://github.com/xMercyTheDeveloper) for adding a fact to prior database\
[@Lioness100](https://github.com/Lioness100) for adding types and improving codes in version [2.2.6](https://www.npmjs.com/package/anime-facts/v/2.2.6)\
[@Aetrnyx](https://github.com/aetrnyx) for fixing the readme in [4.3.9](https://www.npmjs.com/package/anime-facts/v/4.3.9)
2 changes: 0 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
interface AnimeFacts {
_id: number;
tags: string[];
fact: string;
length: number;
}

export function getFact(): Promise<AnimeFacts>;
27 changes: 2 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,14 @@ class AnimeFact extends EventEmitter {

/**
* Gets a fact from the api
* @param {string[]} [tags] - the array of tags
* @param {number} [minLength] - the minLength for query
* @param {number} [maxLength] - the maxLength for query
* @returns {Promise<Fact>}
*/

async getFact(tags, minLength, maxLength) {
async getFact() {
const auth = this._auth;
if (!auth) throw new TypeError("Missing authorization token");
const params = {};
if (tags === undefined) {
params.tags = "";
} else {
params.tags = tags;
}
if (minLength === undefined) {
params.minLength = "";
} else {
params.minLength = minLength;
}
if (maxLength === undefined) {
params.maxLength = "";
} else {
params.maxLength = maxLength;
}
return fetch({
url: `${api}/fact?tags=${params.tags}&minLength=${params.minLength}&maxLength=${params.maxLength}`,
url: `${api}/fact`,
headers: {
Auth: auth,
"Content-Type": "application/json",
Expand Down Expand Up @@ -72,9 +53,7 @@ class AnimeFact extends EventEmitter {
}
return {
id: res.body._id,
tags: res.body.tags || [],
fact: res.body.fact,
length: res.body.length,
};
})
.catch((err) => {
Expand All @@ -88,7 +67,5 @@ module.exports = AnimeFact;
/**
* @typedef {object} Fact
* @prop {number} id
* @prop {string[]} tags
* @prop {string} fact
* @prop {number} length
*/
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "anime-facts",
"version": "4.3.12",
"version": "5.3.12",
"description": "Generate random anime facts.",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test": "node __tests__/getFact.js"
},
"api": "https://airi.kyoyo.me/api",
"api": "https://animu.ml/api",
"repository": {
"type": "git",
"url": "git+ssh://[email protected]/notkyoyo/anime-facts.git"
"url": "git+ssh://[email protected]/kyrea/anime-facts.git"
},
"keywords": [
"anime",
Expand All @@ -19,12 +19,12 @@
"discord",
"bot"
],
"author": "aetrnyx",
"author": "aeryk",
"license": "AGPLv3",
"bugs": {
"url": "https://github.com/notkyoyo/anime-facts/issues"
"url": "https://github.com/kyrea/anime-facts/issues"
},
"homepage": "https://github.com/notkyoyo/anime-facts#readme",
"homepage": "https://github.com/kyrea/anime-facts#readme",
"dependencies": {
"eventemitter3": "^4.0.7",
"phin": "^3.5.1"
Expand Down

0 comments on commit 5cb2482

Please sign in to comment.