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

hypergiant

v3.1.0

Published

Hypergiant is a small and simple signal-like event emitter for Node.js and the browser.

Downloads

79

Readme

NPM version Known Vulnerabilities npm NPM downloads Gitter

Table of Contents

Installation

To download Hypergiant through NPM, simply use:

$ npm install --save hypergiant

and use it in your Node environment as so:

const Hypergiant = require('hypergiant');

or import it browser side as an ES6 module:

import Hypergiant from './node_modules/hypergiant/hypergiant.js';

Basic Usage

Hypergiant is a signal-like event emitter for Node.JS and the browser.

Hypergiant is very minimal and fast but also very powerful. It is comparable to events in native JavaScript except that Hypergiant events are emitted after the action has occurred and it doesn't rely on the events being referenced by string which can lead to misspellings.

Creating a new signal is as simple as:

const appStarted = new Hypergiant();

Any variable or property can be made into a signal.

Now a signal isn't very useful if there isn't a response to the event when it happens. To add a task that will run whenever the event is dispatched, use the add method on the created signal:

appStarted.add(hello);

function hello(name) {
  console.log(`Hello ${name}!`);
}

You can add as many methods as you would like to respond to a signal.

Lastly, it's time to dispatch the signal with the dispatch method:

appStarted.dispatch('Bob');

// The console will display the following message:
// => Hello Bob!

Any parameters passed with dispatch will also be passed to the tesk functions attached to it.

Properties

tasks

Returns all of the tasks that have been created for this signal:

exmple:

const sol = new Hypergiant();

// Tasks...
sol.add(blah);
// More tasks...

const tasks = sol.tasks;

numTasks

Returns the number of tasks currently assigned to this signal.

example:

const sol = new Hypergiant();

sol.add(blah);
sol.add(blah);

const numTasks = sol.numTasks; // 2

API

add

Add takes in a function and an optional parameter named once that can be set to true if you would like this task to be called only once and then be deleted.

| param | type | description | default | |-------|----------|--------------------------------------------------------------------------------------------|---------| | fn | Function | The function to be called when the signal is dispatched. | | | once | false | Indicates whether this task should happen only once and then be automatically deleted. | false |

example:

const sol = new Hypergiant();

// When sol is dispatched, the `sayHello` function will be called once and then deleted from the signal's task list.
sol.add(sayHello, true);

function sayHello(name1, name2) {
  console.log(`Hello ${name1} and ${name2}!`);
}

dispatch

Dispatch sends out the signal and any attached tasks will be called.

This method can take any number of parameters which will act as data sent to the tasks.

| param | type | description | default | |---------|---------|----------------------------------------------------------|---------| | ...data | any | Any data that you want to pass to the tasks | |

example:

const sol = new Hypergiant();

// When sol is dispatched, the `sayHello` function will be called once and then deleted from the signal's task list.
sol.add(sayHello, true);

function sayHello(name1, name2) {
  console.log(`Hello ${name1} and ${name2}!`);
}

// At some other point in your application...
// This will dispatch the Hypergiant event and any attached tasks will be called with 'Bob' and 'John' as parameter values.
sol.disaptch('Bob', 'John');

// In this case the `sayHello` function will log:
// => Hello Bob and John!

remove

Deletes a task from the signal

| param | type | description | default | |-------|----------|--------------------------------------------------------------------------------------------|---------| | fn | Function | The function to delete | |

example:

const sol = new Hypergiant();

sol.add(hello);
sol.remove(hello);

function hello() {
  return 'Hello World!';
}

removeAll

Deletes all tasks from the signal.

example:

const sol = new Hypergiant();

sol.add(hello);
sol.removeAll();

function hello() {
  return 'Hello World!';
}

noop

Makes a task a noop function

| param | type | description | default | |-------|----------|--------------------------------------------------------------------------------------------|---------| | fn | Function | The function to make a noop function | |

example:

const sol = new Hypergiant();

sol.add(hello);
sol.noop(hello);

function hello() {
  return 'Hello World!';
}

Tests

To run the tests available use:

$ npm run test

License

MIT