Leichte Container‑UI als TypeScript‑Bibliothek – kompatibel mit JS und TS.
Beinhaltet folgende Elemente:
Container(Wurzel/Composer)TextDisplay(einfacher Textblock)Section(Gruppe von Items)Separator(Trennlinie/Spacing)MediaGallery(Sammlung von Bild/Medien‑URLs)FileItem(beliebige Datei‑URL; optional als Spoiler)
✅ Dual Build (ESM & CJS) – funktioniert out‑of‑the‑box mit modernen Bundlern sowie mit
require()in Node.
npm install discord-container-ui
# oder im Repo:
npm install
npm run buildDas Build erzeugt
dist/index.mjs(ESM),dist/index.cjs(CJS) sowie Typdefinitionen.
// Node CommonJS
const { Container } = require("discord-container-ui");
const c = new Container()
.add_text("Hello world")
.add_separator()
.add_text("Another line");
console.log(JSON.stringify(c.toJSON(), null, 2));import { Container } from "discord-container-ui";
const c = new Container();
c.add_text("Hello world");
c.add_separator();
c.add_text("Another line");
console.log(c.copy_text()); // "Hello world\n---\nAnother line"
console.log(c.toJSON());add_item(item: Item | string | number): thisadd_text(content: string, id?: number | null): TextDisplayadd_separator(opts?: { divider?: boolean; spacing?: SeparatorSpacingSize; id?: number|null }): Separatoradd_gallery(...media: string[]): MediaGalleryadd_file(url: string, spoiler?: boolean, id?: number|null): FileItemwalk_items(): Iterable<Item>– flache Iteration inkl. Items inSectioncopy_text(): stringtoJSON(): SerializedContainerstatic fromJSON(obj: SerializedContainer): Container
content: stringcopy_text(): string
items: Item[]copy_text(): string– verkettet Inhalte der enthaltenen Items
divider: boolean(Standard:true)spacing: "small" | "medium" | "large"(Standard:"medium")
media: string[](URLs)
url: stringspoiler: boolean
Die Container können verlustarm in ein neutrales JSON‑Format konvertiert werden:
type SerializedItem =
| { type: "TextDisplay"; id?: number|null; payload: { content: string } }
| { type: "Separator"; id?: number|null; payload: { divider: boolean; spacing: "small"|"medium"|"large" } }
| { type: "Section"; id?: number|null; payload: { items: SerializedItem[] } }
| { type: "MediaGallery"; id?: number|null; payload: { media: string[] } }
| { type: "FileItem"; id?: number|null; payload: { url: string; spoiler?: boolean } };
type SerializedContainer = {
type: "Container";
id?: number|null;
colour?: number|null;
spoiler?: boolean;
components: SerializedItem[];
};toJSON()erzeugtSerializedContainer.Container.fromJSON()baut eine Instanz daraus wieder auf.
npm run dev– Watch‑Build mit tsupnpm run typecheck– TypeScript‑Typprüfungnpm run build– ESM & CJS Output inkl. Typen
MIT – siehe LICENSE.