From 5e882111cf55da3ce78019e4ec2322268eb60c5e Mon Sep 17 00:00:00 2001 From: bonartm Date: Tue, 13 Jul 2021 12:56:49 +0200 Subject: [PATCH] add methods to public API --- src/quizdown.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/quizdown.ts b/src/quizdown.ts index 641de9d..e9a95af 100644 --- a/src/quizdown.ts +++ b/src/quizdown.ts @@ -2,10 +2,12 @@ import App from './App.svelte'; import parseQuizdown from './parser.js'; import { Config } from './config.js'; import marked from './customizedMarked.js'; +import type { Quiz } from './quiz'; export interface Quizdown { - register(extension: QuizdownExtension): void; - createApp(rawQuizdown: string, node: Element, config: Config): void; + register(extension: QuizdownExtension): Quizdown; + createApp(rawQuizdown: string, node: Element, config: Config): App; + parseQuizdown(rawQuizdown: string, config: Config): Quiz; init(config: object): void; getMarkedParser(): typeof marked; } @@ -14,12 +16,12 @@ export interface QuizdownExtension { setup(quizdown: Quizdown): void; } -function register(extension: QuizdownExtension) { - extension.setup(this); - return this; +function register(extension: QuizdownExtension): Quizdown { + extension.setup(this as Quizdown); + return this as Quizdown; } -function createApp(rawQuizdown: string, node: Element, config: Config): void { +function createApp(rawQuizdown: string, node: Element, config: Config): App { node.innerHTML = ''; let root: ShadowRoot; if (!!node.shadowRoot) { @@ -31,7 +33,7 @@ function createApp(rawQuizdown: string, node: Element, config: Config): void { } try { let quiz = parseQuizdown(rawQuizdown, config); - new App({ + let app = new App({ // https://github.com/sveltejs/svelte/pull/5870 target: root, intro: false, @@ -39,6 +41,7 @@ function createApp(rawQuizdown: string, node: Element, config: Config): void { quiz: quiz, }, }); + return app; } catch (e) { root.innerHTML = `${e}. App could not render. Please check your quizdown syntax.`; } @@ -69,6 +72,7 @@ function getMarkedParser(): typeof marked { let quizdown: Quizdown = { init, register, + parseQuizdown, createApp, getMarkedParser, };