screamer.js
    Preparing search index...

    Node, bundlers, and the browser

    screamer.js is one package that runs in Node and in the browser. The API is identical everywhere; only how you point the runtime at the package differs. In every environment the rule is the same: call await ready() once before constructing any operator, because the WebAssembly module loads asynchronously.

    Browser use (a bundler or a CDN) requires version 2.2.1 or newer. Earlier versions load only under Node.

    Node 18 or newer. Install and import by name:

    // npm i @screamer-labs/screamer
    import { ready, RollingMean } from "@screamer-labs/screamer";

    await ready();
    const sma = RollingMean(3);
    console.log(sma([1, 2, 3, 4])); // [ NaN, NaN, 2, 3 ]

    The package ships one self-contained module with the WebAssembly embedded, so there is no separate .wasm file to resolve.

    Bundlers need no special configuration (esbuild is tested; Vite, Next.js, webpack and Rollup use the same entry). Install and import exactly as in Node; the bundler inlines the embedded-WASM module into your output:

    // npm i @screamer-labs/screamer
    import { ready, RollingMean } from "@screamer-labs/screamer";

    await ready();
    const sma = RollingMean(3);

    The bare specifier @screamer-labs/screamer resolves through the bundler (or an import map). A raw browser cannot resolve a bare specifier, which is what the CDN form below handles.

    The ES build loads its module with a plain import(), which a bundler follows, and uses no eval or new Function. The tests bundle it with esbuild and run the bundle in Chrome; Vite, webpack and Rollup follow the same import(). The package's browser and module export conditions give a bundler the ES build, also for a require(); the CommonJS build is for Node. Under a Content-Security-Policy, the page needs only 'wasm-unsafe-eval' in script-src (to compile WebAssembly), not 'unsafe-eval'.

    Import from a full URL inside a module script. jsDelivr serves the published module directly:

    <script type="module">
    import { ready, RollingMean }
    from "https://cdn.jsdelivr.net/npm/@screamer-labs/screamer@3.4.0/dist/index.js";

    await ready();

    const sma = RollingMean(3);
    console.log(Array.from(sma(new Float64Array([1, 2, 3, 4])))); // [ NaN, NaN, 2, 3 ]
    </script>

    Pin the version (@3.4.0) so loads are reproducible. The module embeds its WebAssembly, so nothing else needs to be fetched or configured.

    To avoid a third-party origin (for offline use, a strict Content-Security-Policy, or full control), copy the package's dist/ directory next to your page and import it with a relative URL. The Live demo does this; its source shows the pattern.

    await ready() resolves the WebAssembly module once and caches it; a second call awaits the same load. Construct operators after it, never before. Each op owns memory on the WASM side, so call .dispose() when you are done with it (or use using where your runtime supports it). See Lifecycle.

    Requirements: Node 18+, or any browser with WebAssembly, which is every current browser on desktop and mobile.