diff --git a/.gitignore b/.gitignore index a3bfa41..72a0daa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +dist # Packages node_modules/ package-lock.json diff --git a/.npmignore b/.npmignore index a3bfa41..7942ef7 100644 --- a/.npmignore +++ b/.npmignore @@ -1,3 +1,5 @@ +src +tsconfig.json # Packages node_modules/ package-lock.json diff --git a/index.js b/index.js deleted file mode 100644 index f5518cf..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -const APIClient = require("./src/class/apiclient"); -const random8ball = require("./src/functions/8ball"); -module.exports = { random8ball, APIClient }; diff --git a/package.json b/package.json index df66bea..5418a30 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,13 @@ { - "name": "cath", + "name": "cath.js", "version": "1.1.0", "description": "A powerful package that can interact with Cath API", - "main": "index.js", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "dev": "nodemon .", + "build": "tsc", "start": "node .", "node-update": "npm i --save-dev node@16 && npm config set prefix=$(pwd)/node_modules/node && export PATH=$(pwd)/node_modules/node/bin:$PATH", "node-clean": "rm -rf node_modules && rm package-lock.json && npm cache clear --force && npm cache clean --force && npm i", @@ -34,5 +36,11 @@ "dependencies": { "axios": "^0.21.4", "discord.js": "^13.1.0" + }, + "devDependencies": { + "@types/jsdom": "^16.2.13", + "ts-node": "^10.2.1", + "typedoc": "^0.21.9", + "typescript": "^4.4.3" } } diff --git a/src/CODMClient/codmclient.interface.ts b/src/CODMClient/codmclient.interface.ts new file mode 100644 index 0000000..ecff099 --- /dev/null +++ b/src/CODMClient/codmclient.interface.ts @@ -0,0 +1,6 @@ +export interface CODMClientOptions { + /** + * Authorisation key for the API + */ + key: string; +} diff --git a/src/class/apiclient.js b/src/CODMClient/codmclient.ts similarity index 50% rename from src/class/apiclient.js rename to src/CODMClient/codmclient.ts index 006c734..0233c91 100644 --- a/src/class/apiclient.js +++ b/src/CODMClient/codmclient.ts @@ -1,26 +1,23 @@ -const axios = require("axios"); -const config = require("../utils/config.json"); +import axios from "axios"; +import config from "../utils/config.json"; +import { CODMClientOptions } from "./codmclient.interface"; /** - * @class APIClient - **/ -class APIClient { - /** - * @name APIClient - * @kind constructor - * @param {String} key Authorization Key for API (Only for CODM commands) - * @param {String} [options.key] - */ - constructor(key, options = {}) { + * @name APIClient + * @kind constructor + * @param {String} key Authorization Key for API (Only for CODM commands) + */ +export class CODMClient { + public key: CODMClientOptions; + constructor(key: CODMClientOptions) { if (key && typeof key !== "string") throw new TypeError("API key must be a string"); - if (key) this.key = key; } /** * Sends a CODM perk object - * @returns {Promise} + * @return {Promise} * @param {String} name */ - async getperk(name) { + public async getperk(name: string): Promise { const data = await axios .get(`${config.api}/api/v1/codm/perks?name=${name}`, { headers: { @@ -32,4 +29,3 @@ class APIClient { return data; } } -module.exports = APIClient; diff --git a/src/CODMClient/index.ts b/src/CODMClient/index.ts new file mode 100644 index 0000000..ee6a90e --- /dev/null +++ b/src/CODMClient/index.ts @@ -0,0 +1,2 @@ +export { CODMClientOptions } from "./codmclient.interface"; +export { CODMClient } from "./codmclient"; diff --git a/src/functions/8ball.js b/src/functions/8ball.js deleted file mode 100644 index 6e4b21f..0000000 --- a/src/functions/8ball.js +++ /dev/null @@ -1,13 +0,0 @@ -const axios = require("axios"); -const config = require("../utils/config.json"); -/** - * Sends a 8ball response - * @returns {Promise} - */ -async function random() { - const data = await axios - .get(`${config.api}/api/v1/fun/8ball`) - .then(res => res.data); - return data.answer; -} -module.exports = random; diff --git a/src/functions/8ball.ts b/src/functions/8ball.ts new file mode 100644 index 0000000..b92c617 --- /dev/null +++ b/src/functions/8ball.ts @@ -0,0 +1,12 @@ +import axios from "axios"; +import config from "../utils/config.json"; +/** + * Sends a 8ball response + * @return {Promise} + */ +export async function random8ball(): Promise { + const data = await axios + .get(`${config.api}/api/v1/fun/8ball`) + .then(res => res.data); + return data.answer; +} diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..fdd8581 --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,2 @@ +export { CODMClient, CODMClientOptions } from "./CODMClient/index"; +export { random8ball } from "./functions/8ball"; diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..28dba65 --- /dev/null +++ b/src/index.js @@ -0,0 +1,20 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.CODMClient = void 0; +// CODMClient +var codmclient_1 = require("./CODMClient/index"); +Object.defineProperty(exports, "CODMClient", { + enumerable: true, + get: function () { + return codmclient_1.CODMClient; + }, +}); +// functions +var _8ball_1 = require("./functions/8ball"); +Object.defineProperty(exports, "random8ball", { + enumerable: true, + get: function () { + return _8ball_1.random8ball; + }, +}); +//# sourceMappingURL=index.js.map diff --git a/src/typings/index.d.ts b/src/typings/index.d.ts index 17830a9..c74de91 100644 --- a/src/typings/index.d.ts +++ b/src/typings/index.d.ts @@ -1,14 +1,11 @@ +import { CODMClientOptions } from "../CODMClient"; declare module "cath" { - export class APIClient { - public constructor(key: string, options?: APIClientOptions); + export class CODMClient { + public constructor(key: CODMClientOptions); private key: string; - public options?: APIClientOptions; - public random8ball(): Promise; - public getperk(perk: string): Promise; + public getperk(perk: string): Promise; } - export type APIClientOptions = { - codm?: string; - }; + export async function random8ball(): Promise; } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..721ee0e --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "lib": ["ESNext"], + "module": "commonjs", + "moduleResolution": "node", + "target": "ESNext", + "declaration": true, + "outDir": "dist", + "sourceMap": true, + "esModuleInterop": true, + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "allowSyntheticDefaultImports": true, + "skipLibCheck": true, + "skipDefaultLibCheck": true, + "resolveJsonModule": true + }, + "include": ["./src"], + "exclude": ["./node_modules"] +}