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

ultron

v1.1.1

Published

Ultron is high-intelligence robot. It gathers intel so it can start improving upon his rudimentary design

Downloads

9,111,624

Readme

Ultron

Made by unshiftVersion npmBuild StatusDependenciesCoverage StatusIRC channel

Ultron is a high-intelligence robot. It gathers intelligence so it can start improving upon his rudimentary design. It will learn your event emitting patterns and find ways to exterminate them. Allowing you to remove only the event emitters that you assigned and not the ones that your users or developers assigned. This can prevent race conditions, memory leaks and even file descriptor leaks from ever happening as you won't remove clean up processes.

Installation

The module is designed to be used in browsers using browserify and in Node.js. You can install the module through the public npm registry by running the following command in CLI:

npm install --save ultron

Usage

In all examples we assume that you've required the library as following:

'use strict';

var Ultron = require('ultron');

Now that we've required the library we can construct our first Ultron instance. The constructor requires one argument which should be the EventEmitter instance that we need to operate upon. This can be the EventEmitter module that ships with Node.js or EventEmitter3 or anything else as long as it follow the same API and internal structure as these 2. So with that in mind we can create the instance:

//
// For the sake of this example we're going to construct an empty EventEmitter
//
var EventEmitter = require('events').EventEmitter; // or require('eventmitter3');
var events = new EventEmitter();

var ultron = new Ultron(events);

You can now use the following API's from the Ultron instance:

Ultron.on

Register a new event listener for the given event. It follows the exact same API as EventEmitter.on but it will return itself instead of returning the EventEmitter instance. If you are using EventEmitter3 it also supports the context param:

ultron.on('event-name', handler, { custom: 'function context' });

Just like you would expect, it can also be chained together.

ultron
.on('event-name', handler)
.on('another event', handler);

Ultron.once

Exactly the same as the Ultron.on but it only allows the execution once.

Just like you would expect, it can also be chained together.

ultron
.once('event-name', handler, { custom: 'this value' })
.once('another event', handler);

Ultron.remove

This is where all the magic happens and the safe removal starts. This function accepts different argument styles:

  • No arguments, assume that all events need to be removed so it will work as removeAllListeners() API.
  • 1 argument, when it's a string it will be split on and , to create a list of events that need to be cleared.
  • Multiple arguments, we assume that they are all names of events that need to be cleared.
ultron.remove('foo, bar baz');        // Removes foo, bar and baz.
ultron.remove('foo', 'bar', 'baz');   // Removes foo, bar and baz.
ultron.remove();                      // Removes everything.

If you just want to remove a single event listener using a function reference you can still use the EventEmitter's removeListener(event, fn) API:

function foo() {}

ultron.on('foo', foo);
events.removeListener('foo', foo);

License

MIT