Skip to content

Commit

Permalink
nyaa~
Browse files Browse the repository at this point in the history
  • Loading branch information
purpleblueslime authored Apr 28, 2023
0 parents commit 3dcd03e
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 0 deletions.
21 changes: 21 additions & 0 deletions license
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -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};
34 changes: 34 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 18 additions & 0 deletions src/neko.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {nyaa} from './nyaa.ts';
import {neko_url} from './type.ts';

/**
* @export
* @function gimme_neko
* @returns Promise<neko_url>
* @since 1.0.0
*/

export async function gimme_neko (): Promise<neko_url> {
try {
return await nyaa();
}
catch (error) {
console.error(error);
}
}
17 changes: 17 additions & 0 deletions src/nyaa.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {neko_url} from './type.ts';

/**
* @export
* @function nyaa
* @returns Promise<neko_url>
* @since 1.0.0
*/

export async function nyaa (): Promise<neko_url> { // 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<
}
8 changes: 8 additions & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3dcd03e

Please sign in to comment.