Skip to content

Function: init() ​

ts
function init(source?): Promise<void>;

Defined in: wasm.ts:72

Compiles and instantiates the WebAssembly module.

Every public API calls this for you, so reach for it directly only to control when the roughly 50 ms cost is paid — during a splash screen rather than on a user's first click — or to point at a .wasm you serve yourself.

Safe to call repeatedly: the first call wins and later callers await the same instantiation. A failed attempt is not cached, so a transient network error can be retried.

Required before anything else when using @crmackey/shapefile-wasm/slim, which ships without the inlined binary.

Parameters ​

ParameterTypeDescription
source?WasmSourceWhere to get the binary: a URL string or URL, a Response, an ArrayBuffer/Uint8Array of bytes, or an already-compiled WebAssembly.Module. Omit it on the package root to use the inlined binary.

Returns ​

Promise<void>

Resolves once the module is ready to use.

Throws ​

If no binary is available — the usual cause is importing /slim and calling init() with no argument — or if compilation fails.

Examples ​

Warm the module up ahead of time

ts
await init();

Serve the binary as its own asset (smaller, streams while compiling)

ts
import { init } from '@crmackey/shapefile-wasm/slim';
import wasmUrl from '@crmackey/shapefile-wasm/wasm?url';

await init(wasmUrl);

Released under the MIT License.