testownik-converter 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ name: Publish to npm registry
2
+
3
+ permissions:
4
+ id-token: write # Required for OIDC
5
+ contents: read
6
+
7
+ on:
8
+ push:
9
+ branches: ["main"]
10
+ workflow_dispatch:
11
+
12
+ jobs:
13
+ publish:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: actions/setup-node@v4
18
+ with:
19
+ node-version: 22
20
+ registry-url: https://registry.npmjs.org/
21
+ - uses: pnpm/action-setup@v4
22
+ - run: pnpm install --frozen-lockfile
23
+ - run: pnpm run build
24
+ - run: npm install --global npm@latest
25
+ - run: npm publish --provenance
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Konrad Guzek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Testownik Converter
2
+
3
+ This is a command-line utility for converting text-base single-choice or multiple-choice quizzes into the JSON format used by [Testownik](https://testownik.solvro.pl).
4
+
5
+ ## Adapters
6
+
7
+ Currently, the only supported adapter is for converting quizzes exported from CCNA exams.
8
+
9
+ ### CCNA
10
+
11
+ Invoke this adapter by running:
12
+
13
+ ```sh
14
+ npx testownik-converter ccna <filename>
15
+ ```
16
+
17
+ ## Options
18
+
19
+ For a list of globally-available command-line options, run the command without arguments.
20
+
21
+ ```sh
22
+ npx testownik-converter
23
+ ```
24
+
25
+ For more information about adapter-specific options, use the `help` command:
26
+
27
+ ```sh
28
+ npx testowink-converter help ccna
29
+ ```
30
+
31
+ ## Copyright
32
+
33
+ Copyright © 2026 Konrad Guzek
34
+
35
+ This file, along with all other source code files found in this repository, is a part of the Testownik Converter project, licensed under the [MIT license](./LICENSE).
36
+
37
+ This tool is not affiliated with, endorsed by, or sponsored by Cisco Systems, Inc. Cisco® is a registered trademark of Cisco Systems, Inc.
38
+
39
+ It is also not endorsed neither by Testownik nor by KN Solvro, although you should [check out their projects](https://solvro.pwr.edu.pl)!
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "testownik-converter",
3
+ "version": "1.0.0",
4
+ "description": "A command-line utility to convert quizzes into Solvro's Testownik format.",
5
+ "type": "module",
6
+ "author": "Konrad Guzek",
7
+ "license": "MIT",
8
+ "homepage": "https://github.com/kguzek/testownik-converter#readme",
9
+ "bugs": {
10
+ "url": "https://github.com/kguzek/testownik-converter/issues"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/kguzek/testownik-converter.git"
15
+ },
16
+ "bin": {
17
+ "testownik-converter": "node dist/index.js"
18
+ },
19
+ "dependencies": {
20
+ "commander": "^14.0.3"
21
+ },
22
+ "devDependencies": {
23
+ "@types/node": "^25.2.0",
24
+ "tsup": "^8.5.1",
25
+ "typescript": "^5.9.3"
26
+ },
27
+ "scripts": {
28
+ "build": "tsup"
29
+ }
30
+ }
@@ -0,0 +1,34 @@
1
+ import type { AdapterOptions, TestownikQuestion, TestownikQuiz } from "@/types";
2
+ import { readFileSync, writeFileSync } from "node:fs";
3
+
4
+ export abstract class BaseAdapter {
5
+ protected inputContent!: string;
6
+ protected options!: AdapterOptions;
7
+
8
+ constructor(options: AdapterOptions) {
9
+ const content = readFileSync(options.inputFilename, "utf8");
10
+
11
+ this.inputContent = content;
12
+ this.options = options;
13
+ }
14
+
15
+ protected abstract convertQuestions(): TestownikQuestion[];
16
+
17
+ private createQuiz(): TestownikQuiz {
18
+ const questions = this.convertQuestions();
19
+ const quiz: TestownikQuiz = {
20
+ title: this.options.quizTitle,
21
+ ...(this.options.quizDescription == null
22
+ ? {}
23
+ : { description: this.options.quizDescription }),
24
+ questions,
25
+ };
26
+ return quiz;
27
+ }
28
+
29
+ writeOutput(): void {
30
+ const quiz = this.createQuiz();
31
+ const data = JSON.stringify(quiz, null, 2);
32
+ writeFileSync(this.options.outputFilename, data, "utf8");
33
+ }
34
+ }
@@ -0,0 +1,54 @@
1
+ import { BaseAdapter } from "./base-adapter";
2
+ import type { TestownikQuestion, TestownikAnswer } from "@/types";
3
+
4
+ const QUESTION_REGEX = new RegExp(
5
+ String.raw`^(?:(?<number>\d+)\.\s+)?(?<question>.+)$\n(?<answers>(?:(?=^-\s).+$\n?)+\n?)`,
6
+ "gm",
7
+ );
8
+
9
+ const ANSWER_REGEX = new RegExp(
10
+ String.raw`^- (?<correct>\[✓\] )?(?<question>.+)$`,
11
+ "gm",
12
+ );
13
+
14
+ export class CcnaAdapter extends BaseAdapter {
15
+ convertQuestions() {
16
+ QUESTION_REGEX.lastIndex = 0;
17
+ const questions: TestownikQuestion[] = [];
18
+ let questionMatch: RegExpExecArray | null;
19
+ while (
20
+ (questionMatch = QUESTION_REGEX.exec(this.inputContent)) != null &&
21
+ questionMatch.groups != null
22
+ ) {
23
+ const answers: TestownikAnswer[] = [];
24
+ ANSWER_REGEX.lastIndex = 0;
25
+
26
+ const rawAnswers = questionMatch.groups.answers;
27
+ let answerMatch: RegExpExecArray | null;
28
+ while (
29
+ (answerMatch = ANSWER_REGEX.exec(rawAnswers)) != null &&
30
+ answerMatch.groups != null
31
+ ) {
32
+ const answer: TestownikAnswer = {
33
+ text: answerMatch.groups.question,
34
+ is_correct: answerMatch.groups.correct != null,
35
+ };
36
+ answers.push(answer);
37
+ }
38
+ if (answers.length === 0) {
39
+ continue;
40
+ }
41
+ const question: TestownikQuestion = {
42
+ text: questionMatch.groups.question,
43
+ answers,
44
+ multiple: answers.filter((answer) => answer.is_correct).length > 1,
45
+ };
46
+ if (questionMatch.groups.number != null) {
47
+ question.order = Number(questionMatch.groups.number);
48
+ }
49
+ questions.push(question);
50
+ }
51
+
52
+ return questions;
53
+ }
54
+ }
@@ -0,0 +1,42 @@
1
+ import { Command } from "commander";
2
+ import { CcnaAdapter } from "@/adapters/ccna-adapter";
3
+ import { REPO_NAME, REPO_URL } from "@/constants";
4
+
5
+ const program = new Command();
6
+ program
7
+ .name("testownik-converter")
8
+ .description(
9
+ "A command-line converter of quizzes into KN Solvro's Testownik format.",
10
+ )
11
+ .option("-t, --title <string>", "quiz title", "Testownik Quiz")
12
+ .option(
13
+ "-d, --description <string>",
14
+ "quiz description",
15
+ `Generated by ${REPO_NAME}: ${REPO_URL}`,
16
+ )
17
+ .option("-o, --output <filename>", "output JSON filename", "testownik.json")
18
+ .version("1.0.0");
19
+
20
+ program
21
+ .command("ccna")
22
+ .argument("<filename>", "input text filename")
23
+ .description("Parses questions from Cisco's CCNA exam format.")
24
+ .action((inputFilename: string) => {
25
+ const options = program.opts();
26
+
27
+ const outputFilename: string = options.output;
28
+ const quizTitle: string = options.title;
29
+ const quizDescription: string | undefined = options.description;
30
+
31
+ const adapter = new CcnaAdapter({
32
+ inputFilename,
33
+ outputFilename,
34
+ quizTitle,
35
+ quizDescription,
36
+ });
37
+
38
+ adapter.writeOutput();
39
+ console.log(`Quiz written to ${options.output}!`);
40
+ });
41
+
42
+ program.parse(process.argv);
@@ -0,0 +1,5 @@
1
+ export const REPO_NAME = "testownik-converter";
2
+
3
+ export const AUTHOR_URL = "https://github.com/kguzek";
4
+
5
+ export const REPO_URL = `${AUTHOR_URL}/${REPO_NAME}`;
@@ -0,0 +1,6 @@
1
+ export interface AdapterOptions {
2
+ inputFilename: string;
3
+ outputFilename: string;
4
+ quizTitle: string;
5
+ quizDescription?: string;
6
+ }
@@ -0,0 +1,3 @@
1
+ export type { AdapterOptions } from "./adapters";
2
+
3
+ export type { TestownikQuiz, TestownikQuestion } from "./testownik";
@@ -0,0 +1,21 @@
1
+ interface QuizPart {
2
+ text: string;
3
+ order?: number;
4
+ image_url?: string;
5
+ }
6
+
7
+ interface TestownikAnswer extends QuizPart {
8
+ is_correct: boolean;
9
+ }
10
+
11
+ export interface TestownikQuestion extends QuizPart {
12
+ answers: TestownikAnswer[];
13
+ multiple?: boolean; // default: false
14
+ explanation?: string | null;
15
+ }
16
+
17
+ export interface TestownikQuiz {
18
+ title: string;
19
+ description?: string;
20
+ questions: TestownikQuestion[];
21
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ // Visit https://aka.ms/tsconfig to read more about this file
3
+ "compilerOptions": {
4
+ // File Layout
5
+ "rootDir": "./src",
6
+ "outDir": "./dist",
7
+
8
+ // Environment Settings
9
+ // See also https://aka.ms/tsconfig/module
10
+ "module": "esnext",
11
+ "target": "esnext",
12
+ "lib": ["esnext"],
13
+ "types": ["node"],
14
+ "moduleResolution": "bundler",
15
+
16
+ // Other Outputs
17
+ "sourceMap": true,
18
+ "declaration": true,
19
+ "declarationMap": true,
20
+
21
+ // Stricter Typechecking Options
22
+ "noUncheckedIndexedAccess": true,
23
+ "exactOptionalPropertyTypes": true,
24
+
25
+ // Style Options
26
+ // "noImplicitReturns": true,
27
+ // "noImplicitOverride": true,
28
+ // "noUnusedLocals": true,
29
+ // "noUnusedParameters": true,
30
+ // "noFallthroughCasesInSwitch": true,
31
+ // "noPropertyAccessFromIndexSignature": true,
32
+
33
+ // Recommended Options
34
+ "strict": true,
35
+ "jsx": "react-jsx",
36
+ "verbatimModuleSyntax": true,
37
+ "isolatedModules": true,
38
+ "noUncheckedSideEffectImports": true,
39
+ "moduleDetection": "force",
40
+ "skipLibCheck": true,
41
+
42
+ "paths": {
43
+ "@/*": ["./src/*"]
44
+ },
45
+ }
46
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { defineConfig } from "tsup";
2
+
3
+ export default defineConfig([
4
+ {
5
+ entry: ["src/cli/index.ts"],
6
+ clean: true,
7
+ shims: true,
8
+ format: "esm",
9
+ splitting: false,
10
+ sourcemap: true,
11
+ outDir: "dist",
12
+ },
13
+ ]);