UNPKG

@trivia-api/models

Version:

Models for The Trivia API.

33 lines (32 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isQuestion = void 0; const index_1 = require("../../index"); /** * Type guard to check that argument is assignable to PublicQuestion * @param arg * @returns */ const isQuestion = (arg) => { if (typeof arg === "object" && arg !== null) { if (["category", "correctAnswer"].every((key) => Object.keys(arg).includes(key))) { if ((0, index_1.isQuestionCategory)(arg.category)) { if (typeof arg.correctAnswer === "string") { if (Array.isArray(arg.incorrectAnswers) && arg.incorrectAnswers.every((a) => typeof a === "string")) { if (typeof arg.question === "string") { if (Array.isArray(arg.tags) && arg.tags.every((a) => typeof a === "string")) { if (arg.type === "Multiple Choice") { return true; } } } } } } } } return false; }; exports.isQuestion = isQuestion;