hunspell-reader
Advanced tools
Comparing version 2.1.2 to 3.0.1
# Release Notes | ||
## 3.0.0 | ||
- **Breaking Change** dropping support for Node 8 and 9 | ||
- Removed dependency upon `cspell-lib` and `rxjs` | ||
- Improved processing speed. | ||
## 2.1.0 | ||
@@ -4,0 +9,0 @@ - Add an Iterable Reader, this works much better for very large dictionaries. |
import { AffInfo, Aff } from './aff'; | ||
import { Observable } from 'rxjs'; | ||
export interface ConvEntry { | ||
@@ -8,3 +7,3 @@ from: string; | ||
export declare function parseAffFile(filename: string, encoding?: string): Promise<AffInfo>; | ||
export declare function parseAff(lines: Observable<string>, _encoding?: string): Promise<AffInfo>; | ||
export declare function parseAff(affFileContent: string, _encoding?: string): AffInfo; | ||
export declare function parseAffFileToAff(filename: string, encoding?: string): Promise<Aff>; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fileReader_1 = require("./fileReader"); | ||
const aff_1 = require("./aff"); | ||
const operators_1 = require("rxjs/operators"); | ||
// cSpell:enableCompoundWords | ||
const fs_extra_1 = require("fs-extra"); | ||
const iconv_lite_1 = require("iconv-lite"); | ||
const fixRegex = { | ||
@@ -15,2 +22,3 @@ 'SFX': { m: /$/, r: '$' }, | ||
const commentRegex = /(?:^\s*#.*)|(?:\s+#.*)/; | ||
const UTF8 = 'UTF-8'; | ||
function convEntry(fieldValue, _, args) { | ||
@@ -119,2 +127,6 @@ if (fieldValue === undefined) { | ||
} | ||
/* | ||
cspell:ignore COMPOUNDBEGIN COMPOUNDEND COMPOUNDMIDDLE COMPOUNDMIN COMPOUNDPERMITFLAG COMPOUNDRULE FORBIDDENWORD KEEPCASE | ||
cspell:ignore MAXDIFF NEEDAFFIX WORDCHARS | ||
*/ | ||
const affTableField = { | ||
@@ -156,7 +168,9 @@ AF: afEntry, | ||
}; | ||
function parseAffFile(filename, encoding = 'UTF-8') { | ||
return parseAff(fileReader_1.lineReader(filename, encoding), encoding) | ||
.then(affInfo => { | ||
function parseAffFile(filename, encoding = UTF8) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const buffer = yield fs_extra_1.readFile(filename); | ||
const file = iconv_lite_1.decode(buffer, encoding); | ||
const affInfo = parseAff(file, encoding); | ||
if (affInfo.SET && affInfo.SET.toLowerCase() !== encoding.toLowerCase()) { | ||
return parseAff(fileReader_1.lineReader(filename, affInfo.SET), affInfo.SET); | ||
return parseAff(iconv_lite_1.decode(buffer, affInfo.SET.toLowerCase()), affInfo.SET); | ||
} | ||
@@ -167,4 +181,10 @@ return affInfo; | ||
exports.parseAffFile = parseAffFile; | ||
function parseAff(lines, _encoding = 'UTF-8') { | ||
return lines.pipe(operators_1.map(line => line.replace(commentRegex, '')), operators_1.filter(line => line.trim() !== ''), operators_1.map(line => line.split(spaceRegex)), operators_1.reduce((aff, line) => { | ||
function parseAff(affFileContent, _encoding = UTF8) { | ||
const lines = affFileContent.split(/\r?\n/g); | ||
return lines | ||
.map(line => line.trimLeft()) | ||
.map(line => line.replace(commentRegex, '')) | ||
.filter(line => line.trim() !== '') | ||
.map(line => line.split(spaceRegex)) | ||
.reduce((aff, line) => { | ||
const [field, ...args] = line; | ||
@@ -179,3 +199,3 @@ const fn = affTableField[field]; | ||
return aff; | ||
}, {})).toPromise(); | ||
}, {}); | ||
} | ||
@@ -182,0 +202,0 @@ exports.parseAff = parseAff; |
@@ -12,2 +12,3 @@ #!/usr/bin/env node | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// cSpell:ignore findup | ||
const commander = require("commander"); | ||
@@ -37,2 +38,3 @@ const IterableHunspellReader_1 = require("./IterableHunspellReader"); | ||
.option('-p, --progress', 'Show progress.') | ||
.option('-n, --number <limit>', 'Limit the number of words to output.') | ||
.description('Output all the words in the <hunspell.dic> file.') | ||
@@ -98,2 +100,3 @@ .action(action); | ||
if (reason.code === 'EPIPE') { | ||
console.log(reason); | ||
return; | ||
@@ -144,3 +147,3 @@ } | ||
const applyTransformers = (aff) => transformers.reduce((aff, fn) => fn(aff), aff); | ||
const words = seqWords | ||
const allWords = seqWords | ||
.map(applyTransformers) | ||
@@ -150,2 +153,3 @@ .filter(filterUnique) | ||
.map(a => a.word + '\n'); | ||
const words = options.number ? allWords.take(options.number) : allWords; | ||
if (sort) { | ||
@@ -152,0 +156,0 @@ log('Sorting...'); |
@@ -1,2 +0,2 @@ | ||
export * from './HunspellReader'; | ||
export * from './IterableHunspellReader'; | ||
export { IterableHunspellReader as HunspellReader } from './IterableHunspellReader'; |
@@ -6,4 +6,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./HunspellReader")); | ||
__export(require("./IterableHunspellReader")); | ||
var IterableHunspellReader_1 = require("./IterableHunspellReader"); | ||
exports.HunspellReader = IterableHunspellReader_1.IterableHunspellReader; | ||
//# sourceMappingURL=index.js.map |
@@ -14,2 +14,3 @@ "use strict"; | ||
const fs = require("fs-extra"); | ||
const iconv_lite_1 = require("iconv-lite"); | ||
const defaultEncoding = 'UTF-8'; | ||
@@ -66,3 +67,4 @@ class IterableHunspellReader { | ||
const aff = yield affReader_1.parseAffFileToAff(affFile); | ||
const dicFileContent = yield fs.readFile(dicFile, aff.affInfo.SET || defaultEncoding); | ||
const buffer = yield fs.readFile(dicFile); | ||
const dicFileContent = iconv_lite_1.decode(buffer, aff.affInfo.SET || defaultEncoding); | ||
const dic = dicFileContent.split('\n') | ||
@@ -69,0 +71,0 @@ .slice(1) // The first entry is the count of entries. |
{ | ||
"name": "hunspell-reader", | ||
"version": "2.1.2", | ||
"version": "3.0.1", | ||
"description": "A library for reading Hunspell Dictionary Files", | ||
"bin": "./dist/app.js", | ||
"bin": "bin.js", | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"files": [ | ||
"dist/", | ||
"src/", | ||
"dist", | ||
"bin.js", | ||
"!**/*.map", | ||
"!**/*.test.*" | ||
@@ -15,8 +16,10 @@ ], | ||
"test": "mocha --recursive ./dist/*.test.js", | ||
"build": "tsc", | ||
"clean": "rimraf ./dist/", | ||
"build": "tsc -p .", | ||
"prepare": "npm run build", | ||
"prepublishOnly": "npm run test", | ||
"clean": "rimraf ./dist", | ||
"coverage": "npm run generate-code-coverage", | ||
"generate-code-coverage": "NODE_ENV=test nyc npm run test-ts", | ||
"test-ts": "NODE_ENV=test mocha --require ts-node/register --recursive --bail \"src/**/*.test.ts\"", | ||
"test-watch": "npm run build && mocha --require ts-node/register --watch --recursive \"src/**/*.test.ts\"", | ||
"test-ts": "NODE_ENV=test mocha --require ts-node/register --recursive \"src/**/*.test.ts\"", | ||
"test-watch": "mocha --require ts-node/register --watch --recursive \"src/**/*.test.ts\"", | ||
"coverage-coveralls": "nyc report --reporter=text-lcov | coveralls", | ||
@@ -41,20 +44,18 @@ "travis-coverage": "npm run generate-code-coverage && npm run coverage-coveralls", | ||
"@types/chai": "^4.1.7", | ||
"@types/fs-extra": "^5.0.4", | ||
"@types/mocha": "^5.2.5", | ||
"@types/node": "^8.10.39", | ||
"@types/fs-extra": "^7.0.0", | ||
"@types/mocha": "^5.2.6", | ||
"@types/node": "^10.14.7", | ||
"chai": "^4.2.0", | ||
"coveralls": "^3.0.2", | ||
"mocha": "^5.2.0", | ||
"nyc": "^13.1.0", | ||
"coveralls": "^3.0.3", | ||
"mocha": "^6.1.4", | ||
"nyc": "^14.1.1", | ||
"rimraf": "^2.6.3", | ||
"ts-node": "^7.0.1", | ||
"typescript": "^3.2.2" | ||
"ts-node": "^8.1.0", | ||
"typescript": "^3.4.5" | ||
}, | ||
"dependencies": { | ||
"commander": "^2.19.0", | ||
"cspell-lib": "^3.0.5", | ||
"fs-extra": "^7.0.1", | ||
"commander": "^2.20.0", | ||
"fs-extra": "^8.0.1", | ||
"gensequence": "^2.1.2", | ||
"rxjs": "^6.3.3", | ||
"rxjs-stream": "^3.0.1" | ||
"iconv-lite": "^0.4.24" | ||
}, | ||
@@ -74,3 +75,3 @@ "eslintConfig": { | ||
"engines": { | ||
"node": ">=8.0.0" | ||
"node": ">=10.0.0" | ||
}, | ||
@@ -77,0 +78,0 @@ "nyc": { |
# hunspell-reader | ||
[![Build Status](https://travis-ci.org/Jason3S/cSpell-Tools.svg?branch=master)](https://travis-ci.org/Jason3S/cSpell-Tools) | ||
[![Build Status](https://travis-ci.org/streetsidesoftware/hunspell-reader.svg?branch=master)](https://travis-ci.org/streetsidesoftware/hunspell-reader) | ||
@@ -4,0 +4,0 @@ A library for reading Hunspell Dictionary files |
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
4
41903
25
993
3
+ Addediconv-lite@^0.4.24
+ Addedfs-extra@8.1.0(transitive)
- Removedcspell-lib@^3.0.5
- Removedrxjs@^6.3.3
- Removedrxjs-stream@^3.0.1
- Removedcspell-lib@3.0.8(transitive)
- Removedfs-extra@7.0.1(transitive)
- Removedrxjs@6.6.7(transitive)
- Removedrxjs-stream@3.3.0(transitive)
- Removedtslib@1.14.1(transitive)
Updatedcommander@^2.20.0
Updatedfs-extra@^8.0.1