LoopKitBackend
Validation
Input validation helpers for deck config, notes, and grades
Functions
validateDeckConfig
function validateDeckConfig(partial: Partial<DeckConfig>): DeckConfigMerges partial config with DEFAULT_DECK_CONFIG and clamps all values to safe ranges:
| Field | Constraint |
|---|---|
newCardsPerDay | >= 0, integer |
maxReviewsPerDay | >= 0, integer |
graduatingInterval | >= 1 |
easyInterval | >= 1 |
maxInterval | >= 1 |
startingEaseFactor | >= 1.3 |
hardIntervalMultiplier | >= 0.5 |
easyBonus | >= 1.0 |
lapseNewInterval | 0-1 |
lapseMinInterval | >= 1 |
nextDayStartsAt | 0-23, integer |
learningSteps | At least [1, 10] if empty |
relearningSteps | At least [10] if empty |
validateNote
function validateNote(input: CreateNoteInput, noteType: NoteType): voidValidates that:
- All provided fields exist in the note type's field schema
- All required fields are present
- Required fields are not empty (after trimming)
Throws: ValidationError with descriptive messages.
validateGrade
function validateGrade(grade: string): GradeValidates that the grade is one of 'again', 'hard', 'good', 'easy'.
Throws: InvalidGradeError if invalid.