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

preact-twitch-status

v1.1.0

Published

TwitchStatus is a small [Preact](https://preactjs.com) component I built to show my live/offline status on my website using the [Twitch Helix API](https://dev.twitch.tv/docs/api/reference).

Downloads

2

Readme

TwitchStatus

TwitchStatus is a small Preact component I built to show my live/offline status on my website using the Twitch Helix API.

I know this implementation is less than ideal and will probably hit rate limits pretty quickly, especially with polling on, but it was for fun. If Twitch releases an officially documented webhook or WebSocket event for this I will probably update the component.

I chose Preact because of its small size so that I could include it in a distributable as a self-contained “Renderer” that could be used on static HTML sites. When minified and gzipped the distributable is less than 4kB.

This component includes no styles, it is a very basic HTML component that you should be able to style in your application to fit your visual language.

Usage

Using the Renderer

If you’re using a static site like I am, you could download the latest release. Then include the minified JavaScript file, and instantiate a Renderer on your page.

<!doctype html>
<html>
  <head>
    <title>TwitchStatus Example</title>
  </head>

  <body>
    <div id="twitch-status"></div>

    <script src="/javascripts/twitch-status.min.js"></script>
    <script>
      new TwitchStatus.Renderer('twitch-status', {
        userLogin: 'joedynamitetv',
        clientId: 'my-secret-client-id'
      });
    </script>
  </body>
</html>

The constructor accepts two arguments, the first is an HTML id for the element to render the component inside of. The second is a set of props that get passed to the component, valid props are listed below.

Using the Component

Install first using either Yarn or NPM.

$ yarn add preact-twitch-status
$ npm install --save preact-twitch-status

Then you should import the component directly into another Preact project and use it like you would expect. Valid props are listed below.

import { h, Component } from 'preact';
import { Component as TwitchStatus } from 'preact-twitch-status';

class App extends Component {
  render() {
    return (
      <div>
        <TwitchStatus userLogin="joedynamitetv" clientId="my-secret-client-id" />
      </div>
    );
  }
}

export default App;

Prop Types and Default Values

| Name | Optionality | Type | Default | |--------------------|-------------|---------|-------------| | userLogin | Required | String | None | | clientId | Required | String | None | | offlineText | Optional | String | "Offline" | | offlineClassName | Optional | String | "offline" | | liveText | Optional | String | "Live" | | liveClassName | Optional | String | "live" | | poll | Optional | Boolean | false | | pollInterval | Optional | Number | 5000 |