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

web-workers

v0.9.1

Published

Web Workers Kit

Downloads

15

Readme

Web Workers Kit

Run your code easily in web workers

Features

  • :zero: Zero Dependencies
  • :v: Promise based architecture
  • :cloud: Light Weight BundlePhobia Web Workes

Install

NPM -

npm i web-workers

or CDN -

<script src="https://unpkg.com/[email protected]/dist.js"></script>

Usage

const lunar = () => {
  async function get () {
    const res = await fetch('https://jsonplaceholder.typicode.com/todos/1')
    return res.json()
  }
}

const lunarMission = WebWorker(lunar)

lunarMission.get().then(d => console.log(d))

API Documentations

WebWorker

The WebWorker constructor is used invoke/spawn a web worker with the script you pass. And will return promises for all underlying methods of the script.

const WebWorker = require('web-workers')

const script = function () {
  console.log('Web Worker is Invocked')

  function add(a, b) {
    return a + b
  }
}

const worker = WebWorker(script)

Params

  • script - script to run in the worker thread

worker.call() and worker[method]

The call() or [method] can be used to call underlying functions/methods which are also promise based

worker.add(1, 2) // 3

worker.call('add', 2, 3) // 5

Params

  • ...args - arguments to pass to the method

worker.message()

The method is used to add a message to the worker :warning: but not post/send it. The same message you can use and append later in the stage and post.

worker.message('Hello')

worker.message({
  data: [],
  errors: []
})

To clear the message use message with no params :wink:

Params

  • message - message to set - can be of any type - string, object, array

worker.append()

This method is used to append the passed message to the earlier set message

worker.message('Hello')

worker.append(' World!')

Params

  • message - message to append - can be of any type - string, object, array but should be matching the already set message

worker.getMessage()

getMessage() returns the current message with worker

worker.message('Hello')

worker.getMessage() // 'Hello'

worker.kill()

kill() will terminate your worker thread :warning: The kill method will kill the worker even if there is some execution happening

worker.kill()

worker.onerror(fn)

onerror is an error event handler, i.e. if any error happens at the worker thread, you can listen to it right here

worker.onerror((err) => {
  console.log(err)
})

worker.ondata(fn)

Use this method to access the message posted in the worker thread, using postMessage()

worker.ondata((data) => {
  console.log(data)
})