Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
hunspell-asm
Advanced tools
Hunspell-asm
is isomorphic javascript binding to hunspell spellchecker based on WebAssembly hunspell binary. This module aims to provide thin, lightweight interface to hunspell without requiring native modules.
npm install hunspell-asm
Hunspell-asm
relies on wasm binary of hunspell, which need to be initialized first.
import { loadModule } from 'hunspell-asm';
const hunspellFactory = await loadModule();
loadModule
loads wasm binary, initialize it, and returns factory function to create instance of hunspell.
loadModule({timeout?: number, locateBinary?: (wasmPath: string) => string | object}): Promise<HunspellFactory>
It allows to specify timeout to wait until wasm binary compliation & load, also allows to override to lookup binary of wasm. Based on environment & bundling configurations, it is not sufficient to rely on default resolution logic. locateBinary
expects to return path of binary (i.e remote endpoint url) or loader-specific object if it's bundled by bundler. Check examples for usecases.
Wasm binary uses different memory spaces allocated for its own and cannot access plain javascript object / or files directly. HunspellFactory
provides few interfaces to interop physical file, or file contents into hunspell.
mountDirectory(dirPath: string): string
: (node.js only) Mount physical path. Once directory is mounted hunspell can read all files under mounted path. Returns virtual
path to mounted path.mountBuffer(contents: ArrayBufferView, fileName?: string): string
: Mount contents of file. Environment like browser which doesn't have access to filesystem can use this interface to create each file into memory.unmount(mountedFilePath: string)
: Unmount path if it's exists in memory. If it's bufferFile created by mountBuffer
, unmount will remove those file object in wasm memory as well.All of virtual
paths for mounted filesystem uses unix separator regardless of platform.
Once you mounted dic / aff files you can create hunspell spellchecker instance via HunspellFactory::create
. Each path for files are mounted path and should not be actual path or server endpoint.
create(affPath: string, dictPath: string): Hunspell
Hunspell
exposes minimal interfaces to spellchecker.
spell(word: string): boolean
: Check spelling for word. False for misspelled, True otherwise.suggest(word: string): Array<string>
: Get suggestion list for misspelled word. Empty if word is not misspelled or no suggestions.dispose(): void
: Destroy current instance of hunspell. It is important to note created instance of hunspell will not be destroyed automatically.There are simple examples for each environments using different apis. In each example directory do npm install && npm start
.
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.Few npm scripts are supported for build / test code.
build
: Transpiles code to ES5 commonjs to dist
.test
: Run hunspell
/ hunspell-asm
test both. Does not require build
before execute test.test:hunspell
: Run integration test for actual hunspell wasm binary, using hunspell's test case as-is.test:hunspell-asm
: Run unit test against hunspell-asm
interfacelint
: Run lint over all codebaseslint:staged
: Run lint only for staged changes. This'll be executed automatically with precommit hook.commit
: Commit wizard to write commit message2.0.0-beta.3 (2019-01-26)
<a name="2.0.0-beta.2"></a>
FAQs
WebAssembly based Javascript bindings for hunspell spellchecker
The npm package hunspell-asm receives a total of 1,142 weekly downloads. As such, hunspell-asm popularity was classified as popular.
We found that hunspell-asm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.