UNPKG

@notatki/preview

Version:

A collection of tools for creating and syncing Anki notes from simple text files.

53 lines 1.57 kB
import {} from "@notatki/core"; import { formatField, renderHtml } from "@notatki/format"; import { escapeHtml } from "./html.js"; const html = renderHtml({ output: "html", throwOnError: false }); export class CardData { #model; #card; #note; #data; constructor(model, card, note) { this.#model = model; this.#card = card; this.#note = note; this.#data = new Map(); // Build-in fields. this.setValue("Type", escapeHtml(note.type.name)); this.setValue("Card", escapeHtml(card.name)); this.setValue("Deck", escapeHtml(note.deck)); this.setValue("Subdeck", escapeHtml(note.deck.split("::").pop() ?? note.deck)); this.setValue("Tags", escapeHtml(note.tags)); this.setValue("Flags", escapeHtml("Flags")); // User-defined fields. for (const { name, value } of note) { this.setValue(name, formatField(value, html)); } } get model() { return this.#model; } get card() { return this.#card; } get note() { return this.#note; } hasValue(name) { return this.#data.get(name) != null; } getValue(name) { const value = this.#data.get(name); if (value == null) { throw new Error(`Unknown field: ${this.#note.type.name}::${name}`); } return value; } clearValue(name) { this.#data.delete(name); } setValue(name, value) { this.#data.set(name, value); } } //# sourceMappingURL=card-data.js.map