Files
Hankan/types/lib/srs.d.ts
MechaCat02 966043ab3f feat(lib): type declarations and golden tests for the exported modules
lib/ ships unchanged, so its types live in types/lib/ and are wired up by a
tsconfig path mapping. Adding types costs nothing; reimplementing the logic
would cost the two things that make this port possible.

The tests exist so a later refactor cannot silently drift them:

  hangul       the nine Composer cases named in the export README —
               먹어 · 왔어 · 읽어 · 괜찮아 · 값 · 의사 · 뭐야 and backspace
  conjugation  all seven irregular classes, and every form in
               IRREGULAR_FORMS reachable through haeche()
  srs          the SM-2 transitions, ease and interval clamps
  blocks       parse → answerText round-trip for all four task types

101 tests.

One is a pinned defect rather than a guarantee. blocks.parse() never closes
a ::gloss block on its "=" line, so a multi-sentence gloss — which the tutor
prompt explicitly invites — collapses into one run-on line keeping only the
last translation. lib/ ships unchanged, so the test records the real
behaviour and the app works around it at the call site.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-08 19:12:19 +02:00

39 lines
1.1 KiB
TypeScript

/* Declarations for lib/srs.js — the module itself ships unchanged. */
export const AGAIN: 0;
export const HARD: 1;
export const GOOD: 2;
export const EASY: 3;
export type Grade = 0 | 1 | 2 | 3;
export const NEW: 0;
export const LEARNING: 1;
export const REVIEW: 2;
export type CardState = 0 | 1 | 2;
/** Days at which a card counts as known. */
export const SECURE_INTERVAL: number;
export interface Card {
state: CardState;
interval: number;
ease: number;
/** Day number, not a timestamp — see dayNumber(). */
due: number;
reps: number;
lapses: number;
}
export function newCard(): Card;
export function grade(card: Card, g: Grade, today: number): Card;
export function markKnown(today: number): Card;
export type CardStatus = "new" | "learning" | "review" | "secure";
export function statusOf(card: Card | null | undefined): CardStatus;
/** Label for the interval a grade would produce — shown on the buttons. */
export function preview(card: Card | null | undefined, g: Grade, today: number): string;
/** Local day number, DST-safe. */
export function dayNumber(d?: Date): number;