My App
LoopKitBackend

Validation

Input validation helpers for deck config, notes, and grades

Functions

validateDeckConfig

function validateDeckConfig(partial: Partial<DeckConfig>): DeckConfig

Merges partial config with DEFAULT_DECK_CONFIG and clamps all values to safe ranges:

FieldConstraint
newCardsPerDay>= 0, integer
maxReviewsPerDay>= 0, integer
graduatingInterval>= 1
easyInterval>= 1
maxInterval>= 1
startingEaseFactor>= 1.3
hardIntervalMultiplier>= 0.5
easyBonus>= 1.0
lapseNewInterval0-1
lapseMinInterval>= 1
nextDayStartsAt0-23, integer
learningStepsAt least [1, 10] if empty
relearningStepsAt least [10] if empty

validateNote

function validateNote(input: CreateNoteInput, noteType: NoteType): void

Validates that:

  1. All provided fields exist in the note type's field schema
  2. All required fields are present
  3. Required fields are not empty (after trimming)

Throws: ValidationError with descriptive messages.

validateGrade

function validateGrade(grade: string): Grade

Validates that the grade is one of 'again', 'hard', 'good', 'easy'.

Throws: InvalidGradeError if invalid.

On this page