33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
import fs from 'node:fs';
|
|
import { buildWordSet } from './lexicon-sources.mjs';
|
|
|
|
// Build a clean, high-frequency recognized vocabulary for client-side unlimited/custom puzzles
|
|
// (includes regional spellings and the proper-word allowlist)
|
|
const vocabulary = buildWordSet();
|
|
|
|
console.log('Total vocabulary words:', vocabulary.size);
|
|
|
|
// Pack into space-separated string or array
|
|
const sortedWords = [...vocabulary].sort();
|
|
const lexiconContent = `// Client-side recognized English words for solver & custom puzzles
|
|
// Loaded as a Set for O(1) instantaneous lookup
|
|
const RAW_LEXICON = ${JSON.stringify(sortedWords)};
|
|
|
|
export const DICTIONARY_SET = new Set(RAW_LEXICON);
|
|
|
|
// Prefix set for lightning fast tree-pruning search (1 to 6 chars)
|
|
export const PREFIX_SET = new Set();
|
|
for (const word of RAW_LEXICON) {
|
|
for (let len = 1; len <= Math.min(word.length, 6); len++) {
|
|
PREFIX_SET.add(word.slice(0, len));
|
|
}
|
|
}
|
|
|
|
export function isWordValid(word) {
|
|
return DICTIONARY_SET.has(word.toLowerCase());
|
|
}
|
|
`;
|
|
|
|
fs.writeFileSync('src/data/lexicon.js', lexiconContent, 'utf8');
|
|
console.log('Saved src/data/lexicon.js successfully!');
|