hunspell-reader
Advanced tools
Comparing version 6.22.0 to 6.23.0
171
dist/app.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// cSpell:ignore findup | ||
const commander_1 = require("commander"); | ||
const fs_1 = require("fs"); | ||
const gensequence_1 = require("gensequence"); | ||
const aff_1 = require("./aff"); | ||
const IterableHunspellReader_1 = require("./IterableHunspellReader"); | ||
const iterableToStream_1 = require("./iterableToStream"); | ||
const util_1 = require("./util"); | ||
const uniqueHistorySize = 500000; | ||
const commandDictInfo_1 = require("./commandDictInfo"); | ||
const commandWords_1 = require("./commandWords"); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const packageInfo = require('../package.json'); | ||
const version = packageInfo['version']; | ||
let displayHelp = true; | ||
let logStream = process.stderr; | ||
commander_1.program.version(version); | ||
commander_1.program | ||
.command('words <hunspell_dic_file>') | ||
.option('-o, --output <file>', 'output file - defaults to stdout') | ||
.option('-s, --sort', 'sort the list of words') | ||
.option('-u, --unique', 'make sure the words are unique.') | ||
.option('-l, --lower_case', 'output in lower case') | ||
.option('-T, --no-transform', 'Do not apply the prefix and suffix transforms. Root words only.') | ||
.option('-x, --infix', 'Return words with prefix / suffix breaks. ex: "un<do>ing"') | ||
.option('-r, --rules', 'Append rules used to generate word.') | ||
.option('-p, --progress', 'Show progress.') | ||
.option('-m, --max_depth <limit>', 'Maximum depth to apply suffix rules.') | ||
.option('-n, --number <limit>', 'Limit the number of words to output.') | ||
.option('--forbidden', 'include forbidden words') | ||
.option('--partial_compounds', 'include words that must be part of a compound word') | ||
.option('--only_forbidden', 'includes only words that are forbidden') | ||
.description('Output all the words in the <hunspell.dic> file.') | ||
.action(action); | ||
commander_1.program.parse(process.argv); | ||
if (displayHelp) { | ||
commander_1.program.help(); | ||
} | ||
function notify(message, newLine = true) { | ||
message = message + (newLine ? '\n' : ''); | ||
logStream.write(message, 'utf-8'); | ||
} | ||
function yesNo(value) { | ||
return value ? 'Yes' : 'No'; | ||
} | ||
function affWordToInfix(aff) { | ||
return { ...aff, word: aff.prefix + '<' + aff.base + '>' + aff.suffix }; | ||
} | ||
function mapWord(map) { | ||
return (aff) => ({ ...aff, word: map(aff.word) }); | ||
} | ||
function appendRules(aff) { | ||
return { ...aff, word: aff.word + '\t[' + aff.rulesApplied + ' ]\t' + '(' + aff.dic + ')' }; | ||
} | ||
function writeSeqToFile(seq, outFile) { | ||
return new Promise((resolve, reject) => { | ||
let resolved = false; | ||
const out = outFile ? (0, fs_1.createWriteStream)(outFile) : process.stdout; | ||
const bufferedSeq = (0, gensequence_1.genSequence)((0, util_1.batch)(seq, 500)).map((batch) => batch.join('')); | ||
const dataStream = (0, iterableToStream_1.iterableToStream)(bufferedSeq); | ||
const fileStream = dataStream.pipe(out); | ||
const endEvents = ['finish', 'close', 'end']; | ||
function resolvePromise() { | ||
if (!resolved) { | ||
resolved = true; | ||
resolve(); | ||
} | ||
} | ||
const endHandler = () => { | ||
cleanupStreams(); | ||
setTimeout(resolvePromise, 10); | ||
}; | ||
const errorHandler = (e) => { | ||
cleanupStreams(); | ||
reject(e); | ||
}; | ||
listenToStreams(); | ||
function listenToStreams() { | ||
endEvents.forEach((event) => fileStream.addListener(event, endHandler)); | ||
fileStream.addListener('error', errorHandler); | ||
dataStream.addListener('end', endHandler); | ||
} | ||
function cleanupStreams() { | ||
endEvents.forEach((event) => fileStream.removeListener(event, endHandler)); | ||
fileStream.removeListener('error', errorHandler); | ||
dataStream.removeListener('end', endHandler); | ||
} | ||
}); | ||
} | ||
function action(hunspellDicFilename, options) { | ||
return actionPrime(hunspellDicFilename, options).catch((reason) => { | ||
if (reason.code === 'EPIPE') { | ||
console.log(reason); | ||
return; | ||
} | ||
console.error(reason); | ||
}); | ||
} | ||
async function actionPrime(hunspellDicFilename, options) { | ||
displayHelp = false; | ||
const { sort = false, unique = false, output: outputFile, lower_case: lowerCase = false, transform = true, infix = false, rules = false, progress: showProgress = false, max_depth, forbidden = false, only_forbidden: onlyForbidden = false, partial_compounds: partialCompoundsAllowed = false, } = options; | ||
logStream = outputFile ? process.stdout : process.stderr; | ||
const log = notify; | ||
log('Write words'); | ||
log(`Sort: ${yesNo(sort)}`); | ||
log(`Unique: ${yesNo(unique)}`); | ||
const baseFile = hunspellDicFilename.replace(/\.(dic|aff)$/, ''); | ||
const dicFile = baseFile + '.dic'; | ||
const affFile = baseFile + '.aff'; | ||
log(`Dic file: ${dicFile}`); | ||
log(`Aff file: ${affFile}`); | ||
log(`Generating Words...`); | ||
const reader = await IterableHunspellReader_1.IterableHunspellReader.createFromFiles(affFile, dicFile); | ||
if (max_depth && Number.parseInt(max_depth) >= 0) { | ||
reader.maxDepth = Number.parseInt(max_depth); | ||
} | ||
const transformers = []; | ||
const filters = []; | ||
if (!forbidden && !onlyForbidden) | ||
filters.push((aff) => !aff.flags.isForbiddenWord); | ||
if (onlyForbidden) | ||
filters.push((aff) => !!aff.flags.isForbiddenWord); | ||
if (!partialCompoundsAllowed) | ||
filters.push((aff) => !aff.flags.isOnlyAllowedInCompound); | ||
if (infix) { | ||
transformers.push(affWordToInfix); | ||
} | ||
if (lowerCase) { | ||
transformers.push(mapWord((a) => a.toLowerCase())); | ||
} | ||
if (rules) { | ||
transformers.push(appendRules); | ||
} | ||
transformers.push(mapWord((a) => a.trim())); | ||
const dicSize = reader.dic.length; | ||
let current = 0; | ||
const calcProgress = () => '\r' + current + ' / ' + dicSize; | ||
const reportProgressRate = 253; | ||
const callback = showProgress | ||
? () => { | ||
current++; | ||
!(current % reportProgressRate) && process.stderr.write(calcProgress(), 'utf-8'); | ||
} | ||
: () => { | ||
/* void */ | ||
}; | ||
const seqWords = transform ? reader.seqAffWords(callback) : reader.seqRootWords().map(aff_1.asAffWord); | ||
const filterUnique = unique ? (0, util_1.uniqueFilter)(uniqueHistorySize) : (_) => true; | ||
const applyTransformers = (aff) => transformers.reduce((aff, fn) => fn(aff), aff); | ||
const applyFilters = (aff) => filters.reduce((cur, fn) => cur && fn(aff), true); | ||
const allWords = seqWords | ||
.filter(applyFilters) | ||
.map(applyTransformers) | ||
.map((a) => a.word) | ||
.filter((a) => !!a) | ||
.filter(filterUnique) | ||
.map((a) => a + '\n'); | ||
const words = options.number ? allWords.take(Number.parseInt(options.number)) : allWords; | ||
if (sort) { | ||
log('Sorting...'); | ||
const data = words.toArray().sort().join(''); | ||
const fd = outputFile ? (0, fs_1.openSync)(outputFile, 'w') : 1; | ||
(0, fs_1.writeSync)(fd, data); | ||
} | ||
else { | ||
await writeSeqToFile(words, outputFile); | ||
} | ||
if (showProgress) { | ||
console.error(calcProgress()); | ||
} | ||
log('Done.'); | ||
} | ||
commander_1.program.addCommand((0, commandWords_1.getCommand)()); | ||
commander_1.program.addCommand((0, commandDictInfo_1.getCommand)()); | ||
commander_1.program.showHelpAfterError(); | ||
commander_1.program.parseAsync(process.argv); | ||
//# sourceMappingURL=app.js.map |
export type { AffInfo, AffWord } from './affDef'; | ||
export { parseAff, parseAffFile as readAffFile } from './affReader'; | ||
export * from './IterableHunspellReader'; | ||
export { createMatchingWordsFilter, type HunspellSrcData, IterableHunspellReader, type WordInfo, } from './IterableHunspellReader'; | ||
export { IterableHunspellReader as HunspellReader } from './IterableHunspellReader'; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.HunspellReader = exports.readAffFile = exports.parseAff = void 0; | ||
exports.HunspellReader = exports.IterableHunspellReader = exports.createMatchingWordsFilter = exports.readAffFile = exports.parseAff = void 0; | ||
var affReader_1 = require("./affReader"); | ||
Object.defineProperty(exports, "parseAff", { enumerable: true, get: function () { return affReader_1.parseAff; } }); | ||
Object.defineProperty(exports, "readAffFile", { enumerable: true, get: function () { return affReader_1.parseAffFile; } }); | ||
__exportStar(require("./IterableHunspellReader"), exports); | ||
var IterableHunspellReader_1 = require("./IterableHunspellReader"); | ||
Object.defineProperty(exports, "HunspellReader", { enumerable: true, get: function () { return IterableHunspellReader_1.IterableHunspellReader; } }); | ||
Object.defineProperty(exports, "createMatchingWordsFilter", { enumerable: true, get: function () { return IterableHunspellReader_1.createMatchingWordsFilter; } }); | ||
Object.defineProperty(exports, "IterableHunspellReader", { enumerable: true, get: function () { return IterableHunspellReader_1.IterableHunspellReader; } }); | ||
var IterableHunspellReader_2 = require("./IterableHunspellReader"); | ||
Object.defineProperty(exports, "HunspellReader", { enumerable: true, get: function () { return IterableHunspellReader_2.IterableHunspellReader; } }); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "hunspell-reader", | ||
"version": "6.22.0", | ||
"version": "6.23.0", | ||
"description": "A library for reading Hunspell Dictionary Files", | ||
@@ -28,3 +28,3 @@ "bin": "bin.js", | ||
"type": "git", | ||
"url": "git+https://github.com/Jason-Rev/hunspell-reader.git" | ||
"url": "git+https://github.com/streetsidesoftware/cspell.git" | ||
}, | ||
@@ -37,9 +37,9 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/Jason-Rev/hunspell-reader/issues" | ||
"url": "https://github.com/streetsidesoftware/cspell/issues" | ||
}, | ||
"homepage": "https://github.com/Jason-Rev/hunspell-reader#readme", | ||
"homepage": "https://github.com/streetsidesoftware/cspell/tree/main/packages/hunspell-reader#readme", | ||
"devDependencies": { | ||
"@types/jest": "^29.4.0", | ||
"@types/node": "^18.11.19", | ||
"jest": "^29.4.1", | ||
"@types/node": "^18.13.0", | ||
"jest": "^29.4.2", | ||
"ts-jest": "^29.0.5", | ||
@@ -49,2 +49,4 @@ "typescript": "^4.9.5" | ||
"dependencies": { | ||
"@cspell/cspell-pipe": "^6.23.0", | ||
"@cspell/cspell-types": "^6.23.0", | ||
"commander": "^10.0.0", | ||
@@ -57,3 +59,3 @@ "gensequence": "^4.0.3", | ||
}, | ||
"gitHead": "a133874ed7590cbe140f5067cfa80db84b644a5d" | ||
"gitHead": "a7cfbfa6cf42c9d9746dd8229d9f1317472e5af8" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
74480
32
1847
5
+ Added@cspell/cspell-pipe@^6.23.0
+ Added@cspell/cspell-types@^6.23.0
+ Added@cspell/cspell-pipe@6.31.3(transitive)
+ Added@cspell/cspell-types@6.31.3(transitive)