This package has been archived, and as such it is read-only.
@flashcard/core@0.0.4Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
latest
bpevs/flashcard.jsThis package works with Cloudflare Workers, Node.js, Deno, BrowsersIt is unknown whether this package works with Bun




JSR Score
76%
Published
a year ago (0.0.4)
import Card from './card.ts' import type Template from './template.ts' export type NoteContent = Record<string, string | number> /** * A card contains the data necessary to create a flashcard. * Essentially, a "row" of the deck. A note contains one card per template */ export default class Note { id: string templates: Template[] = [] content: NoteContent _cards: Card[] = [] constructor(id: string, content: NoteContent, templates?: Template[]) { this.id = id this.content = content this._cards = [] if (templates) this.templates = templates } getCards(templates: Record<string, Template> = {}): Card[] { const prevTemplatesLen = this.templates.length const newTemplatesLen = Object.keys(templates).length const cardsLength = this._cards.length if (newTemplatesLen && (newTemplatesLen !== prevTemplatesLen)) { this.templates = [] Object.keys(templates).forEach((name) => { this.templates.push(templates[name]) }) } if (cardsLength !== this.templates.length) { this._cards = (this.templates || []) .map((template) => new Card(this.id + template.id, this, template)) } return this._cards } }