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

@jprochazk/twitch_irc

v0.11.2

Published

Twitch chat client

Downloads

1

Readme

twitch_irc

Twitch chat client

Usage in Deno

import * as TwitchIrc from "https://deno.land/x/twitch_irc/mod.ts";

const channel = /*...*/;
const nick = /*...*/;
const pass = /*...*/;

const client = new TwitchIrc.Client({
  credentials: { nick, pass }
});
client.on("privmsg", ({ user, message }) => {
  console.log(`${user.login}: ${message}`);
});
client.on("open", () => {
  client.join(channel);
});

Usage in Node

$ npm install twitch_irc@npm:@jprochazk/twitch_irc

ESM:

// index.mjs
// or index.js, but with "type":"module" in package.json
import * as TwitchIrc from "twitch_irc";

const channel = /*...*/;
const nick = /*...*/;
const pass = /*...*/;

const client = new TwitchIrc.Client({
  credentials: { nick, pass }
});
client.on("privmsg", ({ user, message }) => {
  console.log(`${user.login}: ${message}`);
});
client.on("open", () => {
  client.join(channel);
});

CommonJS:

// index.js
const TwitchIrc = require("twitch_irc");

const channel = /*...*/;
const nick = /*...*/;
const pass = /*...*/;

const client = new TwitchIrc.Client({
  credentials: { nick, pass }
});
client.on("privmsg", ({ user, message }) => {
  console.log(`${user.login}: ${message}`);
});
client.on("open", () => {
  client.join(channel);
});

Features

  • Connection management
    • Authentication
    • Automatic reconnect
    • Automatic keep-alive
  • Correct message parsing[^1]
  • Same message bypass for PRIVMSG
  • Auto-complete tag names
  • Latency measurement
  • Strong type safety[^2]
  • Rate limiting

[^1]: Some tag values can have a space in them, and the example parser by Twitch will not correctly handle that case. [^2]: The library uses string and template literal types extensively, for example to ensure that a channel has the # prefix - similar usage of these advanced type features simplifies the internals of the library greatly, and contributes towards making it less error prone to use.

Examples

Specify the --inspect-brk flag to inspect any of the examples using developer tools. For example, for Chrome it's chrome://inspect -> Open dedicated DevTools for Node. The client is available on the window object as window.client.

Simple chat logging (anonymous)

Requires the CHANNEL environment variable to be specified in the format #<name>, e.g. #jtv.

$ deno run \
  --allow-env=CHANNEL \
  --allow-net=irc-ws.chat.twitch.tv \
  https://deno.land/x/twitch_irc/examples/logs.ts

Simple bot

Requires three environment variables:

  • CHANNEL in the format #<name>, e.g. #jtv.
  • TOKEN in the format oauth:<token>, e.g. oauth:abcdefg0123456789. You can generate one here.
  • LOGIN, which is the username of the account you used to generate TOKEN.

The bot will join CHANNEL upon connecting, and you can type !ping in command to have it respond to you. It will also join its own channel.

$ deno run \
  --allow-env=CHANNEL,LOGIN,TOKEN \
  --allow-net=irc-ws.chat.twitch.tv \
  https://deno.land/x/twitch_irc/examples/bot.ts

Release process

  • Commit latest changes
  • Tag with new version according to semver
  • deno run -A ./scripts/build_npm.ts <version> using the same version
  • cd npm && npm publish --access=public