Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hunspell-reader

Package Overview
Dependencies
Maintainers
1
Versions
228
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hunspell-reader - npm Package Compare versions

Comparing version 3.1.5 to 3.2.0

41

dist/aff.d.ts

@@ -45,3 +45,3 @@ import { Converter } from './converter';

export interface AffInfo extends AffTransformFlags {
SET?: string;
SET: string;
TRY?: string;

@@ -77,2 +77,6 @@ KEY?: string;

}
/**
* AffWordFlags are the flags applied to a word after the hunspell rules have been applied.
* They are either `true` or `undefined`.
*/
export interface AffWordFlags {

@@ -85,5 +89,4 @@ /**

*
* @default false
*/
isCompoundPermitted?: boolean;
isCompoundPermitted?: true;
/**

@@ -94,5 +97,4 @@ * COMPOUNDBEGIN flag

*
* @default false
*/
canBeCompoundBegin?: boolean;
canBeCompoundBegin?: true;
/**

@@ -103,5 +105,4 @@ * COMPOUNDMIDDLE flag

*
* @default false
*/
canBeCompoundMiddle?: boolean;
canBeCompoundMiddle?: true;
/**

@@ -112,5 +113,4 @@ * COMPOUNDLAST flag

*
* @default false
*/
canBeCompoundEnd?: boolean;
canBeCompoundEnd?: true;
/**

@@ -122,5 +122,4 @@ * COMPOUNDPERMITFLAG flag

*
* @default false
*/
isOnlyAllowedInCompound?: boolean;
isOnlyAllowedInCompound?: true;
/**

@@ -131,5 +130,4 @@ * COMPOUNDFORBIDFLAG flag

*
* @default false
*/
isCompoundForbidden?: boolean;
isCompoundForbidden?: true;
/**

@@ -140,3 +138,3 @@ * WARN flag

*/
isWarning?: boolean;
isWarning?: true;
/**

@@ -149,3 +147,3 @@ * KEEPCASE flag

*/
isKeepCase?: boolean;
isKeepCase?: true;
/**

@@ -158,3 +156,3 @@ * FORCEUCASE flag

*/
isForceUCase?: boolean;
isForceUCase?: true;
/**

@@ -166,3 +164,3 @@ * FORBIDDENWORD flag

*/
isForbiddenWord?: boolean;
isForbiddenWord?: true;
/**

@@ -174,3 +172,3 @@ * NOSUGGEST flag

*/
isNoSuggest?: boolean;
isNoSuggest?: true;
/**

@@ -182,3 +180,3 @@ * NEEDAFFIX flag

*/
isNeedAffix?: boolean;
isNeedAffix?: true;
}

@@ -226,2 +224,3 @@ export interface AffWord {

}
declare function signature(aff: AffWord): string;
export declare function processRules(affInfo: AffInfo): Map<string, Rule>;

@@ -238,1 +237,5 @@ export declare function logAffWord(affWord: AffWord, message: string): AffWord;

export declare function filterAff(): (t: AffWord) => boolean;
export declare const debug: {
signature: typeof signature;
};
export {};

@@ -82,3 +82,3 @@ "use strict";

: '';
const flags = Object.assign(Object.assign({}, affWord.flags), { isNeedAffix: false });
const flags = affWord.flags.isNeedAffix ? removeNeedAffix(affWord.flags) : affWord.flags;
const matchingSubstitutions = [...affix.substitutionSets.values()]

@@ -159,3 +159,3 @@ .filter(sub => sub.match.test(word));

const { word, flags } = aff;
const sig = Object.keys(flags).map(f => flagToStringMap[f]).sort().join('|');
const sig = Object.entries(flags).filter(e => e[1]).map(f => flagToStringMap[f[0]]).sort().join('');
return word + '|' + sig;

@@ -257,2 +257,10 @@ }

exports.filterAff = filterAff;
exports.debug = {
signature,
};
function removeNeedAffix(flags) {
const newFlags = Object.assign({}, flags);
delete newFlags.isNeedAffix;
return newFlags;
}
//# sourceMappingURL=aff.js.map

@@ -21,3 +21,3 @@ import { AffInfo, Aff, Fx } from './aff';

export declare function parseAffFile(filename: string, encoding?: string): Promise<AffInfo>;
export declare function parseAff(affFileContent: string, _encoding?: string): AffInfo;
export declare function parseAff(affFileContent: string, encoding?: string): AffInfo;
export declare function parseAffFileToAff(filename: string, encoding?: string): Promise<Aff>;

@@ -24,0 +24,0 @@ declare function parseLine(line: string): AffLine;

@@ -222,3 +222,3 @@ "use strict";

exports.parseAffFile = parseAffFile;
function parseAff(affFileContent, _encoding = UTF8) {
function parseAff(affFileContent, encoding = UTF8) {
const lines = affFileContent.split(/\r?\n/g);

@@ -240,3 +240,3 @@ return lines

return aff;
}, {});
}, { SET: encoding });
}

@@ -243,0 +243,0 @@ exports.parseAff = parseAff;

@@ -40,2 +40,5 @@ #!/usr/bin/env node

.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.')

@@ -110,3 +113,3 @@ .action(action);

displayHelp = false;
const { sort = false, unique = false, output: outputFile, lower_case: lowerCase = false, transform = true, infix = false, rules = false, progress: showProgress = false, max_depth, } = options;
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;

@@ -128,2 +131,9 @@ const log = notify;

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) {

@@ -152,3 +162,5 @@ transformers.push(affWordToInfix);

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)

@@ -155,0 +167,0 @@ .filter(filterUnique)

@@ -1,2 +0,2 @@

import { Aff } from './aff';
import { Aff, AffWord } from './aff';
import { Sequence } from 'gensequence';

@@ -31,3 +31,3 @@ import { WordInfo } from './types';

* Iterator for all the words in the dictionary. The words are in the order found in the .dic after the
* transformations have been applied. No filtering is done based upon the AFF flags.
* transformations have been applied. Forbidden and CompoundOnly words are filtered out.
*/

@@ -41,4 +41,14 @@ [Symbol.iterator](): Sequence<string>;

*/
seqAffWords(tapPreApplyRules?: (w: string, index: number) => any, maxDepth?: number): Sequence<import("./aff").AffWord>;
seqAffWords(tapPreApplyRules?: (dicEntry: string, index: number) => any, maxDepth?: number): Sequence<AffWord>;
/**
* create an iterable sequence of the words in the dictionary.
*
* @param tapPreApplyRules -- optional function to be called before rules are applied to a word.
* It is mostly used for monitoring progress in combination with `size`.
*/
seqTransformDictionaryEntries(tapPreApplyRules?: (dicEntry: string, index: number) => any, maxDepth?: number): Sequence<AffWord[]>;
/**
* Iterator for all the words in the dictionary. The words are in the order found in the .dic after the
* transformations have been applied. Forbidden and CompoundOnly ARE INCLUDED.
*
* @internal

@@ -48,2 +58,6 @@ */

/**
* Returns an iterable that will only return stand alone words.
*/
wholeWords(): Sequence<string>;
/**
* @internal

@@ -50,0 +64,0 @@ */

@@ -57,5 +57,5 @@ "use strict";

* Iterator for all the words in the dictionary. The words are in the order found in the .dic after the
* transformations have been applied. No filtering is done based upon the AFF flags.
* transformations have been applied. Forbidden and CompoundOnly words are filtered out.
*/
[Symbol.iterator]() { return this.seqWords(); }
[Symbol.iterator]() { return this.wholeWords(); }
/**

@@ -68,2 +68,11 @@ * create an iterable sequence of the words in the dictionary.

seqAffWords(tapPreApplyRules, maxDepth) {
return this.seqTransformDictionaryEntries(tapPreApplyRules, maxDepth).concatMap(a => a);
}
/**
* create an iterable sequence of the words in the dictionary.
*
* @param tapPreApplyRules -- optional function to be called before rules are applied to a word.
* It is mostly used for monitoring progress in combination with `size`.
*/
seqTransformDictionaryEntries(tapPreApplyRules, maxDepth) {
const seq = gensequence_1.genSequence(this.src.dic);

@@ -73,12 +82,26 @@ let count = 0;

return dicWords
.filter(a => !!a.trim())
.concatMap(dicWord => this.aff.applyRulesToDicEntry(dicWord, maxDepth));
.map(dicWord => this.aff.applyRulesToDicEntry(dicWord, maxDepth));
}
/**
* Iterator for all the words in the dictionary. The words are in the order found in the .dic after the
* transformations have been applied. Forbidden and CompoundOnly ARE INCLUDED.
*
* @internal
*/
seqWords() {
return this.seqAffWords().map(w => w.word).filter(createMatchingWordsFilter());
return this.seqAffWords()
.map(w => w.word)
.filter(createMatchingWordsFilter());
}
/**
* Returns an iterable that will only return stand alone words.
*/
wholeWords() {
return this.seqAffWords()
// Filter out words that are forbidden or only allowed in Compounds.
.filter(w => !w.flags.isForbiddenWord && !w.flags.isOnlyAllowedInCompound)
.map(w => w.word)
.filter(createMatchingWordsFilter());
}
/**
* @internal

@@ -91,7 +114,8 @@ */

return __awaiter(this, void 0, void 0, function* () {
const aff = yield affReader_1.parseAffFileToAff(affFile);
const aff = yield affReader_1.parseAffFileToAff(affFile, defaultEncoding);
const buffer = yield fs.readFile(dicFile);
const dicFileContent = iconv_lite_1.decode(buffer, aff.affInfo.SET || defaultEncoding);
const dicFileContent = iconv_lite_1.decode(buffer, aff.affInfo.SET);
const dic = dicFileContent.split('\n')
.slice(1) // The first entry is the count of entries.
.map(a => a.trim())
.filter(line => !!line);

@@ -98,0 +122,0 @@ return new IterableHunspellReader({ aff, dic });

{
"name": "hunspell-reader",
"version": "3.1.5",
"version": "3.2.0",
"description": "A library for reading Hunspell Dictionary Files",

@@ -5,0 +5,0 @@ "bin": "bin.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc