Word difficulty extension for GLOST - generates and formats difficulty data
npm install glost-difficultybeginner - Basic, easy words for beginners
intermediate - Moderate difficulty words
advanced - Difficult words for advanced learners
bash
pnpm add glost-difficulty
`
Usage
$3
`typescript
import { createDifficultyGeneratorExtension, createDifficultyEnhancerExtension } from "glost-difficulty";
import { createJapaneseDifficultyProvider } from "glost-ja/extensions";
// Create JLPT-based provider
const provider = createJapaneseDifficultyProvider({
jlptLevel: "N3"
});
const generator = createDifficultyGeneratorExtension({
targetLanguage: "ja",
provider
});
const enhancer = createDifficultyEnhancerExtension();
const result = await processGLOSTWithExtensionsAsync(doc, [generator, enhancer]);
`
API
$3
Creates extension that assesses word difficulty.
Options:
- targetLanguage - ISO-639-1 language code
- provider - DifficultyProvider instance
- skipExisting - Skip words with existing difficulty (default: true)
$3
Creates extension that formats difficulty data.
Options:
- normalize - Normalize difficulty values (default: true)
- customMapping - Word → difficulty mappings
$3
Implement the DifficultyProvider interface with real word lists:
`typescript
import type { DifficultyProvider, DifficultyLevel } from "glost-difficulty";
export function createMyDifficultyProvider(
cefrLists: { A1: Set, A2: Set, B1: Set, ... }
): DifficultyProvider {
return {
async getDifficulty(word, language) {
if (cefrLists.A1.has(word) || cefrLists.A2.has(word)) return "beginner";
if (cefrLists.B1.has(word) || cefrLists.B2.has(word)) return "intermediate";
if (cefrLists.C1.has(word) || cefrLists.C2.has(word)) return "advanced";
return undefined; // No data? Return undefined, don't guess!
}
};
}
`
$3
Convenience function that creates both generator and enhancer.
Returns: [generator, enhancer]`