npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wraker/core

v1.0.0

Published

The go-to express-like API for Web Workers

Downloads

69

Readme

Wraker

wraker release license node size language

workflow - wraker codecov issues contrib downloads stars

Wraker is a wrapper for web workers. It makes it easier to manage the communication between the main thread and the worker thread through a simple express like API.

Documentation

Getting started

Using a CDN or a static server

Create a new file worker.js:

import { WrakerApp } from "https://cdn.jsdelivr.net/npm/@wraker/core/+esm";

const app = new WrakerApp();

app.get("/ping", (req, res) => {
  res.send("pong");
});

app.listen();

Then, create a new file main.js:

import { Wraker } from "https://cdn.jsdelivr.net/npm/@wraker/core/+esm";

const worker = new Wraker("worker.js", {
  type: "module",
  name: "my-first-worker",
});

worker.fetch("/ping").then((response) => {
  console.log(response.body); // "pong"
});

Finally, create a web page index.html and serve it:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Wraker</title>
  </head>

  <body>
    <script type="module" src="main.js"></script>
  </body>
</html>

ℹ️ You must serve your files using a server because of the CORS policy. If you open the index.html file directly in your browser, you will get an error as the worker will not be able to fetch the index.js and worker.js files.

You can use any server to serve your files. You can use express. Other good options are http-server, python's http.server, or Live Server for VSCode.

Using a Node.js bundler

npm install wraker

Vite (Nuxt, Vue, Svelte, etc.)

Vite automatically resolves "./worker.js?worker" to a worker class and "./worker.js?url" to a worker url. Please refer to the Vite documentation for more information.

You can take advantage of this feature to create a worker with Wraker:

// worker.js
import { WrakerApp } from "wraker";
// main.js using ?worker shorthand
import { Wraker } from "wraker";
import myWorker from "./worker.js?worker";

const worker = new myWorker();
const wraker = new Wraker.fromWorker(worker);
// main.js using ?url shorthand
import { Wraker } from "wraker";
import myWorkerUrl from "./worker.js?url";

const worker = new Wraker(myWorkerUrl, {
  type: "module",
});
// main.js using the full path
import { Wraker } from "wraker";

const myWorkerUrl = new URL("./worker.js", import.meta.url);

const worker = new Wraker(myWorkerUrl, {
  type: "module",
});

Webpack (React, Angular, etc.)

The correct way to use Wraker with Webpack is to use the full path to the worker file. Please refer to the Webpack documentation for more information.

// main.js
import { Wraker } from "wraker";

const myWorkerUrl = new URL("./worker.js", import.meta.url);

const worker = new Wraker(myWorkerUrl, {
  type: "module",
});

ℹ️ You may be able to use the ?worker or ?url shorthands, but it is using workarounds and may not work as expected. Refer to this discussion for details.

Contributing

Please read the CONTRIBUTING.md file for more information.

License

Wraker is licensed under the MIT License. See LICENSE for the full license text.