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 0.0.9 to 0.0.10

5

CHANGELOG.md

@@ -0,1 +1,6 @@

<a name="0.0.10"></a>
## [0.0.10](https://github.com/kwonoj/hunspell-asm/compare/v0.0.9...v0.0.10) (2017-09-12)
<a name="0.0.9"></a>

@@ -2,0 +7,0 @@ ## [0.0.9](https://github.com/kwonoj/hunspell-asm/compare/v0.0.8...v0.0.9) (2017-09-10)

@@ -0,5 +1,25 @@

/**
* Interface for hunspell spellchecker.
*
*/
export interface Hunspell {
/**
* Dispose current instance.
* This should be called to free object created via `HunspellFactory::create`
* once it's not being used anymore.
*
*/
dispose: () => void;
/**
* Check spell for given word using current hunspell instance.
*
* @returns {boolean} false for misspelled, true otherwise.
*/
spell: (word: string) => boolean;
/**
* Get suggestion list for given word using current hunspell instance.
* This'll return suggestion list only if word is misspelled one, otherwise
* returns empty array.
*/
suggest: (word: string) => Array<string>;
}
/// <reference types="node" />
import fsType = require('fs');
/** @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;
/** @internal */
export declare type FILESYSTEMS = {

@@ -9,2 +12,6 @@ NODEFS: any;

};
/**
* Subset of internal filesystem api for wasm module.
*/
/** @internal */
export declare type FS = {

@@ -27,2 +34,7 @@ filesystems: FILESYSTEMS;

};
/**
* Interface for module generated by emscripten to load wasm binary.
* https://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html
*/
/** @internal */
export interface HunspellAsmModule {

@@ -29,0 +41,0 @@ cwrap: cwrapSignature;

import { Hunspell } from './Hunspell';
/**
* Interface for factory function for mounting files into wasm filesystem
* and creating hunspell instance.
*
*/
export interface HunspellFactory {
/**
* (Node.js only) Mount physical directory into hunspell loader's in-memory filesystem path.
* Once it's mounted, hunspell can access physical file with generated in-memory path.
*
* @param {string} dirPath Absoulte path to directory to mount.
*
* @return {string} In-memory mounted path for given phsysical path.
* This path uses unix separator *regardless of platform*
*/
mountDirectory: (dirPath: string) => string;
/**
* Mount a file into hunspell loader's in-memory filesystem path.
*
* @param {ArrayBufferView} contents Contents of file to be mounted.
* @param {string} [fileName] Name of file. If not specified, will be generated randomly.
*
* @return {string} Path to in-memory mounted file.
* This path uses unix separator *regardless of platform*
*/
mountBuffer: (contents: ArrayBufferView, fileName?: string) => string;
/**
* Unmount file / path from in-memory filesystem.
* If given path is physical directory path, it'll be simply unmounted.
* If given path is in-memory file mounted via `mountBuffer`, it'll be removed.
*
* @param {string} mountedFilePath path to unmount
*/
unmount: (mountedFilePath: string) => void;
/**
* Creates new hunspell dictionary instance.
*
* @param {string} affPath In-memory file path to aff file. Path should use unix separator.
* @param {string} dictPath In-memory file path to dic file. Path should use unix separator.
*
* @return {Hunspell} Hunspell dictionary instance created.
*/
create: (affPath: string, dictPath: string) => Hunspell;
}
import { HunspellAsmModule } from './HunspellAsmModule';
import { HunspellFactory } from './HunspellFactory';
/**
* Creates a factory function for mounting files into wasm filesystem
* and creating hunspell instance.
*
* @param {HunspellAsmModule} asmModule wasm / asm module loaded into memory.
*
* @return {HunspellFactory} factory function for mounting files and creating hunspell instance.
*/
/** @internal */
export declare const hunspellLoader: (asmModule: HunspellAsmModule) => HunspellFactory;

@@ -10,5 +10,15 @@ "use strict";

var wrapHunspellInterface_1 = require("./wrapHunspellInterface");
/**
* Creates a factory function for mounting files into wasm filesystem
* and creating hunspell instance.
*
* @param {HunspellAsmModule} asmModule wasm / asm module loaded into memory.
*
* @return {HunspellFactory} factory function for mounting files and creating hunspell instance.
*/
/** @internal */
exports.hunspellLoader = function (asmModule) {
var cwrap = asmModule.cwrap, FS = asmModule.FS, stringToUTF8 = asmModule.stringToUTF8, Runtime = asmModule.Runtime, getValue = asmModule.getValue, Pointer_stringify = asmModule.Pointer_stringify;
var hunspellInterface = wrapHunspellInterface_1.wrapHunspellInterface(cwrap);
//creating top-level path to mount files
var memPathId = "/" + nanoid(45);

@@ -37,2 +47,3 @@ FS.mkdir(memPathId);

spell: function (word) {
//let allocated string volatile via manually save / restore stacks, instead of malloc / free
var stack = Runtime.stackSave();

@@ -39,0 +50,0 @@ var ret = hunspellInterface.spell(hunspellPtr, allocString(word));

import { FS } from './HunspellAsmModule';
/**
* Check if given mount path is already mounted
*
* @param {FS} FS wasm module filesystem
* @param {string} mountPath path to wasm filesystem
* @param {dir | file} type type of mountPath
*
* @returns {boolean} true if mounted, false otherwise or error occurred
*/
/** @internal */
export declare const isMounted: (FS: FS, mountPath: string, type: "dir" | "file") => boolean;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var logger_1 = require("./util/logger");
/**
* Check if given mount path is already mounted
*
* @param {FS} FS wasm module filesystem
* @param {string} mountPath path to wasm filesystem
* @param {dir | file} type type of mountPath
*
* @returns {boolean} true if mounted, false otherwise or error occurred
*/
/** @internal */
exports.isMounted = function (FS, mountPath, type) {

@@ -5,0 +15,0 @@ try {

import { HunspellFactory } from './HunspellFactory';
/**
* Asynchronously load and initialize asm module.
*
* @param {string} [binaryEndpoint] Provides endpoint to server to download binary module
* (.wasm, .mem) via fetch when initialize module in a browser environment.
*
* @returns {HunspellFactory} Factory function manages lifecycle of hunspell and virtual files.
*/
export declare const loadModule: (binaryEndpoint?: string | undefined) => Promise<HunspellFactory>;

12

dist/src/loadModule.js

@@ -9,2 +9,10 @@ "use strict";

var logger_1 = require("./util/logger");
/**
* Asynchronously load and initialize asm module.
*
* @param {string} [binaryEndpoint] Provides endpoint to server to download binary module
* (.wasm, .mem) via fetch when initialize module in a browser environment.
*
* @returns {HunspellFactory} Factory function manages lifecycle of hunspell and virtual files.
*/
exports.loadModule = function (binaryEndpoint) { return tslib_1.__awaiter(_this, void 0, void 0, function () {

@@ -29,7 +37,7 @@ var asmType, moduleLoader, asmModule;

: moduleLoader();
return [4, asmModule.initializeRuntime()];
return [4 /*yield*/, asmModule.initializeRuntime()];
case 1:
_a.sent();
logger_1.log("loadModule: initialized hunspell Runtime");
return [2, hunspellLoader_1.hunspellLoader(asmModule)];
return [2 /*return*/, hunspellLoader_1.hunspellLoader(asmModule)];
}

@@ -36,0 +44,0 @@ });

import { FS } from './HunspellAsmModule';
/**
* `mkdir -p` implementation for wasm FS.mkdir interface.
* dirPath param should be unixified.
*/
/** @internal */
export declare const mkdirTree: (FS: FS, dirPath: string) => void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* `mkdir -p` implementation for wasm FS.mkdir interface.
* dirPath param should be unixified.
*/
/** @internal */
exports.mkdirTree = function (FS, dirPath) {

@@ -9,2 +14,3 @@ var mkdir = function (path) {

catch (e) {
//throw if not ERRNO_CODES.EEXIST
if (e.errno != 17) {

@@ -11,0 +17,0 @@ throw e;

import { FS } from './HunspellAsmModule';
/**
* Creates a function to mount contents of file into wasm internal memory filesystem
* to allow wasm can access.
*
* @param {FS} FS wasm module filesystem
* @param {string} memPathId root path in memory filesystem to mount given arrayBuffer.
* This prefix path is generated automatically each time wasm module is loaded.
*
* @return {(contents: ArrayBufferView, fileName?: string) => string} function to mount buffer under memory filesystem.
* If filename is not provided, it'll be generated automatically. This function checks existing file mounted via filename,
* does not validate contents of buffer to find out already mounted one.
*/
/** @internal */
export declare const mountBuffer: (FS: FS, memPathId: string) => (contents: ArrayBufferView, fileName?: string | undefined) => string;

@@ -6,2 +6,15 @@ "use strict";

var logger_1 = require("./util/logger");
/**
* Creates a function to mount contents of file into wasm internal memory filesystem
* to allow wasm can access.
*
* @param {FS} FS wasm module filesystem
* @param {string} memPathId root path in memory filesystem to mount given arrayBuffer.
* This prefix path is generated automatically each time wasm module is loaded.
*
* @return {(contents: ArrayBufferView, fileName?: string) => string} function to mount buffer under memory filesystem.
* If filename is not provided, it'll be generated automatically. This function checks existing file mounted via filename,
* does not validate contents of buffer to find out already mounted one.
*/
/** @internal */
exports.mountBuffer = function (FS, memPathId) { return function (contents, fileName) {

@@ -8,0 +21,0 @@ var file = fileName || nanoid(45);

import { FS } from './HunspellAsmModule';
/**
* Creates a function to mount phsyical path into wasm internal memory filesystem
* to allow wasm can access phsyical file directly.
*
* @param {FS} FS wasm module filesystem
* @param {string} nodePathId root path in memory filesystem to mount given path under.
* This prefix path is generated automatically each time wasm module is loaded.
*
* @return {(dirPath: string) => string} function to mount given phsical path under memory filesystem.
*/
/** @internal */
export declare const mountDirectory: (FS: FS, nodePathId: string) => (dirPath: string) => string;

@@ -8,2 +8,13 @@ "use strict";

var logger_1 = require("./util/logger");
/**
* Creates a function to mount phsyical path into wasm internal memory filesystem
* to allow wasm can access phsyical file directly.
*
* @param {FS} FS wasm module filesystem
* @param {string} nodePathId root path in memory filesystem to mount given path under.
* This prefix path is generated automatically each time wasm module is loaded.
*
* @return {(dirPath: string) => string} function to mount given phsical path under memory filesystem.
*/
/** @internal */
exports.mountDirectory = function (FS, nodePathId) { return function (dirPath) {

@@ -13,3 +24,3 @@ if (!isNode_1.isNode()) {

}
var path = require('path');
var path = require('path'); //tslint:disable-line:no-require-imports
var mountedDirPath = unixify(path.join(nodePathId, unixify(path.resolve(dirPath))));

@@ -16,0 +27,0 @@ if (isMounted_1.isMounted(FS, mountedDirPath, 'dir')) {

import { FS } from './HunspellAsmModule';
/**
* Creates a function to unmount file or directory in wasm internal memory filesystem
* If given mounted path prefix is pointing internal buffer file mounted via `mountBuffer`,
* it'll be removed. Otherwise it'll be unmounted and remove internal directory.
*
* @param {FS} FS wasm module filesystem
* @param {string} memPathId root path in memory filesystem to determine given unmount path is physical directory or buffer.
* This prefix path is generated automatically each time wasm module is loaded.
*
* @return {(mountedPath: string) => void} function to unmount given path under memory filesystem.
*/
/** @internal */
export declare const unmount: (FS: FS, memPathId: string) => (mountedPath: string) => void;

@@ -5,2 +5,14 @@ "use strict";

var logger_1 = require("./util/logger");
/**
* Creates a function to unmount file or directory in wasm internal memory filesystem
* If given mounted path prefix is pointing internal buffer file mounted via `mountBuffer`,
* it'll be removed. Otherwise it'll be unmounted and remove internal directory.
*
* @param {FS} FS wasm module filesystem
* @param {string} memPathId root path in memory filesystem to determine given unmount path is physical directory or buffer.
* This prefix path is generated automatically each time wasm module is loaded.
*
* @return {(mountedPath: string) => void} function to unmount given path under memory filesystem.
*/
/** @internal */
exports.unmount = function (FS, memPathId) { return function (mountedPath) {

@@ -7,0 +19,0 @@ if (isMounted_1.isMounted(FS, mountedPath, 'file') && mountedPath.indexOf(memPathId) > -1) {

@@ -0,1 +1,4 @@

/**
* Naïvely detect if running environment if node
*/
export declare const isNode: () => boolean;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var getroot_1 = require("getroot");
/**
* Naïvely detect if running environment if node
*/
exports.isNode = function () {

@@ -5,0 +8,0 @@ var proc = getroot_1.root.process;

@@ -0,1 +1,4 @@

/**
* Naïvely check if current runtime supports native web assembly.
*/
export declare const isWasmEnabled: () => boolean;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var getroot_1 = require("getroot");
/**
* Naïvely check if current runtime supports native web assembly.
*/
exports.isWasmEnabled = function () { return !!getroot_1.root.WebAssembly && !!getroot_1.root.WebAssembly.compile && !!getroot_1.root.WebAssembly.instantiate; };
//# sourceMappingURL=isWasmEnabled.js.map
declare type logFunctionType = (message: string, ...optionalParams: Array<any>) => void;
declare const log: logFunctionType;
/**
* Enables logging internal behavior of hunspell-asm.
* @param logger function to log.
*/
declare const enableLogger: (logger: (message: string, ...optionalParams: any[]) => void) => (message: string, ...optionalParams: any[]) => void;
export { enableLogger, logFunctionType, log };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Default log instance falls back to noop if not specified.
*/
var logInstance = function () {
/* noop */
};

@@ -13,4 +17,8 @@ var log = function () {

exports.log = log;
/**
* Enables logging internal behavior of hunspell-asm.
* @param logger function to log.
*/
var enableLogger = function (logger) { return (logInstance = logger); };
exports.enableLogger = enableLogger;
//# sourceMappingURL=logger.js.map
import { cwrapSignature } from './HunspellAsmModule';
/**
* Wrap hunspell exported interfaces via cwrap for resuable mannter.
*
*/
/** @internal */
export declare const wrapHunspellInterface: (cwrap: cwrapSignature) => {

@@ -3,0 +8,0 @@ create: (affPath: number, dicPath: number) => number;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Wrap hunspell exported interfaces via cwrap for resuable mannter.
*
*/
/** @internal */
exports.wrapHunspellInterface = function (cwrap) { return ({
//Hunhandle* Hunspell_create(const char* affpath, const char* dpath)
create: cwrap('Hunspell_create', 'number', ['number', 'number']),
//void Hunspell_destroy(Hunhandle* pHunspell)
destroy: cwrap('Hunspell_destroy', null, ['number']),
//int Hunspell_spell(Hunhandle* pHunspell, const char*)
spell: cwrap('Hunspell_spell', 'number', ['number', 'number']),
//int Hunspell_suggest(Hunhandle* pHunspell, char*** slst, const char* word);
suggest: cwrap('Hunspell_suggest', 'number', ['number', 'number', 'number']),
//void Hunspell_free_list(Hunhandle* pHunspell, char*** slst, int n);
free_list: cwrap('Hunspell_free_list', null, ['number', 'number', 'number'])
}); };
//# sourceMappingURL=wrapHunspellInterface.js.map

2

package.json
{
"name": "hunspell-asm",
"version": "0.0.9",
"version": "0.0.10",
"description": "WebAssembly based Javascript bindings for hunspell spellchecker",

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

{
"compilerOptions": {
"removeComments": true,
"preserveConstEnums": true,

@@ -5,0 +4,0 @@ "sourceMap": true,

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

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