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

cld3-asm

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cld3-asm - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

dist/esm/tsconfig.types.tsbuildinfo

10

CHANGELOG.md

@@ -0,1 +1,11 @@

<a name="2.0.1"></a>
## [2.0.1](https://github.com/kwonoj/cld3-asm/compare/v2.0.0...v2.0.1) (2019-06-10)
### Features
* **index:** reexport environment ([9eae6e9](https://github.com/kwonoj/cld3-asm/commit/9eae6e9))
<a name="2.0.0"></a>

@@ -2,0 +12,0 @@ # [2.0.0](https://github.com/kwonoj/cld3-asm/compare/v2.0.0-beta.6...v2.0.0) (2019-03-01)

2

dist/cjs/index.js

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

exports.LanguageCode = languageCode_1.LanguageCode;
var emscripten_wasm_loader_1 = require("emscripten-wasm-loader");
exports.ENVIRONMENT = emscripten_wasm_loader_1.ENVIRONMENT;
//# sourceMappingURL=index.js.map
"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());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var emscripten_wasm_loader_1 = require("emscripten-wasm-loader");

@@ -21,5 +55,5 @@ var cldLoader_1 = require("./cldLoader");

if (initOptions === void 0) { initOptions = {}; }
return tslib_1.__awaiter(_this, void 0, void 0, function () {
return __awaiter(_this, void 0, void 0, function () {
var runtime, environment, timeout, env, overriddenModule, moduleLoader;
return tslib_1.__generator(this, function (_a) {
return __generator(this, function (_a) {
switch (_a.label) {

@@ -26,0 +60,0 @@ case 0:

88

dist/esm/cldLoader.js
import { log } from './util/logger';
import { wrapCldInterface } from './wrapCldInterface';
// size of pointer to calculate pointer position.
var PTR_SIZE = 4;
const PTR_SIZE = 4;
/**

@@ -14,5 +14,5 @@ * @internal

*/
export var cldLoader = function (asmModule, _environment) {
var cwrap = asmModule.cwrap, _free = asmModule._free, allocateUTF8 = asmModule.allocateUTF8, _malloc = asmModule._malloc, getValue = asmModule.getValue, Pointer_stringify = asmModule.Pointer_stringify, setValue = asmModule.setValue;
var cldInterface = wrapCldInterface(cwrap);
export const cldLoader = (asmModule, _environment) => {
const { cwrap, _free, allocateUTF8, _malloc, getValue, Pointer_stringify, setValue } = asmModule;
const cldInterface = wrapCldInterface(cwrap);
/**

@@ -22,30 +22,26 @@ * Naive auto-dispose interface to call cld 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); });
const usingParamPtr = (...args) => {
const params = [...args];
const fn = params.pop();
const paramsPtr = params.map((param) => allocateUTF8(param));
const ret = fn(...paramsPtr);
paramsPtr.forEach(paramPtr => _free(paramPtr));
return ret;
};
// grab constant values from cld3 library
var unknownIdentifier = Pointer_stringify(cldInterface.getUnknownIdentifier());
var minBytesDefault = cldInterface.getMinNumBytesDefault();
var maxBytesDefault = cldInterface.getMaxNumBytesDefault();
var maxBytesInput = cldInterface.getMaxNumBytesInput();
var languageResultStructSize = cldInterface.sizeLanguageResult();
log("cldLoader: cld3 wasm initialized with default values", {
unknownIdentifier: unknownIdentifier,
minBytesDefault: minBytesDefault,
maxBytesDefault: maxBytesDefault,
maxBytesInput: maxBytesInput,
languageResultStructSize: languageResultStructSize
const unknownIdentifier = Pointer_stringify(cldInterface.getUnknownIdentifier());
const minBytesDefault = cldInterface.getMinNumBytesDefault();
const maxBytesDefault = cldInterface.getMaxNumBytesDefault();
const maxBytesInput = cldInterface.getMaxNumBytesInput();
const languageResultStructSize = cldInterface.sizeLanguageResult();
log(`cldLoader: cld3 wasm initialized with default values`, {
unknownIdentifier,
minBytesDefault,
maxBytesDefault,
maxBytesInput,
languageResultStructSize
});
// both identifier should match all time, check when initialize binary
if (unknownIdentifier !== "und" /* UNKNOWN */) {
throw new Error("cld3 binary unknownIdentifier constant does not match to LanguageCode enum");
throw new Error(`cld3 binary unknownIdentifier constant does not match to LanguageCode enum`);
}

@@ -58,7 +54,7 @@ /**

*/
var volatileReadResultStruct = function (structPtr) {
const volatileReadResultStruct = (structPtr) => {
// get value of first field of LanguageResult struct (char*)
var languageStringPtr = getValue(structPtr + PTR_SIZE * 0, '*');
const languageStringPtr = getValue(structPtr + PTR_SIZE * 0, '*');
// be careful to match order of properties to match pointer to struct field.
var ret = {
const ret = {
language: Pointer_stringify(languageStringPtr),

@@ -76,21 +72,19 @@ probability: getValue(structPtr + PTR_SIZE * 1, 'float'),

return {
create: function (minBytes, maxBytes) {
if (minBytes === void 0) { minBytes = minBytesDefault; }
if (maxBytes === void 0) { maxBytes = maxBytesDefault; }
var cldPtr = cldInterface.create(minBytes, maxBytes);
create: (minBytes = minBytesDefault, maxBytes = maxBytesDefault) => {
const cldPtr = cldInterface.create(minBytes, maxBytes);
return {
findLanguage: function (text) {
findLanguage: (text) => {
// `findLanguage` requires caller must allocate memory for return value.
var resultPtr = _malloc(languageResultStructSize);
usingParamPtr(text, function (textPtr) { return cldInterface.findLanguage(cldPtr, textPtr, resultPtr); });
const resultPtr = _malloc(languageResultStructSize);
usingParamPtr(text, textPtr => cldInterface.findLanguage(cldPtr, textPtr, resultPtr));
return volatileReadResultStruct(resultPtr);
},
findMostFrequentLanguages: function (text, numLangs) {
findMostFrequentLanguages: (text, numLangs) => {
// `findMostFrequentLanguages` requires caller must allocate memory for return value.
var languageListPtr = _malloc(numLangs * PTR_SIZE);
const languageListPtr = _malloc(numLangs * PTR_SIZE);
// For convinience, we'll store allocated pointer to each empty LanguageResult for return value
var resultStructsPtr = [];
const resultStructsPtr = [];
//allocate memory in js. `findTopNMostFreqLangs` always returns vector with given num_langs, allows predictable memory allocation.
for (var idx = 0; idx < numLangs; idx++) {
var resultPtr = _malloc(languageResultStructSize);
for (let idx = 0; idx < numLangs; idx++) {
const resultPtr = _malloc(languageResultStructSize);
resultStructsPtr.push(resultPtr);

@@ -100,9 +94,7 @@ // fill in array with allocated struct ptr

}
var languageCount = usingParamPtr(text, function (textPtr) {
return cldInterface.findTopNMostFreqLangs(cldPtr, textPtr, numLangs, languageListPtr);
});
const languageCount = usingParamPtr(text, textPtr => cldInterface.findTopNMostFreqLangs(cldPtr, textPtr, numLangs, languageListPtr));
// if `numLangs` exceeds number of languages detected rest of array will be filled with default result with unknown language identifier
var ret = resultStructsPtr
.map(function (ptr) { return volatileReadResultStruct(ptr); })
.filter(function (x) { return x.language !== unknownIdentifier; });
const ret = resultStructsPtr
.map(ptr => volatileReadResultStruct(ptr))
.filter(x => x.language !== unknownIdentifier);
// each LanguageResult struct is freed via `volatileReadResultStruct` already. delete allocated memory for array itself.

@@ -112,3 +104,3 @@ _free(languageListPtr);

},
dispose: function () { return cldInterface.destroy(cldPtr); }
dispose: () => cldInterface.destroy(cldPtr)
};

@@ -115,0 +107,0 @@ }

export { loadModule } from './loadModule';
export { log, enableLogger } from './util/logger';
export { LanguageCode } from './languageCode';
export { ENVIRONMENT } from 'emscripten-wasm-loader';
//# sourceMappingURL=index.js.map

@@ -1,3 +0,1 @@

var _this = this;
import * as tslib_1 from "tslib";
import { ENVIRONMENT, getModuleLoader, isNode } from 'emscripten-wasm-loader';

@@ -17,23 +15,17 @@ import { cldLoader } from './cldLoader';

*/
var loadModule = function (initOptions) {
if (initOptions === void 0) { initOptions = {}; }
return tslib_1.__awaiter(_this, void 0, void 0, function () {
var runtime, environment, timeout, env, overriddenModule, moduleLoader;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
runtime = require("./lib/cld3");
environment = initOptions.environment, timeout = initOptions.timeout;
env = environment ? environment : isNode() ? ENVIRONMENT.NODE : ENVIRONMENT.WEB;
log("loadModule: loading cld3 wasm binary", { initOptions: initOptions });
overriddenModule = { ENVIRONMENT: env };
return [4 /*yield*/, getModuleLoader(function (runtime) { return cldLoader(runtime, env); }, runtime, overriddenModule, { timeout: timeout })];
case 1:
moduleLoader = _a.sent();
return [2 /*return*/, moduleLoader()];
}
});
});
const loadModule = async (initOptions = {}) => {
//imports MODULARIZED emscripten preamble
//tslint:disable-next-line:no-require-imports no-var-requires
const runtime = require(`./lib/cld3`);
const { environment, timeout } = initOptions;
const env = environment ? environment : isNode() ? ENVIRONMENT.NODE : ENVIRONMENT.WEB;
log(`loadModule: loading cld3 wasm binary`, { initOptions });
//https://github.com/kwonoj/docker-hunspell-wasm/issues/63
//Build module object to construct wasm binary module via emscripten preamble.
//apply overridden environment values to custom patched hunspell preamble.
const overriddenModule = { ENVIRONMENT: env };
const moduleLoader = await getModuleLoader((runtime) => cldLoader(runtime, env), runtime, overriddenModule, { timeout });
return moduleLoader();
};
export { loadModule };
//# sourceMappingURL=loadModule.js.map

@@ -5,12 +5,6 @@ import { enableLogger as emscriptenEnableLogger } from 'emscripten-wasm-loader';

*/
var logInstance = function () {
let logInstance = () => {
/* noop */
};
var log = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return logInstance.apply(void 0, args);
};
const log = (...args) => logInstance(...args);
/**

@@ -20,14 +14,10 @@ * Enables logging internal behavior of cld3-asm.

*/
var enableLogger = function (logger) {
var scopedLogger = function (scope) { return function (message) {
var optionalParams = [];
for (var _i = 1; _i < arguments.length; _i++) {
optionalParams[_i - 1] = arguments[_i];
}
logger.apply(void 0, [scope + "::" + message].concat(optionalParams));
}; };
logInstance = scopedLogger("cld3");
emscriptenEnableLogger(scopedLogger("cld3Loader"));
const enableLogger = (logger) => {
const scopedLogger = (scope) => (message, ...optionalParams) => {
logger(`${scope}::${message}`, ...optionalParams);
};
logInstance = scopedLogger(`cld3`);
emscriptenEnableLogger(scopedLogger(`cld3Loader`));
};
export { enableLogger, log };
//# sourceMappingURL=logger.js.map

@@ -6,3 +6,3 @@ /**

*/
export var wrapCldInterface = function (cwrap) { return ({
export const wrapCldInterface = (cwrap) => ({
/**

@@ -58,3 +58,3 @@ * get size of struct for interop.

findTopNMostFreqLangs: cwrap('Cld_findTopNMostFreqLangs', 'number', ['number', 'number', 'number', 'number'])
}); };
});
//# sourceMappingURL=wrapCldInterface.js.map

@@ -6,2 +6,3 @@ export { loadModule } from './loadModule';

export { LanguageCode } from './languageCode';
export { ENVIRONMENT } from 'emscripten-wasm-loader';
//# sourceMappingURL=index.d.ts.map
{
"name": "cld3-asm",
"version": "2.0.0",
"version": "2.0.1",
"description": "WebAssembly based Javascript bindings for google compact language detector 3",

@@ -56,33 +56,32 @@ "main": "./dist/cjs/index.js",

"devDependencies": {
"@commitlint/cli": "^7.5.2",
"@commitlint/config-angular": "^7.5.0",
"@commitlint/cli": "^8.0.0",
"@commitlint/config-angular": "^8.0.0",
"@types/chai": "^4.1.7",
"@types/jest": "^23.3.14",
"@types/lodash": "^4.14.121",
"@types/node": "^10.12.27",
"@types/shelljs": "^0.8.3",
"@types/jest": "^24.0.13",
"@types/lodash": "^4.14.134",
"@types/node": "^12.0.7",
"@types/shelljs": "^0.8.5",
"@types/utf8": "^2.1.6",
"chai": "^4.2.0",
"commitizen": "3.0.4",
"conventional-changelog-cli": "^2.0.12",
"commitizen": "^3.1.1",
"conventional-changelog-cli": "^2.0.21",
"cz-conventional-changelog": "2.1.0",
"husky": "^1.3.1",
"jest": "^23.6.0",
"husky": "^2.4.0",
"jest": "^24.8.0",
"jest-spin-reporter": "^1.0.2",
"lint-staged": "^8.1.5",
"lint-staged": "^8.2.0",
"lodash": "^4.17.11",
"npm-run-all": "^4.1.5",
"prettier": "^1.16.4",
"prettier": "^1.18.2",
"shelljs": "^0.8.3",
"shx": "^0.3.2",
"ts-jest": "^23.10.5",
"ts-node": "^7.0.1",
"tslint": "^5.13.1",
"ts-jest": "^24.0.2",
"ts-node": "^8.2.0",
"tslint": "^5.17.0",
"tslint-no-unused-expression-chai": "^0.1.4",
"typescript": "^3.3.3333",
"typescript": "^3.5.1",
"utf8": "^3.0.0"
},
"dependencies": {
"emscripten-wasm-loader": "^2.2.3",
"tslib": "^1.9.3"
"emscripten-wasm-loader": "^2.2.3"
},

@@ -89,0 +88,0 @@ "husky": {

@@ -6,1 +6,2 @@ export { loadModule } from './loadModule';

export { LanguageCode } from './languageCode';
export { ENVIRONMENT } from 'emscripten-wasm-loader';

@@ -5,4 +5,5 @@ {

"module": "esnext",
"target": "es2018",
"outDir": "../dist/esm",
}
}

@@ -5,3 +5,3 @@ {

"module": "es2015",
"target": "esnext",
"target": "es2018",
"declaration": true,

@@ -8,0 +8,0 @@ "declarationDir": "../dist/types",

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