-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from notkyoyo/canary
Added Query Support, changed packages, and so on.
- Loading branch information
Showing
9 changed files
with
147 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.vscode/ | ||
node_modules/ | ||
index.d.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ node_modules/ | |
__tests__/ | ||
.deepsource.toml | ||
.github/ | ||
package-lock.json | ||
package-lock.json | ||
index.d.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
const random = require("../index"); | ||
|
||
random.getFact().then((r) => console.log(r)); | ||
const { getFact } = require("../index"); | ||
getFact().then((res) => console.log(res)); | ||
// .catch((err) => { | ||
// console.log(err); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
interface AnimeFact { | ||
interface AnimeFacts { | ||
_id: number; | ||
tags: string[]; | ||
fact: string; | ||
length: number; | ||
} | ||
|
||
export async function getFact(): Promise<AnimeFact>; | ||
export function getFact(): Promise<AnimeFacts>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,76 @@ | ||
const axios = require("axios"); | ||
const fetch = require("phin"); | ||
|
||
const fact = { | ||
getFact() { | ||
return axios.get(`https://animu.ml/fact`).then((res) => res.data); | ||
}, | ||
}; | ||
/** | ||
* 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>} | ||
*/ | ||
|
||
module.exports = fact; | ||
async function getFact(tags, minLength, maxLength) { | ||
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: `https://animu.ml/fact?tags=${params.tags}&minLength=${params.minLength}&maxLength=${params.maxLength}`, | ||
parse: "json", | ||
}) | ||
.then((res) => { | ||
if (res.statusCode !== 200) | ||
switch (res.statusCode) { | ||
case 404: | ||
return { | ||
statusCode: res.statusCode, | ||
body: res.body, | ||
error: "Could not find any fact", | ||
}; | ||
break; | ||
case 502: | ||
return { | ||
statusCode: res.statusCode, | ||
body: res.body, | ||
error: "Server down", | ||
}; | ||
break; | ||
default: | ||
return { | ||
statusCode: res.statusCode, | ||
body: res.body, | ||
error: "Unknown error", | ||
}; | ||
} | ||
return { | ||
id: res.body._id, | ||
tags: res.body.tags || [], | ||
fact: res.body.fact, | ||
length: res.body.length, | ||
}; | ||
}) | ||
.catch((err) => { | ||
throw err; | ||
}); | ||
} | ||
|
||
module.exports = { getFact }; | ||
|
||
/** | ||
* @typedef {object} Fact | ||
* @prop {number} id | ||
* @prop {string[]} tags | ||
* @prop {string} fact | ||
* @prop {number} length | ||
*/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters