Comparing version 1.3.1 to 2.0.0
"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()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const OnigasmModuleFactory = require('./onigasm.js' /** when TS is compiled to JS, this will mean `lib/onigasm.js` (emitted by `emcc`) */); | ||
function initModule(bytes) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return new Promise((resolve, reject) => { | ||
OnigasmModuleFactory({ | ||
instantiateWasm(imports, successCallback) { | ||
WebAssembly.instantiate(bytes, imports) | ||
.then((output) => { | ||
successCallback(output.instance); | ||
}) | ||
.catch((e) => { | ||
throw e; | ||
}); | ||
return {}; | ||
} | ||
}) | ||
.then(moduleH => { | ||
exports.onigasmH = moduleH; | ||
resolve(); | ||
}); | ||
async function initModule(bytes) { | ||
return new Promise((resolve, reject) => { | ||
OnigasmModuleFactory({ | ||
instantiateWasm(imports, successCallback) { | ||
WebAssembly.instantiate(bytes, imports) | ||
.then((output) => { | ||
successCallback(output.instance); | ||
}) | ||
.catch((e) => { | ||
throw e; | ||
}); | ||
return {}; | ||
} | ||
}) | ||
.then(moduleH => { | ||
exports.onigasmH = moduleH; | ||
resolve(); | ||
}); | ||
@@ -39,21 +29,19 @@ }); | ||
*/ | ||
function loadWASM(data) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (isInitialized) { | ||
throw new Error(`Onigasm#init has been called and was succesful, subsequent calls are not allowed once initialized`); | ||
} | ||
if (typeof data === 'string') { | ||
const arrayBuffer = yield (yield fetch(data)).arrayBuffer(); | ||
yield initModule(arrayBuffer); | ||
} | ||
else if (data instanceof ArrayBuffer) { | ||
yield initModule(data); | ||
} | ||
else { | ||
throw new TypeError(`Expected a string (URL of .wasm file) or ArrayBuffer (.wasm file itself) as first parameter`); | ||
} | ||
isInitialized = true; | ||
}); | ||
async function loadWASM(data) { | ||
if (isInitialized) { | ||
throw new Error(`Onigasm#init has been called and was succesful, subsequent calls are not allowed once initialized`); | ||
} | ||
if (typeof data === 'string') { | ||
const arrayBuffer = await (await fetch(data)).arrayBuffer(); | ||
await initModule(arrayBuffer); | ||
} | ||
else if (data instanceof ArrayBuffer) { | ||
await initModule(data); | ||
} | ||
else { | ||
throw new TypeError(`Expected a string (URL of .wasm file) or ArrayBuffer (.wasm file itself) as first parameter`); | ||
} | ||
isInitialized = true; | ||
} | ||
exports.loadWASM = loadWASM; | ||
//# sourceMappingURL=onigasmH.js.map |
{ | ||
"name": "onigasm", | ||
"version": "1.3.1", | ||
"version": "2.0.0", | ||
"description": "WebAssembly port of Oniguruma regex library", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"target": "esnext", | ||
"module": "commonjs", | ||
@@ -5,0 +5,0 @@ "sourceMap": true, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1339261
50
1729