changing javascript to typescript
This commit is contained in:
parent
08e984b00b
commit
f564e8bffd
13 changed files with 92 additions and 42 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
dist
|
||||
# Packages
|
||||
node_modules/
|
||||
package-lock.json
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
src
|
||||
tsconfig.json
|
||||
# Packages
|
||||
node_modules/
|
||||
package-lock.json
|
||||
|
|
3
index.js
3
index.js
|
@ -1,3 +0,0 @@
|
|||
const APIClient = require("./src/class/apiclient");
|
||||
const random8ball = require("./src/functions/8ball");
|
||||
module.exports = { random8ball, APIClient };
|
12
package.json
12
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"
|
||||
}
|
||||
}
|
||||
|
|
6
src/CODMClient/codmclient.interface.ts
Normal file
6
src/CODMClient/codmclient.interface.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
export interface CODMClientOptions {
|
||||
/**
|
||||
* Authorisation key for the API
|
||||
*/
|
||||
key: string;
|
||||
}
|
|
@ -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<Object>}
|
||||
* @return {Promise<Object>}
|
||||
* @param {String} name
|
||||
*/
|
||||
async getperk(name) {
|
||||
public async getperk(name: string): Promise<object> {
|
||||
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;
|
2
src/CODMClient/index.ts
Normal file
2
src/CODMClient/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
export { CODMClientOptions } from "./codmclient.interface";
|
||||
export { CODMClient } from "./codmclient";
|
|
@ -1,13 +0,0 @@
|
|||
const axios = require("axios");
|
||||
const config = require("../utils/config.json");
|
||||
/**
|
||||
* Sends a 8ball response
|
||||
* @returns {Promise<String>}
|
||||
*/
|
||||
async function random() {
|
||||
const data = await axios
|
||||
.get(`${config.api}/api/v1/fun/8ball`)
|
||||
.then(res => res.data);
|
||||
return data.answer;
|
||||
}
|
||||
module.exports = random;
|
12
src/functions/8ball.ts
Normal file
12
src/functions/8ball.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import axios from "axios";
|
||||
import config from "../utils/config.json";
|
||||
/**
|
||||
* Sends a 8ball response
|
||||
* @return {Promise<String>}
|
||||
*/
|
||||
export async function random8ball(): Promise<string> {
|
||||
const data = await axios
|
||||
.get(`${config.api}/api/v1/fun/8ball`)
|
||||
.then(res => res.data);
|
||||
return data.answer;
|
||||
}
|
2
src/index.d.ts
vendored
Normal file
2
src/index.d.ts
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
export { CODMClient, CODMClientOptions } from "./CODMClient/index";
|
||||
export { random8ball } from "./functions/8ball";
|
20
src/index.js
Normal file
20
src/index.js
Normal file
|
@ -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
|
13
src/typings/index.d.ts
vendored
13
src/typings/index.d.ts
vendored
|
@ -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<String>;
|
||||
public getperk(perk: string): Promise<Object>;
|
||||
public getperk(perk: string): Promise<object>;
|
||||
}
|
||||
export type APIClientOptions = {
|
||||
codm?: string;
|
||||
};
|
||||
export async function random8ball(): Promise<string>;
|
||||
}
|
||||
|
|
20
tsconfig.json
Normal file
20
tsconfig.json
Normal file
|
@ -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"]
|
||||
}
|
Loading…
Reference in a new issue