intl-segmenter-polyfill
Advanced tools
Comparing version 0.2.4 to 0.2.5
@@ -1,2 +0,2 @@ | ||
declare const createIntlSegmenterPolyfill: (wasm: Response | PromiseLike<Response>) => Promise<{ | ||
declare const createIntlSegmenterPolyfill: (wasm: ArrayBufferLike | PromiseLike<Response>) => Promise<{ | ||
new (locale: string, options: { | ||
@@ -3,0 +3,0 @@ granularity: 'word' | 'grapheme'; |
@@ -53,22 +53,33 @@ "use strict"; | ||
}; | ||
var instantiateWasmModule = function (wasm, imports) { | ||
if (typeof wasm.then === 'function') { | ||
if (WebAssembly.instantiateStreaming != null) { | ||
return WebAssembly.instantiateStreaming(wasm, imports); | ||
} | ||
return wasm | ||
.then(function (response) { return response.arrayBuffer(); }) | ||
.then(function (buffer) { return WebAssembly.instantiate(buffer, imports); }); | ||
} | ||
else { | ||
return WebAssembly.instantiate(wasm, imports); | ||
} | ||
}; | ||
var createIntlSegmenterPolyfill = function (wasm) { return __awaiter(void 0, void 0, void 0, function () { | ||
var breaks, instantiate, response, allocStr; | ||
var breaks, response, allocStr; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
instantiate = WebAssembly.instantiateStreaming || WebAssembly.instantiate; | ||
return [4 /*yield*/, instantiate(wasm, { | ||
env: { | ||
push: function (start, end, segmentType) { | ||
breaks.push([start, end, segmentType]); | ||
}, | ||
__sys_stat64: function () { } | ||
case 0: return [4 /*yield*/, instantiateWasmModule(wasm, { | ||
env: { | ||
push: function (start, end, segmentType) { | ||
breaks.push([start, end, segmentType]); | ||
}, | ||
wasi_snapshot_preview1: { | ||
proc_exit: function () { }, | ||
fd_close: function () { }, | ||
environ_sizes_get: function () { }, | ||
environ_get: function () { } | ||
} | ||
})]; | ||
__sys_stat64: function () { } | ||
}, | ||
wasi_snapshot_preview1: { | ||
proc_exit: function () { }, | ||
fd_close: function () { }, | ||
environ_sizes_get: function () { }, | ||
environ_get: function () { } | ||
} | ||
})]; | ||
case 1: | ||
@@ -75,0 +86,0 @@ response = _a.sent(); |
{ | ||
"name": "intl-segmenter-polyfill", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "This repo builds .wasm module using icu4c for breaking text into words, so that we can polyfill [Intl Segmenter Proposal](https://github.com/tc39/proposal-intl-segmenter) with full compatibility, even on browsers that do not expose v8BreakIterator api.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -17,11 +17,22 @@ const BREAK_TYPES = { | ||
const instantiateWasmModule = (wasm, imports) => { | ||
if (typeof wasm.then === 'function') { | ||
if (WebAssembly.instantiateStreaming != null) { | ||
return WebAssembly.instantiateStreaming(wasm, imports) | ||
} | ||
return wasm | ||
.then((response) => response.arrayBuffer()) | ||
.then((buffer) => WebAssembly.instantiate(buffer, imports)) | ||
} else { | ||
return WebAssembly.instantiate(wasm, imports) | ||
} | ||
} | ||
const createIntlSegmenterPolyfill = async ( | ||
wasm: Response | PromiseLike<Response>, | ||
wasm: ArrayBufferLike | PromiseLike<Response> | ||
) => { | ||
let breaks: [number, number, number][] | ||
// node env does not support instantiateStreaming | ||
const instantiate = | ||
WebAssembly.instantiateStreaming || WebAssembly.instantiate | ||
const response = await instantiate(wasm, { | ||
const response = await instantiateWasmModule(wasm, { | ||
env: { | ||
@@ -28,0 +39,0 @@ push: (start: number, end: number, segmentType: number) => { |
1145528
6
226