Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
notify('Create Trie', !!outputFile);
const pOutputStream = createWriteStream(outputFile);
notify(`Generating...`, !!outputFile);
const lines = await fileToLines(filename);
const toLower = lowerCase ? (a: string) => a.toLowerCase() : (a: string) => a;
const wordsRx = lines
.map(toLower)
.map(a => a.trim())
.filter(a => !!a);
notify('Processing Trie');
const root = wordsRx.reduce((node: Trie.TrieNode, word: string) => Trie.insert(word, node), {} as Trie.TrieNode);
notify('Export Trie');
const serialStream = iterableToStream(Trie.serializeTrie(root, (base - 0) || 32));
const outputStream = await pOutputStream;
return new Promise((resolve) => {
serialStream.pipe(outputStream).on('finish', () => resolve());
});
});
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)}`);
}