diff --git a/license b/license new file mode 100644 index 0000000..a3d45e1 --- /dev/null +++ b/license @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 SLIME + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/mod.ts b/mod.ts new file mode 100644 index 0000000..6fe4b0b --- /dev/null +++ b/mod.ts @@ -0,0 +1,5 @@ +import {gimme_neko} from './src/neko.ts'; +import {neko_url} from './src/type.ts'; + +export {gimme_neko}; +export type {neko_url}; diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..f35a303 --- /dev/null +++ b/readme.md @@ -0,0 +1,34 @@ +# gimme_neko + +I just want a neko using **[nekos.best](https://nekos.best) api**~ + +![nekohug](https://user-images.githubusercontent.com/84064124/233825692-588a474f-3e96-47d0-b2fb-745c6cc180e3.png)![nekohug](https://user-images.githubusercontent.com/84064124/233825688-1293878c-090d-48b0-948b-3f904c355bd8.png) + +## Import `deno 🦖` +```ts +import {gimme_neko} from 'https://deno.land/x/gimme_neko@v1.0.0/mod.ts'; +``` + +# function +## `gimme_neko(): neko_url` +**SLIME:** smth like- +```ts +import {gimme_neko, neko_url} from 'https://deno.land/x/gimme_neko@v1.0.0/mod.ts'; // import + +const neko: neko_url = await gimme_neko(); // (await) cus returns a Promise<> +console.log(neko); // log neko +``` +## console +```sh +$ https://nekos.best/api/v2/neko/07996548-24a8-44b5-9200-2a0a74309eb3.png +``` +(or) +```sh +$ undefined +``` +**SLIME:** **`undefined`** cus error ;-; +## error +```sh +$ SLIME: theres no neko here~ +``` +**SLIME:** never really happens but JIC (just-in-case) diff --git a/src/neko.ts b/src/neko.ts new file mode 100644 index 0000000..73eb0bc --- /dev/null +++ b/src/neko.ts @@ -0,0 +1,18 @@ +import {nyaa} from './nyaa.ts'; +import {neko_url} from './type.ts'; + +/** + * @export + * @function gimme_neko + * @returns Promise + * @since 1.0.0 + */ + +export async function gimme_neko (): Promise { + try { + return await nyaa(); + } + catch (error) { + console.error(error); + } +} \ No newline at end of file diff --git a/src/nyaa.ts b/src/nyaa.ts new file mode 100644 index 0000000..3549de4 --- /dev/null +++ b/src/nyaa.ts @@ -0,0 +1,17 @@ +import {neko_url} from './type.ts'; + +/** + * @export + * @function nyaa + * @returns Promise + * @since 1.0.0 + */ + +export async function nyaa (): Promise { // undefined cus error ;-; + const url = 'https://nekos.best/api/v2/neko'; // nekoUrl + const {results} = await (await fetch(url)).json(); // results : Array + if (!results) throw 'SLIME: theres no neko here~'; // throw smth (never really happens but JIC) + + const data = await results.pop() // (pop) -> data : Object + return data.url; // return nekos url >u< +} \ No newline at end of file diff --git a/src/type.ts b/src/type.ts new file mode 100644 index 0000000..b02e609 --- /dev/null +++ b/src/type.ts @@ -0,0 +1,8 @@ +/** + * @export + * @type neko_url + * @since 1.0.0 + */ + +export + type neko_url = `https://nekos.best/api/v2/neko/${any}.png` | undefined; // any : (0_9 a_z -) | undef : cus error