diff --git a/types/kotobee/.npmignore b/types/kotobee/.npmignore new file mode 100644 index 00000000000000..93e307400a5456 --- /dev/null +++ b/types/kotobee/.npmignore @@ -0,0 +1,5 @@ +* +!**/*.d.ts +!**/*.d.cts +!**/*.d.mts +!**/*.d.*.ts diff --git a/types/kotobee/index.d.ts b/types/kotobee/index.d.ts new file mode 100644 index 00000000000000..fe6c4e19493a13 --- /dev/null +++ b/types/kotobee/index.d.ts @@ -0,0 +1,55 @@ +type LanguageCode = + | "ar" + | "de" + | "es" + | "hu" + | "jp" + | "ms" + | "no" + | "pt" + | "ru" + | "tr" + | "zh-tw" + | "cy" + | "en" + | "fr" + | "it" + | "ko" + | "nl" + | "pl" + | "ro" + | "sw" + | "zh-cn" + | "zh"; + +type Directions = "ltr" | "rtl"; + +interface KotobeeReader { + /** + * Clears cached local data used by the reader. + */ + clearCache: () => void; + + /** + * Clears all event listeners attached by the reader. + */ + clearListeners: () => void; + + /** + * Clears remotely fetched data (e.g., cloud sync, remote storage). + */ + clearRemoteData: () => void; + + /** + * Sets the active UI language of the reader. + */ + setLanguage: (language: LanguageCode) => void; + + /** + * Sets reading direction (left-to-right or right-to-left). + */ + setDirection: (direction: Directions) => void; +} + +// Declare the global variable +declare const Kotobee: KotobeeReader; diff --git a/types/kotobee/kotobee-tests.ts b/types/kotobee/kotobee-tests.ts new file mode 100644 index 00000000000000..872382f6ae5a35 --- /dev/null +++ b/types/kotobee/kotobee-tests.ts @@ -0,0 +1,68 @@ +// ------------------- Correct usage ------------------- +const validLanguages: LanguageCode[] = [ + "ar", + "de", + "es", + "hu", + "jp", + "ms", + "no", + "pt", + "ru", + "tr", + "zh-tw", + "cy", + "en", + "fr", + "it", + "ko", + "nl", + "pl", + "ro", + "sw", + "zh-cn", + "zh", +]; + +const validDirections: Directions[] = ["ltr", "rtl"]; + +// Test all valid languages +validLanguages.forEach(lang => Kotobee.setLanguage(lang)); + +// Test all valid directions +validDirections.forEach(dir => Kotobee.setDirection(dir)); + +// ------------------- Incorrect usage ------------------- + +// Invalid language +// @ts-expect-error +Kotobee.setLanguage("invalid"); + +// Invalid direction +// @ts-expect-error +Kotobee.setDirection("up"); + +// Calling clearCache with parameters should error +// @ts-expect-error +Kotobee.clearCache(123); + +// Calling clearListeners with parameters should error +// @ts-expect-error +Kotobee.clearListeners("test"); + +// ------------------- Type assignments ------------------- + +// Assign valid types +validLanguages.forEach(lang => { + const l: LanguageCode = lang; // $ExpectType LanguageCode +}); + +validDirections.forEach(dir => { + const d: Directions = dir; // $ExpectType Directions +}); + +// Invalid assignments +// @ts-expect-error +const fakeLang: LanguageCode = "madeup"; +// @ts-expect-error +const dirCenter: Directions = "center"; diff --git a/types/kotobee/package.json b/types/kotobee/package.json new file mode 100644 index 00000000000000..683be6ab37deef --- /dev/null +++ b/types/kotobee/package.json @@ -0,0 +1,19 @@ +{ + "private": true, + "name": "@types/kotobee", + "nonNpm": true, + "nonNpmDescription": "This is an SDK for Kotobee Author application.", + "version": "0.0.9999", + "projects": [ + "https://support.kotobee.com/en/support/solutions/folders/8000082574" + ], + "devDependencies": { + "@types/kotobee": "workspace:." + }, + "owners": [ + { + "name": "Bashamega", + "githubUsername": "Bashamega" + } + ] +} diff --git a/types/kotobee/tsconfig.json b/types/kotobee/tsconfig.json new file mode 100644 index 00000000000000..745356d063ff64 --- /dev/null +++ b/types/kotobee/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "node16", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "kotobee-tests.ts" + ] +} diff --git a/types/markdown-it-container/.npmignore b/types/markdown-it-container/.npmignore index 93e307400a5456..d73cba2e3a91b8 100644 --- a/types/markdown-it-container/.npmignore +++ b/types/markdown-it-container/.npmignore @@ -3,3 +3,4 @@ !**/*.d.cts !**/*.d.mts !**/*.d.*.ts +/v2/ diff --git a/types/markdown-it-container/index.d.mts b/types/markdown-it-container/index.d.mts new file mode 100644 index 00000000000000..6fd766a7d08364 --- /dev/null +++ b/types/markdown-it-container/index.d.mts @@ -0,0 +1,5 @@ +import MarkdownItContainer = require("./index.js"); + +export type ContainerOpts = MarkdownItContainer.ContainerOpts; + +export default MarkdownItContainer; diff --git a/types/markdown-it-container/index.d.ts b/types/markdown-it-container/index.d.ts index 87aafd33c0def0..540a3baf9adbc6 100644 --- a/types/markdown-it-container/index.d.ts +++ b/types/markdown-it-container/index.d.ts @@ -1,11 +1,10 @@ import MarkdownIt = require("markdown-it"); -import Renderer = require("markdown-it/lib/renderer"); declare namespace MarkdownItContainer { interface ContainerOpts { marker?: string | undefined; validate?(params: string): boolean; - render?: Renderer.RenderRule | undefined; + render?: MarkdownIt.Renderer.RenderRule | undefined; } } diff --git a/types/markdown-it-container/package.json b/types/markdown-it-container/package.json index dc089f647432bc..88c4314ab38780 100644 --- a/types/markdown-it-container/package.json +++ b/types/markdown-it-container/package.json @@ -1,12 +1,22 @@ { "private": true, "name": "@types/markdown-it-container", - "version": "2.0.9999", + "version": "4.0.9999", "projects": [ "https://github.com/markdown-it/markdown-it-container" ], + "exports": { + ".": { + "require": "./index.d.ts", + "import": "./index.d.mts" + }, + "./*": { + "require": "./*", + "import": "./*" + } + }, "dependencies": { - "@types/markdown-it": "<14" + "@types/markdown-it": ">=14" }, "devDependencies": { "@types/markdown-it-container": "workspace:." diff --git a/types/markdown-it-container/tsconfig.json b/types/markdown-it-container/tsconfig.json index a088dbc9ab8fcd..a8a7500f5a8d6a 100644 --- a/types/markdown-it-container/tsconfig.json +++ b/types/markdown-it-container/tsconfig.json @@ -14,6 +14,7 @@ }, "files": [ "index.d.ts", + "index.d.mts", "markdown-it-container-tests.ts" ] } diff --git a/types/markdown-it-container/v2/.npmignore b/types/markdown-it-container/v2/.npmignore new file mode 100644 index 00000000000000..93e307400a5456 --- /dev/null +++ b/types/markdown-it-container/v2/.npmignore @@ -0,0 +1,5 @@ +* +!**/*.d.ts +!**/*.d.cts +!**/*.d.mts +!**/*.d.*.ts diff --git a/types/markdown-it-container/v2/index.d.ts b/types/markdown-it-container/v2/index.d.ts new file mode 100644 index 00000000000000..87aafd33c0def0 --- /dev/null +++ b/types/markdown-it-container/v2/index.d.ts @@ -0,0 +1,14 @@ +import MarkdownIt = require("markdown-it"); +import Renderer = require("markdown-it/lib/renderer"); + +declare namespace MarkdownItContainer { + interface ContainerOpts { + marker?: string | undefined; + validate?(params: string): boolean; + render?: Renderer.RenderRule | undefined; + } +} + +declare function MarkdownItContainer(md: MarkdownIt, name: string, opts: MarkdownItContainer.ContainerOpts): void; + +export = MarkdownItContainer; diff --git a/types/markdown-it-container/v2/markdown-it-container-tests.ts b/types/markdown-it-container/v2/markdown-it-container-tests.ts new file mode 100644 index 00000000000000..7b9e1276d3a0de --- /dev/null +++ b/types/markdown-it-container/v2/markdown-it-container-tests.ts @@ -0,0 +1,36 @@ +import MarkdownIt = require("markdown-it"); + +import MarkdownItContainer = require("markdown-it-container"); + +const md = new MarkdownIt(); + +md.use(MarkdownItContainer, "spoiler", { + validate: (params: string) => params.trim().match(/^spoiler\s+(.*)$/), + render: (tokens: MarkdownIt.Token[], index: number) => { + const match = tokens[index].info.trim().match(/^spoiler\s+(.*)$/); + const onClick = "this.parentNode.classList.toggle('_expanded');" + "event.preventDefault();"; + + if (tokens[index].nesting === 1) { + return ( + // tslint:disable-next-line prefer-template + "