How to use the cspell-trie-lib.consolidate function in cspell-trie-lib

To help you get started, we’ve selected a few cspell-trie-lib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github streetsidesoftware / cspell / packages / cspell-tools / src / compiler / wordListCompiler.ts View on Github external
function compileSimpleWordListSeq(words: Sequence): Sequence {
    return words.map(a => a.toLowerCase());
}

export function normalizeWordsToTrie(words: Sequence): Trie.TrieNode {
    const trie = Trie.buildTrie(normalizeWords(words));
    return trie.root;
}

export interface CompileTrieOptions {
    base?: number;
    trie3?: boolean;
}

export const consolidate = Trie.consolidate;

export async function compileTrie(words: Sequence, destFilename: string, options: CompileTrieOptions): Promise {
    log('Reading Words into Trie');
    const base = options.base ?? 32;
    const version = options.trie3 ? 3 : 1;
    const destDir = path.dirname(destFilename);
    const pDir = mkdirp(destDir);
    const root = normalizeWordsToTrie(words);
    log('Reduce duplicate word endings');
    const trie = consolidate(root);
    log(`Writing to file ${path.basename(destFilename)}`);
    await pDir;
    await writeSeqToFile(Trie.serializeTrie(trie, { base, comment: 'Built by cspell-tools.', version }), destFilename);
    log(`Done writing to file ${path.basename(destFilename)}`);
}