UNPKG

@cspell/cspell-tools

Version:
44 lines 1.35 kB
import { createReader } from './Reader.js'; import { parseFileLines } from './wordListParser.js'; export async function createSourceReader(filename, options) { const reader = await createReader(filename, options); if (reader.type !== 'TextFile') { return { words: splitLines(reader.lines, options), get size() { return reader.size; }, }; } return textFileReader(reader, options); } function splitLines(lines, options) { if (!options.splitWords) return lines; function* split() { const regNonWordOrDigit = /[^\p{L}\p{M}'\w-]+/giu; for (const line of lines) { const words = line.split(regNonWordOrDigit); yield* words; } } return split(); } async function textFileReader(reader, options) { const { legacy, splitWords: split, allowedSplitWords, storeSplitWordsAsCompounds, minCompoundLength } = options; const parseOptions = { legacy, split, splitKeepBoth: undefined, keepCase: undefined, allowedSplitWords, storeSplitWordsAsCompounds, minCompoundLength, }; const words = [...parseFileLines(reader.lines, parseOptions)]; return { size: words.length, words, }; } //# sourceMappingURL=SourceReader.js.map