Skip to content

Commit cb7e9d2

Browse files
authored
Merge pull request #2 from Turtlepaw/main
Change to enums
2 parents f8309fb + e622b34 commit cb7e9d2

24 files changed

+2637
-8763
lines changed

.github/workflows/build.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Build
2+
on: [push, pull_request]
3+
jobs:
4+
test:
5+
name: Build Source
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Checkout repository
9+
uses: actions/checkout@v2
10+
11+
- name: Install node.js v16
12+
uses: actions/setup-node@v2
13+
with:
14+
node-version: 16
15+
cache: 'yarn'
16+
cache-dependency-path: yarn.lock
17+
18+
- name: Install dependencies
19+
run: yarn --immutable
20+
21+
- name: Tests
22+
run: yarn build

.github/workflows/test.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Tests
2+
on: [push, pull_request]
3+
jobs:
4+
test:
5+
name: Run Tests
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Checkout repository
9+
uses: actions/checkout@v2
10+
11+
- name: Install node.js v16
12+
uses: actions/setup-node@v2
13+
with:
14+
node-version: 16
15+
cache: 'yarn'
16+
cache-dependency-path: yarn.lock
17+
18+
- name: Install dependencies
19+
run: yarn --immutable
20+
21+
- name: Tests
22+
run: yarn dev

dist/src/Classes/Category.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ var Category = /** @class */ (function () {
117117
* @static
118118
*/
119119
Category.isNameResolvable = function (arg) {
120-
var _a, _b;
120+
var _a;
121121
var completeNameList = __spreadArray(__spreadArray([], Object.keys(this.allPrettyNames), true), Object.keys(this.allNames), true).filter(function (str) { return isNaN(str); })
122122
.map(function (str) { return str.toLowerCase(); });
123-
return completeNameList.includes((_b = (_a = arg) === null || _a === void 0 ? void 0 : _a.toLowerCase) === null || _b === void 0 ? void 0 : _b.call(_a));
123+
return completeNameList.includes((_a = arg === null || arg === void 0 ? void 0 : arg.toLowerCase) === null || _a === void 0 ? void 0 : _a.call(arg));
124124
};
125125
/**
126126
* Converts a category's pretty name into it's strict version
@@ -150,7 +150,7 @@ var Category = /** @class */ (function () {
150150
* @static
151151
*/
152152
Category.random = function (type) {
153-
if (type === void 0) { type = "ID"; }
153+
if (type === void 0) { type = enums_1.CategoryType.Id; }
154154
var names = Object.keys(this.allPrettyNames).filter(function (val) {
155155
return isNaN(+val);
156156
});

dist/src/Classes/Category.test.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
var enums_1 = require("../Typings/enums");
34
var Category_1 = require("./Category");
45
function createInstance(arg) {
56
return new Category_1.default(arg);
@@ -94,9 +95,9 @@ test("Test outputs of Category.strictToPrettyName()", function () {
9495
expect(Category_1.default.strictToPrettyName("text")).toBe(null);
9596
expect(Category_1.default.strictToPrettyName(true)).toBe(null);
9697
expect(Category_1.default.strictToPrettyName("General Knowledge")).toBe(null);
97-
expect(Category_1.default.strictToPrettyName("GENERAL_KNOWLEDGE")).toBe("General Knowledge");
98+
expect(Category_1.default.strictToPrettyName("GeneralKnowledge")).toBe("General Knowledge");
9899
expect(Category_1.default.strictToPrettyName("Entertainment: Cartoon and Animations")).toBe(null);
99-
expect(Category_1.default.strictToPrettyName("ENTERTAINMENT_CARTOON_AND_ANIMATIONS")).toBe("Entertainment: Cartoon and Animations");
100+
expect(Category_1.default.strictToPrettyName("EntertainmentCartoonAndAnimations")).toBe("Entertainment: Cartoon and Animations");
100101
});
101102
test("Tests outputs for Category.random()", function () {
102103
expect(Category_1.default.random(1)).toBeGreaterThanOrEqual(9);
@@ -105,9 +106,9 @@ test("Tests outputs for Category.random()", function () {
105106
expect(Category_1.default.random({})).toBeLessThanOrEqual(32);
106107
expect(Category_1.default.random(true)).toBeGreaterThanOrEqual(9);
107108
expect(Category_1.default.random(true)).toBeLessThanOrEqual(32);
108-
expect(Category_1.default.random("ID")).toBeGreaterThanOrEqual(9);
109-
expect(Category_1.default.random("ID")).toBeLessThanOrEqual(32);
110-
expect(typeof Category_1.default.random("NAME")).toBe("string");
109+
expect(Category_1.default.random(enums_1.CategoryType.Id)).toBeGreaterThanOrEqual(9);
110+
expect(Category_1.default.random(enums_1.CategoryType.Id)).toBeLessThanOrEqual(32);
111+
expect(typeof Category_1.default.random(enums_1.CategoryType.Name)).toBe("string");
111112
});
112113
test("Tests outputs for Category.resolve()", function () {
113114
expect(Category_1.default.resolve(8)).toBe(null);

dist/src/Classes/Validator.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import { QuestionDifficulties, QuestionEncodings, QuestionTypes } from "../Typings/enums";
12
import { QuestionOptions } from "../Typings/interfaces";
2-
import { QuestionDifficulty } from "../Typings/types";
33
export default class Validator {
44
private readonly options;
55
constructor(options: QuestionOptions);
66
checkAmount(): number | null;
77
checkCategory(): number | null;
8-
checkDifficulty(): QuestionDifficulty | null;
9-
checkEncode(): "none" | "base64" | "url3986" | "urlLegacy" | null;
8+
checkDifficulty(): QuestionDifficulties | null;
9+
checkEncode(): QuestionEncodings | null;
1010
checkToken(): string | null;
11-
checkType(): "boolean" | "multiple" | null;
11+
checkType(): QuestionTypes | null;
1212
static _checkCategory(category: unknown): number | null;
1313
}

dist/src/Classes/Validator.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ var Validator = /** @class */ (function () {
8383
if (typeof difficulty != "string") {
8484
throw new CustomErrors_1.OpenTDBError("'difficulty' option for QuestionOptions must be of type string, received ".concat(typeof difficulty), CustomErrors_1.OpenTDBError.errors.headers.INVALID_OPT);
8585
}
86-
var values = ["easy", "medium", "hard"];
86+
var values = [
87+
enums_1.QuestionDifficulties.Easy,
88+
enums_1.QuestionDifficulties.Medium,
89+
enums_1.QuestionDifficulties.Hard
90+
];
8791
if (!values.includes(difficulty)) {
8892
throw new CustomErrors_1.OpenTDBError("'difficulty' option (\"".concat(difficulty, "\") for QuestionOptions does not resolve into a question difficulty"), CustomErrors_1.OpenTDBError.errors.headers.INVALID_OPT);
8993
}
@@ -97,10 +101,10 @@ var Validator = /** @class */ (function () {
97101
throw new CustomErrors_1.OpenTDBError("'encode' option for QuestionOptions must be of type string, received ".concat(typeof encode), CustomErrors_1.OpenTDBError.errors.headers.INVALID_OPT);
98102
}
99103
var values = [
100-
"base64",
101-
"none",
102-
"url3986",
103-
"urlLegacy",
104+
enums_1.QuestionEncodings.UrlLegacy,
105+
enums_1.QuestionEncodings.Url3986,
106+
enums_1.QuestionEncodings.Base64,
107+
enums_1.QuestionEncodings.None
104108
];
105109
if (!values.includes(encode)) {
106110
throw new CustomErrors_1.OpenTDBError("'encode' option (\"".concat(encode, "\") for QuestionOptions does not resolve into a question encode"), CustomErrors_1.OpenTDBError.errors.headers.INVALID_OPT);
@@ -126,7 +130,10 @@ var Validator = /** @class */ (function () {
126130
if (typeof type != "string") {
127131
throw new CustomErrors_1.OpenTDBError("'type' option for QuestionOptions must be of type string, received ".concat(typeof type), CustomErrors_1.OpenTDBError.errors.headers.INVALID_OPT);
128132
}
129-
var values = ["boolean", "multiple"];
133+
var values = [
134+
enums_1.QuestionTypes.Boolean,
135+
enums_1.QuestionTypes.Multiple
136+
];
130137
if (!values.includes(type)) {
131138
throw new CustomErrors_1.OpenTDBError("'type' option (\"".concat(type, "\") for QuestionOptions does not resolve into a question type"), CustomErrors_1.OpenTDBError.errors.headers.INVALID_OPT);
132139
}

dist/src/Classes/Validator.test.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
//@ts-nocheck
4+
var enums_1 = require("../Typings/enums");
35
var Validator_1 = require("./Validator");
46
function createInstance(options) {
57
return new Validator_1.default(options);
@@ -105,8 +107,8 @@ test("tests output of Validator.checkDifficulty()", function () {
105107
expect(function () {
106108
validator.checkDifficulty();
107109
}).toThrow(TypeError);
108-
validator = createInstance({ difficulty: "easy" });
109-
expect(validator.checkDifficulty()).toEqual("easy");
110+
validator = createInstance({ difficulty: enums_1.QuestionDifficulties.Easy });
111+
expect(validator.checkDifficulty()).toEqual(enums_1.QuestionDifficulties.Easy);
110112
validator = createInstance({ difficulty: undefined });
111113
expect(validator.checkDifficulty()).toEqual(null);
112114
validator = createInstance({ difficulty: null });
@@ -141,8 +143,8 @@ test("tests output of Validator.checkEncoding()", function () {
141143
expect(function () {
142144
validator.checkEncode();
143145
}).toThrow(TypeError);
144-
validator = createInstance({ encode: "base64" });
145-
expect(validator.checkEncode()).toEqual("base64");
146+
validator = createInstance({ encode: enums_1.QuestionEncodings.Base64 });
147+
expect(validator.checkEncode()).toEqual(enums_1.QuestionEncodings.Base64);
146148
validator = createInstance({ encode: undefined });
147149
expect(validator.checkEncode()).toEqual(null);
148150
validator = createInstance({ encode: null });
@@ -201,8 +203,8 @@ test("tests output of Validator.checkType()", function () {
201203
expect(function () {
202204
validator.checkType();
203205
}).toThrow(TypeError);
204-
validator = createInstance({ type: "boolean" });
205-
expect(validator.checkType()).toEqual("boolean");
206+
validator = createInstance({ type: enums_1.QuestionTypes.Boolean });
207+
expect(validator.checkType()).toEqual(enums_1.QuestionTypes.Boolean);
206208
validator = createInstance({ type: undefined });
207209
expect(validator.checkType()).toEqual(null);
208210
validator = createInstance({ type: null });

dist/src/Functions/getQuestions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function getQuestions(options) {
6666
link = OpenTDBUtil_1.default.links.base.GET_QUESTIONS;
6767
defaultOptions = {
6868
amount: 10,
69-
encode: enums_1.QuestionEncodings.none,
69+
encode: enums_1.QuestionEncodings.None,
7070
};
7171
if ((options === null || options === void 0 ? void 0 : options.category) instanceof Category_1.default)
7272
options.category = options.category.id;

dist/src/Typings/enums.d.ts

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@
33
* @enum
44
*/
55
export declare enum CategoryNamesStrict {
6-
GENERAL_KNOWLEDGE = 9,
7-
ENTERTAINMENT_BOOKS = 10,
8-
ENTERTAINMENT_FILM = 11,
9-
ENTERTAINMENT_MUSIC = 12,
10-
ENTERTAINMENT_MUSICALS_AND_THEATRES = 13,
11-
ENTERTAINMENT_TELEVISION = 14,
12-
ENTERTAINMENT_VIDEO_GAMES = 15,
13-
ENTERTAINMENT_BOARD_GAMES = 16,
14-
SCIENCE_AND_NATURE = 17,
15-
SCIENCE_COMPUTERS = 18,
16-
SCIENCE_MATHEMATICS = 19,
17-
MYTHOLOGY = 20,
18-
SPORTS = 21,
19-
GEOGRAPHY = 22,
20-
HISTORY = 23,
21-
POLITICS = 24,
22-
ART = 25,
23-
CELEBRITIES = 26,
24-
ANIMALS = 27,
25-
VEHICLES = 28,
26-
ENTERTAINMENT_COMICS = 29,
27-
SCIENCE_GADGETS = 30,
28-
ENTERTAINMENT_JAPANESE_ANIME_AND_MANGA = 31,
29-
ENTERTAINMENT_CARTOON_AND_ANIMATIONS = 32
6+
GeneralKnowledge = 9,
7+
EntertainmentBooks = 10,
8+
EntertainmentFilm = 11,
9+
EntertainmentMusic = 12,
10+
EntertainmentMusicalsAndTheatres = 13,
11+
EntertainmentJapaneseAnimeAndManga = 14,
12+
EntertainmentCartoonAndAnimations = 15,
13+
EntertainmentTelevision = 16,
14+
EntertainmentVideoGames = 17,
15+
EntertainmentBoardGames = 18,
16+
EntertainmentComics = 19,
17+
ScienceAndNature = 20,
18+
ScienceComputers = 21,
19+
ScienceMathmatics = 22,
20+
ScienceGadgets = 23,
21+
Mythology = 24,
22+
Sports = 25,
23+
Geography = 26,
24+
History = 27,
25+
Politics = 28,
26+
Art = 29,
27+
Celebrities = 30,
28+
Animals = 31,
29+
Vehicles = 32
3030
}
3131
/**
3232
* All pretty category names mapped to their API id
@@ -79,27 +79,27 @@ export declare enum QuestionAmountRange {
7979
* @enum
8080
*/
8181
export declare enum QuestionDifficulties {
82-
easy = "easy",
83-
medium = "medium",
84-
hard = "hard"
82+
Easy = "easy",
83+
Medium = "medium",
84+
Hard = "hard"
8585
}
8686
/**
8787
* The question types mapped to their API value
8888
* @enum
8989
*/
9090
export declare enum QuestionTypes {
91-
multiple = "multiple",
92-
boolean = "boolean"
91+
Multiple = "multiple",
92+
Boolean = "boolean"
9393
}
9494
/**
9595
* The question encodings mapped to their API value
9696
* @enum
9797
*/
9898
export declare enum QuestionEncodings {
99-
base64 = "base64",
100-
none = "none",
101-
url3986 = "url3986",
102-
urlLegacy = "urlLegacy"
99+
Base64 = "base64",
100+
None = "none",
101+
Url3986 = "url3986",
102+
UrlLegacy = "urlLegacy"
103103
}
104104
/**
105105
* The types of Category versions
@@ -109,3 +109,7 @@ export declare enum QuestionVersions {
109109
Raw = 0,
110110
Final = 1
111111
}
112+
export declare enum CategoryType {
113+
Id = "ID",
114+
Name = "NAME"
115+
}

0 commit comments

Comments
 (0)