├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── package.json ├── src ├── index.ts ├── structures │ ├── Endpoint.ts │ └── SRAClient.ts └── util │ ├── Errors.ts │ └── index.ts ├── test └── index.js ├── tsconfig.json └── typings └── index.d.ts /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | *-audit.json 8 | 9 | # Dependency directories 10 | node_modules/ 11 | jspm_packages/ 12 | package-lock.json 13 | yarn.lock 14 | 15 | # Runtime data 16 | pids 17 | *.pid 18 | *.seed 19 | 20 | # Miscellaneous 21 | *.env 22 | .yarn-integrity 23 | .eslintcache 24 | .npm 25 | .tmp/ 26 | ormconfig.json 27 | *.tsbuildinfo 28 | config*.yml 29 | .vscode 30 | 31 | # Build 32 | dist/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [Some Random Api](https://some-random-api.ml) 2 | [![NpmPackage](https://nodei.co/npm/some-random-api.png?downloads=true)](https://www.npmjs.com/package/some-random-api) 3 | 4 | [![Discord](https://discordapp.com/api/guilds/486116455163625513/embed.png?style=shield)](https://discord.gg/tTUMWFd) 5 | 6 | ## About 7 | 8 | Some Random Api is an api where you can find a lot of random apis from games, sites, even animal facts! 9 | 10 | __Advantages of Some Random Api__ 11 | - Simple rest api 12 | - easy to use 13 | - free of charge 14 | - no keys 15 | 16 | __For more information__ Check the [docs](https://some-random-api.ml/docs) 17 | 18 | Looking for wrappers for other languages? 19 | Go [here](https://some-random-api.ml/wrappers) for the list of all wrappers! 20 | 21 | 22 | 23 | ## Code Examples 24 | 25 | ```javascript 26 | const { SRAClient } = require('some-random-api'); 27 | 28 | const sraClient = new SRAClient(/* Insert API key if available */); 29 | sraClient.fetch('/chatbot', { message: 'Hello' }).then(console.log); 30 | ``` 31 | 32 | 33 | ## Links 34 | - Contact me on discord - Telk#4038 35 | - [Discord server](https://discord.gg/tTUMWFd) 36 | - [GitHub Repo](https://github.com/telkenes/some-random-api) 37 | - [NPM](https://www.npmjs.com/package/some-random-api) 38 | 39 | 40 | 41 | ## License 42 | Released under the [Apache 2.0](LICENSE) License 43 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "some-random-api", 3 | "version": "1.2.0", 4 | "description": "some random apis for all your needs", 5 | "main": "dist/index.js", 6 | "types": "typings/index.d.ts", 7 | "scripts": { 8 | "test": "node test", 9 | "watch": "tsc -w", 10 | "postinstall": "npm run build", 11 | "build": "tsc", 12 | "build:watch": "tsc -w", 13 | "lint": "eslint src --ext .ts", 14 | "lint:fix": "eslint src --ext .ts --fix", 15 | "prepare": "npm run build", 16 | "prepublishOnly": "npm run lint", 17 | "preversion": "npm run lint", 18 | "version": "git add -A src", 19 | "postversion": "git push origin master && git push origin master --tags" 20 | }, 21 | "repository": { 22 | "type": "git", 23 | "url": "git+https://github.com/telkenes/some-random-api.git" 24 | }, 25 | "keywords": [ 26 | "api", 27 | "free" 28 | ], 29 | "author": "Telk", 30 | "license": "Apache-2.0", 31 | "bugs": { 32 | "url": "https://github.com/telkenes/some-random-api/issues" 33 | }, 34 | "homepage": "https://github.com/telkenes/some-random-api#readme", 35 | "dependencies": { 36 | "node-fetch": "^2.2.0" 37 | }, 38 | "devDependencies": { 39 | "@typescript-eslint/eslint-plugin": "^2.9.0", 40 | "@typescript-eslint/parser": "^2.9.0", 41 | "eslint": "^6.7.1", 42 | "eslint-config-marine": "^5.3.2", 43 | "@types/node": "^12.12.14", 44 | "@types/node-fetch": "^2.5.4", 45 | "typescript": "^3.7.2" 46 | }, 47 | "eslintConfig": { 48 | "extends": "marine/node", 49 | "rules": { 50 | "@typescript-eslint/explicit-member-accessibility": "off" 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './structures/SRAClient'; 2 | export * from './structures/Endpoint'; 3 | export * from './util'; 4 | -------------------------------------------------------------------------------- /src/structures/Endpoint.ts: -------------------------------------------------------------------------------- 1 | export interface EndpointOptions { 2 | query: { [key: string]: EndpointQuery }; 3 | cooldown: number; 4 | premium: boolean; 5 | } 6 | 7 | export interface EndpointQuery { 8 | key: string; 9 | required?: boolean; 10 | default?: any; 11 | } 12 | 13 | export type Path = 14 | 15 | // Facts 16 | '/facts/dog' | 17 | '/facts/cat' | 18 | '/facts/panda' | 19 | '/facts/fox' | 20 | '/facts/birb' | 21 | '/facts/koala' | 22 | '/facts/racoon' | 23 | '/facts/kangaroo' | 24 | '/facts/elephant' | 25 | '/facts/giraffe' | 26 | '/facts/whale' | 27 | 28 | // Images 29 | '/img/dog' | 30 | '/img/cat' | 31 | '/img/panda' | 32 | '/img/fox' | 33 | '/img/birb' | 34 | '/img/koala' | 35 | '/img/racoon' | 36 | '/img/kangaroo' | 37 | '/img/elephant' | 38 | '/img/giraffe' | 39 | '/img/whale' | 40 | '/img/pikachu' | 41 | 42 | // Animal 43 | '/animal/dog' | 44 | '/animal/cat' | 45 | '/animal/panda' | 46 | '/animal/fox' | 47 | '/animal/birb' | 48 | '/animal/koala' | 49 | '/animal/racoon' | 50 | '/animal/kangaroo' | 51 | '/animal/elephant' | 52 | '/animal/giraffe' | 53 | '/animal/whale' | 54 | 55 | // Gif 56 | '/animu/wink' | 57 | '/animu/pat' | 58 | '/animu/hug' | 59 | 60 | // Canvas 61 | '/canvas/gay' | 62 | '/canvas/glass' | 63 | '/canvas/wasted' | 64 | '/canvas/triggered' | 65 | '/canvas/greyscale' | 66 | '/canvas/invert' | 67 | '/canvas/invertgreyscale' | 68 | '/canvas/brightness' | 69 | '/canvas/threshold' | 70 | '/canvas/sepia' | 71 | '/canvas/red' | 72 | '/canvas/green' | 73 | '/canvas/blue' | 74 | '/canvas/color' | 75 | '/canvas/pixelate' | 76 | '/canvas/youtube-comment' | 77 | '/canvas/color-viewer' | 78 | '/canvas/hex' | 79 | '/canvas/rgb' | 80 | 81 | // Other 82 | '/pokedex' | 83 | '/chatbot' | 84 | '/mc' | 85 | '/lyrics' | 86 | '/binary' | // encode & decode 87 | '/base64' | // encode & decode 88 | '/meme' | 89 | '/bottoken'; 90 | 91 | export class Endpoint { 92 | public query?: EndpointOptions['query']; 93 | public cooldown: EndpointOptions['cooldown']; 94 | public premium: EndpointOptions['premium']; 95 | 96 | public constructor( 97 | public path: Path, 98 | options: Partial = {}, 99 | ) { 100 | this.path = path; 101 | 102 | const { query, cooldown = 100, premium = false} = options; 103 | this.query = query; 104 | this.cooldown = cooldown; 105 | this.premium = premium; 106 | } 107 | } -------------------------------------------------------------------------------- /src/structures/SRAClient.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch'; 2 | import { posix } from 'path'; 3 | import { URL, URLSearchParams } from 'url'; 4 | import { Path, Endpoint } from './Endpoint'; 5 | import { loadEndpoints } from '../util'; 6 | import { EndpointNotExist, MissingParameter, PremiumNeeded } from '../util/Errors'; 7 | import { promisify } from 'util'; 8 | 9 | const wait = promisify(setTimeout); 10 | 11 | interface Cooldown { 12 | path: Path; 13 | ends: number; 14 | } 15 | 16 | export class SRAClient { 17 | public baseURL = 'https://some-random-api.ml'; 18 | public baseEndpoint = '/'; 19 | private endpoints!: Map; 20 | private cooldowns: Map = new Map(); 21 | 22 | public constructor(public apiKey: string = '') { 23 | this.apiKey = apiKey; 24 | this.loadEndpoints(); 25 | } 26 | 27 | private loadEndpoints(): void { 28 | this.endpoints = new Map(); 29 | loadEndpoints(this.endpoints); 30 | } 31 | 32 | public async fetch(path: Path, query?: object): Promise { 33 | if (!this.endpoints.has(path)) { 34 | throw new EndpointNotExist(path); 35 | } 36 | 37 | const endpoint = this.endpoints.get(path)!; 38 | 39 | if (this.cooldowns.has(path)) { 40 | let cooldown = this.cooldowns.get(path)!; 41 | if (cooldown.ends > Date.now()) 42 | await wait(this.cooldowns.get(path)?.ends! - Date.now()); 43 | } 44 | 45 | const url = new URL(posix.join(this.baseEndpoint, path), this.baseURL); 46 | const params = new URLSearchParams(); 47 | 48 | if (this.apiKey) params?.append('key', this.apiKey); 49 | 50 | if (query) { 51 | for (const [k, v] of Object.entries(query)) { 52 | params.append(k, v); 53 | } 54 | } 55 | 56 | this.validateRequest(endpoint, query); 57 | 58 | try { 59 | const res = await fetch(params ? `${url}?${params}` : url); 60 | this.cooldowns.set(path, { path, ends: Date.now() + endpoint.cooldown || 100 }); 61 | const type = res.headers.get('content-type'); 62 | let output; 63 | if (type?.includes('application/json')) { 64 | output = await res.json(); 65 | 66 | if (!res.ok || output.error) { 67 | throw new Error(output.error ? output.error : output); 68 | } 69 | return output; 70 | } else if (type?.includes('image')) { 71 | output = await res.buffer(); 72 | return output; 73 | } 74 | } catch (error) { 75 | throw new Error(error); 76 | } 77 | } 78 | 79 | private validateRequest(endpoint: Endpoint, query: any = {}): void { 80 | if (endpoint.query) { 81 | const entries = Object.entries(endpoint.query); 82 | 83 | for (const [k, v] of entries) { 84 | if (v.required === true && !query[k]) { 85 | throw new MissingParameter(k); 86 | } 87 | } 88 | } 89 | 90 | if (endpoint.premium && !this.apiKey) { 91 | throw new PremiumNeeded(endpoint.path); 92 | } 93 | } 94 | } -------------------------------------------------------------------------------- /src/util/Errors.ts: -------------------------------------------------------------------------------- 1 | export class MissingParameter extends TypeError { 2 | constructor(message: string) { 3 | super(`missing "${message}" parameter`); 4 | } 5 | } 6 | 7 | export class EndpointNotExist extends TypeError { 8 | constructor(path: string) { 9 | super(`Endpoint "${path}" does not exist`); 10 | } 11 | } 12 | 13 | export class PremiumNeeded extends Error { 14 | constructor(path: string) { 15 | super(`Premium needed for path: ${path}`); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/util/index.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch'; 2 | import { MissingParameter } from './Errors'; 3 | import { Endpoint } from '../structures/Endpoint'; 4 | 5 | export async function toBuffer(link: string): Promise { 6 | if (!link) throw new MissingParameter('link'); 7 | 8 | const res = await fetch(link); 9 | const buffer = await res.buffer(); 10 | return buffer; 11 | } 12 | 13 | export function loadEndpoints(endpoints: Map) { 14 | // Facts 15 | endpoints.set('/facts/dog', new Endpoint('/facts/dog')); 16 | endpoints.set('/facts/cat', new Endpoint('/facts/cat')); 17 | endpoints.set('/facts/panda', new Endpoint('/facts/panda')); 18 | endpoints.set('/facts/fox', new Endpoint('/facts/birb')); 19 | endpoints.set('/facts/birb', new Endpoint('/facts/birb')); 20 | endpoints.set('/facts/koala', new Endpoint('/facts/koala')); 21 | endpoints.set('/facts/racoon', new Endpoint('/facts/racoon')); 22 | endpoints.set('/facts/kangaroo', new Endpoint('/facts/kangaroo')); 23 | endpoints.set('/facts/elephant', new Endpoint('/facts/elephant')); 24 | endpoints.set('/facts/giraffe', new Endpoint('/facts/giraffe')); 25 | endpoints.set('/facts/whale', new Endpoint('/facts/whale')); 26 | 27 | // Images 28 | endpoints.set('/img/dog', new Endpoint('/img/dog')); 29 | endpoints.set('/img/cat', new Endpoint('/img/cat')); 30 | endpoints.set('/img/panda', new Endpoint('/img/panda')); 31 | endpoints.set('/img/fox', new Endpoint('/img/birb')); 32 | endpoints.set('/img/birb', new Endpoint('/img/birb')); 33 | endpoints.set('/img/koala', new Endpoint('/img/koala')); 34 | endpoints.set('/img/racoon', new Endpoint('/img/racoon')); 35 | endpoints.set('/img/kangaroo', new Endpoint('/img/kangaroo')); 36 | endpoints.set('/img/elephant', new Endpoint('/img/elephant')); 37 | endpoints.set('/img/giraffe', new Endpoint('/img/giraffe')); 38 | endpoints.set('/img/whale', new Endpoint('/img/whale')); 39 | 40 | // Animals 41 | endpoints.set('/animal/dog', new Endpoint('/animal/dog')); 42 | endpoints.set('/animal/cat', new Endpoint('/animal/cat')); 43 | endpoints.set('/animal/panda', new Endpoint('/animal/panda')); 44 | endpoints.set('/animal/fox', new Endpoint('/animal/birb')); 45 | endpoints.set('/animal/birb', new Endpoint('/animal/birb')); 46 | endpoints.set('/animal/koala', new Endpoint('/animal/koala')); 47 | endpoints.set('/animal/racoon', new Endpoint('/animal/racoon')); 48 | endpoints.set('/animal/kangaroo', new Endpoint('/animal/kangaroo')); 49 | endpoints.set('/animal/elephant', new Endpoint('/animal/elephant')); 50 | endpoints.set('/animal/giraffe', new Endpoint('/animal/giraffe')); 51 | endpoints.set('/animal/whale', new Endpoint('/animal/whale')); 52 | 53 | // Gif 54 | endpoints.set('/animu/wink', new Endpoint('/animu/wink')); 55 | endpoints.set('/animu/pat', new Endpoint('/animu/pat')); 56 | endpoints.set('/animu/hug', new Endpoint('/animu/hug')); 57 | 58 | // Canvas 59 | endpoints.set('/canvas/gay', new Endpoint('/canvas/gay', { query: { 60 | avatar: { key: 'avatar', required: true } 61 | }})); 62 | endpoints.set('/canvas/glass', new Endpoint('/canvas/glass', { query: { 63 | avatar: { key: 'avatar', required: true } 64 | }})); 65 | endpoints.set('/canvas/wasted', new Endpoint('/canvas/wasted', { query: { 66 | avatar: { key: 'avatar', required: true } 67 | }})); 68 | endpoints.set('/canvas/triggered', new Endpoint('/canvas/triggered', { query: { 69 | avatar: { key: 'avatar', required: true } 70 | }})); 71 | endpoints.set('/canvas/greyscale', new Endpoint('/canvas/invert', { query: { 72 | avatar: { key: 'avatar', required: true } 73 | }})); 74 | endpoints.set('/canvas/invert', new Endpoint('/canvas/invert', { query: { 75 | avatar: { key: 'avatar', required: true } 76 | }})); 77 | endpoints.set('/canvas/invertgreyscale', new Endpoint('/canvas/invertgreyscale', { query: { 78 | avatar: { key: 'avatar', required: true } 79 | }})); 80 | endpoints.set('/canvas/brightness', new Endpoint('/canvas/brightness', { query: { 81 | avatar: { key: 'avatar', required: true } 82 | }})); 83 | endpoints.set('/canvas/threshold', new Endpoint('/canvas/threshold', { query: { 84 | avatar: { key: 'avatar', required: true } 85 | }})); 86 | endpoints.set('/canvas/sepia', new Endpoint('/canvas/sepia', { query: { 87 | avatar: { key: 'avatar', required: true } 88 | }})); 89 | endpoints.set('/canvas/red', new Endpoint('/canvas/red', { query: { 90 | avatar: { key: 'avatar', required: true } 91 | }})); 92 | endpoints.set('/canvas/green', new Endpoint('/canvas/green', { query: { 93 | avatar: { key: 'avatar', required: true } 94 | }})); 95 | endpoints.set('/canvas/blue', new Endpoint('/canvas/blue', { query: { 96 | avatar: { key: 'avatar', required: true } 97 | }})); 98 | endpoints.set('/canvas/color', new Endpoint('/canvas/color', { query: { 99 | avatar: { key: 'avatar', required: true }, 100 | color: { key: 'color', required: true } 101 | }})); 102 | endpoints.set('/canvas/pixelate', new Endpoint('/canvas/pixelate', { query: { 103 | avatar: { key: 'avatar', required: true } 104 | }})); 105 | endpoints.set('/canvas/youtube-comment', new Endpoint('/canvas/youtube-comment', { query: { 106 | avatar: { key: 'avatar', required: true } 107 | }})); 108 | endpoints.set('/canvas/color-viewer', new Endpoint('/canvas/color-viewer', { query: { 109 | hex: { key: 'hex', required: true } 110 | }})); 111 | endpoints.set('/canvas/hex', new Endpoint('/canvas/hex', { query: { 112 | rgb: { key: 'rgb', required: true } 113 | }})); 114 | endpoints.set('/canvas/rgb', new Endpoint('/canvas/rgb', { query: { 115 | hex: { key: 'hex', required: true } 116 | }})); 117 | 118 | // Other 119 | endpoints.set('/pokedex', new Endpoint('/pokedex', { query: { 120 | pokemon: { key: 'pokemon', required: true } 121 | }})); 122 | endpoints.set('/chatbot', new Endpoint('/chatbot', { cooldown: 4250, query: { 123 | message: { key: 'message', required: true } 124 | }})); 125 | endpoints.set('/mc', new Endpoint('/mc', { query: { 126 | username: { key: 'username', required: true } 127 | }})); 128 | endpoints.set('/lyrics', new Endpoint('/lyrics', { query: { 129 | title: { key: 'title', required: true } 130 | }})); 131 | endpoints.set('/binary', new Endpoint('/binary', { query: { 132 | text: { key: 'text' }, decode: { key: 'decode' } 133 | }})); 134 | endpoints.set('/base64', new Endpoint('/base64', { query: { 135 | encode: { key: 'encode' }, decode: { key: 'decode' } 136 | }})); 137 | endpoints.set('/meme', new Endpoint('/meme')); 138 | endpoints.set('/bottoken', new Endpoint('/bottoken')); 139 | } -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | const { SRAClient } = require('../dist'); 2 | 3 | (async () => { 4 | const start = Date.now(); 5 | const client = new SRAClient(); 6 | let output = await client.fetch('/chatbot', { message: 'Hello' }); 7 | console.log(output); 8 | console.log(Date.now() - start); 9 | })(); -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "./", 4 | "strict": true, 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "target": "es2017", 8 | "pretty": true, 9 | "removeComments": true, 10 | "allowSyntheticDefaultImports": true, 11 | "experimentalDecorators": true, 12 | "emitDecoratorMetadata": true, 13 | "types": ["@types/node", "@types/node-fetch"], 14 | "lib": [ 15 | "esnext", 16 | "esnext.array", 17 | "esnext.asynciterable", 18 | "esnext.intl", 19 | "esnext.symbol" 20 | ], 21 | "sourceRoot": "src", 22 | "outDir": "dist", 23 | "sourceMap": true 24 | }, 25 | "include": [ 26 | "src", "typings" 27 | ], 28 | "exclude": [ 29 | "node_modules", "dist" 30 | ] 31 | } -------------------------------------------------------------------------------- /typings/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from '../src'; 2 | --------------------------------------------------------------------------------