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

hunspell-asm

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hunspell-asm - npm Package Compare versions

Comparing version 2.0.0-beta.1 to 2.0.0-beta.2

17

CHANGELOG.md

@@ -0,1 +1,18 @@

<a name="2.0.0-beta.2"></a>
# [2.0.0-beta.2](https://github.com/kwonoj/hunspell-asm/compare/v2.0.0-beta.1...v2.0.0-beta.2) (2018-11-02)
### Bug Fixes
* **allocstring:** use emscripten method, explicitly free ([09a1a56](https://github.com/kwonoj/hunspell-asm/commit/09a1a56))
### Features
* **hunspell:** update interfaces ([c937dec](https://github.com/kwonoj/hunspell-asm/commit/c937dec))
* **hunspellloader:** implement addword interfaces ([9a56a35](https://github.com/kwonoj/hunspell-asm/commit/9a56a35))
* **wraphunspellinterface:** expose add interfaces ([73e5d1c](https://github.com/kwonoj/hunspell-asm/commit/73e5d1c))
<a name="2.0.0-beta.1"></a>

@@ -2,0 +19,0 @@ # [2.0.0-beta.1](https://github.com/kwonoj/hunspell-asm/compare/v1.1.2...v2.0.0-beta.1) (2018-11-01)

56

dist/cjs/hunspellLoader.js

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

exports.hunspellLoader = function (asmModule, environment) {
var cwrap = asmModule.cwrap, FS = asmModule.FS, stringToUTF8 = asmModule.stringToUTF8, stackAlloc = asmModule.stackAlloc, stackSave = asmModule.stackSave, stackRestore = asmModule.stackRestore, getValue = asmModule.getValue, Pointer_stringify = asmModule.Pointer_stringify;
var cwrap = asmModule.cwrap, FS = asmModule.FS, _free = asmModule._free, allocateUTF8 = asmModule.allocateUTF8, stackAlloc = asmModule.stackAlloc, getValue = asmModule.getValue, Pointer_stringify = asmModule.Pointer_stringify;
var hunspellInterface = wrapHunspellInterface_1.wrapHunspellInterface(cwrap);

@@ -32,6 +32,16 @@ //creating top-level path to mount files

}
var allocString = function (value) {
var len = (value.length << 2) + 1;
var ret = stackAlloc(len);
stringToUTF8(value, ret, len);
/**
* Naive auto-dispose interface to call hunspell interface with string params.
*
*/
var usingParamPtr = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var params = args.slice();
var fn = params.pop();
var paramsPtr = params.map(function (param) { return allocateUTF8(param); });
var ret = fn.apply(void 0, paramsPtr);
paramsPtr.forEach(function (paramPtr) { return _free(paramPtr); });
return ret;

@@ -44,16 +54,17 @@ };

create: function (affPath, dictPath) {
var hunspellPtr = hunspellInterface.create(allocString(affPath), allocString(dictPath));
var affPathPtr = allocateUTF8(affPath);
var dictPathPtr = allocateUTF8(dictPath);
var hunspellPtr = hunspellInterface.create(affPathPtr, dictPathPtr);
return {
dispose: function () { return hunspellInterface.destroy(hunspellPtr); },
spell: function (word) {
//let allocated string volatile via manually save / restore stacks, instead of malloc / free
var stack = stackSave();
var ret = hunspellInterface.spell(hunspellPtr, allocString(word));
stackRestore(stack);
return !!ret;
dispose: function () {
hunspellInterface.destroy(hunspellPtr);
_free(affPathPtr);
_free(dictPathPtr);
},
spell: function (word) { return !!usingParamPtr(word, function (wordPtr) { return hunspellInterface.spell(hunspellPtr, wordPtr); }); },
suggest: function (word) {
var stack = stackSave();
var suggestionListPtr = stackAlloc(4);
var suggestionCount = hunspellInterface.suggest(hunspellPtr, suggestionListPtr, allocString(word));
var suggestionCount = usingParamPtr(word, function (wordPtr) {
return hunspellInterface.suggest(hunspellPtr, suggestionListPtr, wordPtr);
});
var suggestionListValuePtr = getValue(suggestionListPtr, '*');

@@ -66,5 +77,16 @@ var ret = suggestionCount > 0

hunspellInterface.free_list(hunspellPtr, suggestionListPtr, suggestionCount);
stackRestore(stack);
return ret;
}
},
addDictionary: function (dictPath) {
return usingParamPtr(dictPath, function (dictPathPtr) { return hunspellInterface.add_dic(hunspellPtr, dictPathPtr); }) === 1
? false
: true;
},
addWord: function (word) { return usingParamPtr(word, function (wordPtr) { return hunspellInterface.add(hunspellPtr, wordPtr); }); },
addWordWithAffix: function (word, affix) {
return usingParamPtr(word, affix, function (wordPtr, affixPtr) {
return hunspellInterface.add_with_affix(hunspellPtr, wordPtr, affixPtr);
});
},
removeWord: function (word) { return usingParamPtr(word, function (wordPtr) { return hunspellInterface.remove(hunspellPtr, wordPtr); }); }
};

@@ -71,0 +93,0 @@ }

@@ -18,4 +18,13 @@ "use strict";

//void Hunspell_free_list(Hunhandle* pHunspell, char*** slst, int n);
free_list: cwrap('Hunspell_free_list', null, ['number', 'number', 'number'])
free_list: cwrap('Hunspell_free_list', null, ['number', 'number', 'number']),
//0 = additional dictionary slots available, 1 = slots are now full
//int Hunspell_add_dic(Hunhandle* pHunspell, const char* dpath);
add_dic: cwrap('Hunspell_add_dic', 'number', ['number', 'number']),
//int Hunspell_add(Hunhandle* pHunspell, const char* word);
add: cwrap('Hunspell_add', 'number', ['number', 'number']),
//int Hunspell_add_with_affix(Hunhandle* pHunspell, const char* word, const char* example);
add_with_affix: cwrap('Hunspell_add_with_affix', 'number', ['number', 'number', 'number']),
//int Hunspell_remove(Hunhandle* pHunspell, const char* word);
remove: cwrap('Hunspell_remove', 'number', ['number', 'number'])
}); };
//# sourceMappingURL=wrapHunspellInterface.js.map

@@ -18,3 +18,3 @@ import { ENVIRONMENT } from 'emscripten-wasm-loader';

export var hunspellLoader = function (asmModule, environment) {
var cwrap = asmModule.cwrap, FS = asmModule.FS, stringToUTF8 = asmModule.stringToUTF8, stackAlloc = asmModule.stackAlloc, stackSave = asmModule.stackSave, stackRestore = asmModule.stackRestore, getValue = asmModule.getValue, Pointer_stringify = asmModule.Pointer_stringify;
var cwrap = asmModule.cwrap, FS = asmModule.FS, _free = asmModule._free, allocateUTF8 = asmModule.allocateUTF8, stackAlloc = asmModule.stackAlloc, getValue = asmModule.getValue, Pointer_stringify = asmModule.Pointer_stringify;
var hunspellInterface = wrapHunspellInterface(cwrap);

@@ -30,6 +30,16 @@ //creating top-level path to mount files

}
var allocString = function (value) {
var len = (value.length << 2) + 1;
var ret = stackAlloc(len);
stringToUTF8(value, ret, len);
/**
* Naive auto-dispose interface to call hunspell interface with string params.
*
*/
var usingParamPtr = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var params = args.slice();
var fn = params.pop();
var paramsPtr = params.map(function (param) { return allocateUTF8(param); });
var ret = fn.apply(void 0, paramsPtr);
paramsPtr.forEach(function (paramPtr) { return _free(paramPtr); });
return ret;

@@ -42,16 +52,17 @@ };

create: function (affPath, dictPath) {
var hunspellPtr = hunspellInterface.create(allocString(affPath), allocString(dictPath));
var affPathPtr = allocateUTF8(affPath);
var dictPathPtr = allocateUTF8(dictPath);
var hunspellPtr = hunspellInterface.create(affPathPtr, dictPathPtr);
return {
dispose: function () { return hunspellInterface.destroy(hunspellPtr); },
spell: function (word) {
//let allocated string volatile via manually save / restore stacks, instead of malloc / free
var stack = stackSave();
var ret = hunspellInterface.spell(hunspellPtr, allocString(word));
stackRestore(stack);
return !!ret;
dispose: function () {
hunspellInterface.destroy(hunspellPtr);
_free(affPathPtr);
_free(dictPathPtr);
},
spell: function (word) { return !!usingParamPtr(word, function (wordPtr) { return hunspellInterface.spell(hunspellPtr, wordPtr); }); },
suggest: function (word) {
var stack = stackSave();
var suggestionListPtr = stackAlloc(4);
var suggestionCount = hunspellInterface.suggest(hunspellPtr, suggestionListPtr, allocString(word));
var suggestionCount = usingParamPtr(word, function (wordPtr) {
return hunspellInterface.suggest(hunspellPtr, suggestionListPtr, wordPtr);
});
var suggestionListValuePtr = getValue(suggestionListPtr, '*');

@@ -64,5 +75,16 @@ var ret = suggestionCount > 0

hunspellInterface.free_list(hunspellPtr, suggestionListPtr, suggestionCount);
stackRestore(stack);
return ret;
}
},
addDictionary: function (dictPath) {
return usingParamPtr(dictPath, function (dictPathPtr) { return hunspellInterface.add_dic(hunspellPtr, dictPathPtr); }) === 1
? false
: true;
},
addWord: function (word) { return usingParamPtr(word, function (wordPtr) { return hunspellInterface.add(hunspellPtr, wordPtr); }); },
addWordWithAffix: function (word, affix) {
return usingParamPtr(word, affix, function (wordPtr, affixPtr) {
return hunspellInterface.add_with_affix(hunspellPtr, wordPtr, affixPtr);
});
},
removeWord: function (word) { return usingParamPtr(word, function (wordPtr) { return hunspellInterface.remove(hunspellPtr, wordPtr); }); }
};

@@ -69,0 +91,0 @@ }

@@ -16,4 +16,13 @@ /**

//void Hunspell_free_list(Hunhandle* pHunspell, char*** slst, int n);
free_list: cwrap('Hunspell_free_list', null, ['number', 'number', 'number'])
free_list: cwrap('Hunspell_free_list', null, ['number', 'number', 'number']),
//0 = additional dictionary slots available, 1 = slots are now full
//int Hunspell_add_dic(Hunhandle* pHunspell, const char* dpath);
add_dic: cwrap('Hunspell_add_dic', 'number', ['number', 'number']),
//int Hunspell_add(Hunhandle* pHunspell, const char* word);
add: cwrap('Hunspell_add', 'number', ['number', 'number']),
//int Hunspell_add_with_affix(Hunhandle* pHunspell, const char* word, const char* example);
add_with_affix: cwrap('Hunspell_add_with_affix', 'number', ['number', 'number', 'number']),
//int Hunspell_remove(Hunhandle* pHunspell, const char* word);
remove: cwrap('Hunspell_remove', 'number', ['number', 'number'])
}); };
//# sourceMappingURL=wrapHunspellInterface.js.map

@@ -25,3 +25,41 @@ /**

suggest: (word: string) => Array<string>;
/**
* Load additional dictionaries into existing hunspell instance.
* This only loads dictionaries, cannot load affix.
*
* @param {string} dictPath In-memory file path to dic file. Path should use unix separator.
*
* @return {boolean} false if internal available slot for dict are full and can't add any more.
*/
addDictionary: (dictPath: string) => boolean;
/**
* Add word to the run-time dictionary
*/
addWord: (word: string) => void;
/**
* Add word to the run-time dictionary with affix flags of
* the example (a dictionary word): Hunspell will recognize
* affixed forms of the new word, too.
*
* Note: `affix` flag example word is a word already exists in dictionary with its affix rule,
* so newly supplied word will follow same affix rules.
*
* i.e in current dict, suppose word `uncreate` have rules like
* - dic: `uncreate/V`
* - aff:
* SFX V e ive e
* SFX V 0 ive [^e]
*
* now applying new word
* addWordWithAffix('tttre', 'uncreate');
*
* new word `tttre` follows same affix rule, so
* spell(`tttrive`) === true
*/
addWordWithAffix: (word: string, affix: string) => void;
/**
* Remove word from the run-time dictionary.
*/
removeWord: (word: string) => void;
}
//# sourceMappingURL=Hunspell.d.ts.map
/** @internal */
export declare type stringToUTF8Signature = (str: string, outPtr: number, maxBytesToWrite: number) => void;
/** @internal */
export declare type cwrapSignature = <T = Function>(fn: string, returnType: string | null, parameterType: Array<string>) => T;

@@ -39,6 +37,5 @@ /** @internal */

FS: FS;
stringToUTF8: stringToUTF8Signature;
_free: (ptr: number) => void;
allocateUTF8: (str: string) => number;
stackAlloc: (length: number) => number;
stackSave: () => number;
stackRestore: (stack: number) => void;
getValue: <T = any>(ptr: number, type: string, nosafe?: boolean) => T;

@@ -45,0 +42,0 @@ Pointer_stringify: (ptr: number) => string;

@@ -13,3 +13,7 @@ import { cwrapSignature } from './HunspellAsmModule';

free_list: (hunspellPtr: number, suggestionListPtr: number, count: number) => void;
add_dic: (hunspellPtr: number, dicPath: number) => number;
add: (hunspellPtr: number, value: number) => number;
add_with_affix: (hunspellPtr: number, value: number, affix: number) => number;
remove: (hunspellPtr: number, value: number) => number;
};
//# sourceMappingURL=wrapHunspellInterface.d.ts.map
{
"name": "hunspell-asm",
"version": "2.0.0-beta.1",
"version": "2.0.0-beta.2",
"description": "WebAssembly based Javascript bindings for hunspell spellchecker",

@@ -5,0 +5,0 @@ "main": "./dist/cjs/index.js",

@@ -65,2 +65,12 @@ [![Build Status](https://travis-ci.org/kwonoj/hunspell-asm.svg?branch=master)](https://travis-ci.org/kwonoj/hunspell-asm)

## Adding words to dictionary in runtime
Hunspell exposes few interfaces allow to add words, or dictionaries in existing dictionary in runtime. This is **runtime** behavior, so it doesn't persist over once instance is disposed.
- `addWord(word: string): void` : add single word to current dictionary.
- `removeWord(word: string): void` : remove single word from current dictionary.
- `addWordWithAffix(word: string, affix: string): void`: add word with example word having affix flag to be applied. Second param `affix` is example word, should exists in current dictionary with its own affix flag. Newly added word will have same affix rule as example word.
- `addDictionary(dictPath): boolean` : Load addtional dictionary into existing hunspell instance. This cannot load additional affi
x. If function returns false, it means internal slot hunspell manages are full and can't add additional dictionaries.
## Things to note

@@ -67,0 +77,0 @@

@@ -27,2 +27,44 @@ /**

suggest: (word: string) => Array<string>;
/**
* Load additional dictionaries into existing hunspell instance.
* This only loads dictionaries, cannot load affix.
*
* @param {string} dictPath In-memory file path to dic file. Path should use unix separator.
*
* @return {boolean} false if internal available slot for dict are full and can't add any more.
*/
addDictionary: (dictPath: string) => boolean;
/**
* Add word to the run-time dictionary
*/
addWord: (word: string) => void;
/**
* Add word to the run-time dictionary with affix flags of
* the example (a dictionary word): Hunspell will recognize
* affixed forms of the new word, too.
*
* Note: `affix` flag example word is a word already exists in dictionary with its affix rule,
* so newly supplied word will follow same affix rules.
*
* i.e in current dict, suppose word `uncreate` have rules like
* - dic: `uncreate/V`
* - aff:
* SFX V e ive e
* SFX V 0 ive [^e]
*
* now applying new word
* addWordWithAffix('tttre', 'uncreate');
*
* new word `tttre` follows same affix rule, so
* spell(`tttrive`) === true
*/
addWordWithAffix: (word: string, affix: string) => void;
/**
* Remove word from the run-time dictionary.
*/
removeWord: (word: string) => void;
}
/** @internal */
export type stringToUTF8Signature = (str: string, outPtr: number, maxBytesToWrite: number) => void;
/** @internal */
export type cwrapSignature = <T = Function>(fn: string, returnType: string | null, parameterType: Array<string>) => T;

@@ -38,6 +35,5 @@

FS: FS;
stringToUTF8: stringToUTF8Signature;
_free: (ptr: number) => void;
allocateUTF8: (str: string) => number;
stackAlloc: (length: number) => number;
stackSave: () => number;
stackRestore: (stack: number) => void;
getValue: <T = any>(ptr: number, type: string, nosafe?: boolean) => T;

@@ -44,0 +40,0 @@ Pointer_stringify: (ptr: number) => string;

@@ -22,3 +22,3 @@ import { ENVIRONMENT } from 'emscripten-wasm-loader';

export const hunspellLoader = (asmModule: HunspellAsmModule, environment: ENVIRONMENT): HunspellFactory => {
const { cwrap, FS, stringToUTF8, stackAlloc, stackSave, stackRestore, getValue, Pointer_stringify } = asmModule;
const { cwrap, FS, _free, allocateUTF8, stackAlloc, getValue, Pointer_stringify } = asmModule;
const hunspellInterface = wrapHunspellInterface(cwrap);

@@ -37,6 +37,12 @@

const allocString = (value: string) => {
const len = (value.length << 2) + 1;
const ret = stackAlloc(len);
stringToUTF8(value, ret, len);
/**
* Naive auto-dispose interface to call hunspell interface with string params.
*
*/
const usingParamPtr = <T = void>(...args: Array<string | ((...args: Array<number>) => T)>): T => {
const params = [...args];
const fn = params.pop()!;
const paramsPtr = params.map((param: string) => allocateUTF8(param));
const ret = (fn as Function)(...paramsPtr);
paramsPtr.forEach(paramPtr => _free(paramPtr));
return ret;

@@ -50,16 +56,18 @@ };

create: (affPath: string, dictPath: string) => {
const hunspellPtr = hunspellInterface.create(allocString(affPath), allocString(dictPath));
const affPathPtr = allocateUTF8(affPath);
const dictPathPtr = allocateUTF8(dictPath);
const hunspellPtr = hunspellInterface.create(affPathPtr, dictPathPtr);
return {
dispose: () => hunspellInterface.destroy(hunspellPtr),
spell: (word: string) => {
//let allocated string volatile via manually save / restore stacks, instead of malloc / free
const stack = stackSave();
const ret = hunspellInterface.spell(hunspellPtr, allocString(word));
stackRestore(stack);
return !!ret;
dispose: () => {
hunspellInterface.destroy(hunspellPtr);
_free(affPathPtr);
_free(dictPathPtr);
},
spell: (word: string) => !!usingParamPtr(word, wordPtr => hunspellInterface.spell(hunspellPtr, wordPtr)),
suggest: (word: string) => {
const stack = stackSave();
const suggestionListPtr = stackAlloc(4);
const suggestionCount = hunspellInterface.suggest(hunspellPtr, suggestionListPtr, allocString(word));
const suggestionCount = usingParamPtr(word, wordPtr =>
hunspellInterface.suggest(hunspellPtr, suggestionListPtr, wordPtr)
);
const suggestionListValuePtr = getValue(suggestionListPtr, '*');

@@ -75,6 +83,15 @@

hunspellInterface.free_list(hunspellPtr, suggestionListPtr, suggestionCount);
stackRestore(stack);
return ret;
}
},
addDictionary: (dictPath: string) =>
usingParamPtr(dictPath, dictPathPtr => hunspellInterface.add_dic(hunspellPtr, dictPathPtr)) === 1
? false
: true,
addWord: (word: string) => usingParamPtr(word, wordPtr => hunspellInterface.add(hunspellPtr, wordPtr)),
addWordWithAffix: (word: string, affix: string) =>
usingParamPtr(word, affix, (wordPtr, affixPtr) =>
hunspellInterface.add_with_affix(hunspellPtr, wordPtr, affixPtr)
),
removeWord: (word: string) => usingParamPtr(word, wordPtr => hunspellInterface.remove(hunspellPtr, wordPtr))
};

@@ -81,0 +98,0 @@ }

@@ -16,9 +16,26 @@ import { cwrapSignature } from './HunspellAsmModule';

//int Hunspell_suggest(Hunhandle* pHunspell, char*** slst, const char* word);
suggest: cwrap<
(hunspellPtr: number, outSuggestionListPtr: number, value: number) => number
>('Hunspell_suggest', 'number', ['number', 'number', 'number']),
suggest: cwrap<(hunspellPtr: number, outSuggestionListPtr: number, value: number) => number>(
'Hunspell_suggest',
'number',
['number', 'number', 'number']
),
//void Hunspell_free_list(Hunhandle* pHunspell, char*** slst, int n);
free_list: cwrap<
(hunspellPtr: number, suggestionListPtr: number, count: number) => void
>('Hunspell_free_list', null, ['number', 'number', 'number'])
free_list: cwrap<(hunspellPtr: number, suggestionListPtr: number, count: number) => void>(
'Hunspell_free_list',
null,
['number', 'number', 'number']
),
//0 = additional dictionary slots available, 1 = slots are now full
//int Hunspell_add_dic(Hunhandle* pHunspell, const char* dpath);
add_dic: cwrap<(hunspellPtr: number, dicPath: number) => number>('Hunspell_add_dic', 'number', ['number', 'number']),
//int Hunspell_add(Hunhandle* pHunspell, const char* word);
add: cwrap<(hunspellPtr: number, value: number) => number>('Hunspell_add', 'number', ['number', 'number']),
//int Hunspell_add_with_affix(Hunhandle* pHunspell, const char* word, const char* example);
add_with_affix: cwrap<(hunspellPtr: number, value: number, affix: number) => number>(
'Hunspell_add_with_affix',
'number',
['number', 'number', 'number']
),
//int Hunspell_remove(Hunhandle* pHunspell, const char* word);
remove: cwrap<(hunspellPtr: number, value: number) => number>('Hunspell_remove', 'number', ['number', 'number'])
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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