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

ircee

v0.2.9

Published

A tiny modular IRC library with a stream / event-emitter based API

Downloads

11

Readme

ircee

ircee is a tiny modular IRC library with a stream/event-emitter based API.

Why another library?

Most of the advantages come from the stream / eventemitter API. It allows you to do things such as

  • Live code reloading - connect the network connection in the parent process, pipe it to the child process which loads the actual code. Signal the master to kill and respawn the child process - the code will be reloaded without losing the connection to the IRC server.

  • Browserify / use on different transports - for example, use it through websockets in the browser by piping the connection streams using shoe. Here is a complete example using browserify

The modular design allows for easy extensibility and testing.

Example

var ircee = require('ircee'),
    net = require('net');

// Create a client
var irc = ircee();

irc.on('connect', function() {
    // Load the core module. It keeps the connection alive 
    // when loaded and provides the login method.    
    var core = irc.use(require('ircee/core'));
    // use the login method to send the nickname
    core.login({
        nick: 'ircee_example',
        user: 'ircee_example',
        name: 'Look! I am online!'
    });
});

// Log all protocol lines to stdout
irc.on('event', function(e) { console.log(e.raw); });

// Connect the actual socket and pipe it to the client
var s = net.connect(6667, 'irc.freenode.net');
s.pipe(irc).pipe(s);

Modules

Modules are easy to write. Here is how the core module looks like:

module.exports = function(irc) {
    irc.on('ping', function(e) {
        irc.send('pong', e.text);
    });
    var self = {};
    self.login = function login(params) {
        irc.send('nick', params.nick);
        irc.send('user', params.user, 0, '*', params.name);
    }
    return self;
}

The module should be a function that receives the irc client as its argument. It should return the object to be exported.

Using modules

Using modules is easy. From your main program or from any other module, simply call irc.use in the following ways:

irc.use(module_function); 
irc.use(require('./path/to/module'));

You can also get the exported object:

var module = irc.use(require('path/to/module'));

If the module has already been loaded, it will not be called again. Instead, the cached exported object will simply be returned by irc.use

Connect and disconnect

If you are piping a socket (or any stream with a connect event) directly to ircee it will recognize and re-emit its 'connect' event. Otherwise, you will need to tell it when the connection has been established:

irc.emit('connect')

Disconnects arrive as close events. For example, to immediately reconnect to the server, you can do this:

irc.on('close', function() { 
    var s = net.connect(...); 
    s.pipe(irc).pipe(s);
});

Other methods

The methods shown in the examples are all the available methods:

  • irc.send - sends a command to the server. The first parameter is a command string, while the rest are the command parameters. As per usual in the IRC protocol, the final parameter is allowed to have multiple words. For example:

    ```js
    irc.send('privmsg', '#channel', 'Text to send');
    irc.send('privmsg', 'nickname', 'Some text');
    irc.send('mode', '#channel', '+ov', 'nick1', 'nick2', null);
    irc.send('topic', '#channel', 'New topic text');
    ```

    Notice that the mode command does not use a multi-word parameter and therefore we must add a null argument when calling irc.send

  • irc.on etc - All standard eventemitter and duplex stream methods are available.

Events

Events are lower-case strings. Here are some common events:

  • privmsg - all message events, including CTCP
  • notice - all notice events, including CTCP replies.
  • number - all numeric events
  • event - catchall for all IRC events.

Standard socket and stream events are also available

  • connect - socket connection event
  • close - socket closing event.
  • data - raw data, line by line

Event objects

IRC events receive a single argument - the event object. It has the following properties:

  • raw - the full raw event text
  • source - the event source (e.g. nick!user@host)
  • cmd - the command, e.g. PRIVMSG
  • user - the source user (null if N/A)
    • address - nick!user@hostmask
    • nick - users nickname
    • user - users username (ident)
    • host - user's host, hostmask or IP
  • params: list of command parameters
  • target: event target (nickname or channel)
  • text: event text (e.g. message contents)

License:

MIT