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

@elara-services/twitch

v2.0.0

Published

- Create your Application on https://dev.twitch.tv/console - Once you create your application copy the clientId and clientSecret

Downloads

8

Readme

Getting Started

  • Create your Application on https://dev.twitch.tv/console
  • Once you create your application copy the clientId and clientSecret

Setting Up

const { Twitch } = require("@elara-services/twitch");
const twitch = new Twitch("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");

GET: User(s)

    const res = await twitch.user([ "tfue" ]); // This can be either their login_name or their user ID 
    if (!res.status) return res.message; // When 'status' is false message is always provided.
    console.log(res); // Returns a 'data' field with an array of found user(s)

GET: Stream(s) by User(s)

    const res = await twitch.stream([ "tfue" ]); // This can be either their login_name or their user ID 
    if (!res.status) return res.message; // When 'status' is false message is always provided.
    console.log(res); // Returns a 'data' field with an array of found user(s)

GET: Fetch Both

    const res = await twitch.fetchAll([ "tfue" ]); // This can be either their login_name or their user ID 
    if (!res.status) return res.message; // When 'status' is false message is always provided.
    console.log(res); // Returns both (streams) and (users) fields with an array of found data

STREAM:

[If you want an example look in the GitHub repo -> twitch-ts -> examples]

Setup the stream client:

    const { Stream } = require(`@elara-services/twitch`);
    const stream = new Stream("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");

STREAM: Add user(s):

    // Multiple:
    stream.users.add([
        "tfue",
        "ninja"
    ]);

    // Single:
    stream.users.add("bewitching");

STREAM: Remove user(s):

    // Multiple: 
    stream.users.remove([
        "tfue",
        "ninja",
    ]);

    // Single: 
    stream.users.remove("bewitching");

STREAM: List user(s):

    const list = stream.users.list();
    console.log(list); // Returns an array of strings of the user's names or ids added.

STREAM: Set Timer:

    stream.setTimer(5); // Set the stream to search for new/update/ended live streams every 5 minutes. 
    // By default the stream searches every 6 minutes. 

STREAM: Toggle Default Announcements:

    // SET
    stream.setToggle("live"); // This will turn on/off the default announcements for all users.
    stream.setToggle("update"); // This will turn on/off the default announcement updates for all users.
    stream.setToggle("ended"); // This will turn on/off the default announcement ended update for all users. 

    // VIEW:
    stream.toggles; // Returns an object: 
    // { live: boolean, update: boolean, ended: boolean }
    // By default live, update and ended is enabled.

STREAM: Default Announcements:

    // Add default announcements for a user: 
    stream.announcements.add("bewitching", [
        "discord webhook url"
    ]);

    // Remove default announcements for a user: 
    stream.announcements.remove("bewitching");
    // OR remove only a certain webhook from the user: 
    stream.announcements.remove("bewitching", [
        "discord webhook url to remove"
    ]);

    // List all default announcements: 
    stream.announcements.list();
    // OR list all webhooks for a certain user: 
    stream.announcements.list("bewitching");

WARNING:

  • Update and ended live streams will NOT work if the user is no longer in the package's cache (i.e: if you've restarted the process all previous announced live streams will NOT be updated or ended!)

STREAM: Start:

    stream.run(); // This only needs to be called once, then it will automatically fetch the user's streams and let you know when they're live.

STREAM: Get Duration:

    const duration = stream.getDuration(stream);
    // OR 
    const duration = stream.getDuration(stream, "[d]d, h[h], m[m], s[s]"); // Add your custom moment-duration-format option

STREAM: Events:

    // Listen for new live streams: 
    stream.live((stream) => {
        // Do something with the 'stream' data. 
        console.log(`[LIVE]: ${stream.user_login}`, stream);
    });

    // Listen for updated live streams: 
    stream.update((oldStream, newStream) => {
        // Do something with the updated stream data.
        // oldStream: Will contain the data before the update happened.
        // newStream: Will contain the updated data. 
        console.log(`[LIVE:UPDATED]: ${stream.user_login}'s stream got updated`, oldStream, newStream); 
    });

    // Listen for ended live streams: 
    stream.ended((stream) => {
        // Do something with the ended stream data.
        console.log(`[LIVE:ENDED]: ${stream.user_login} is now longer live streaming.`, stream);
    });

Need support?

Support Server