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

twitch-emote

v1.1.3

Published

splice twitch emotes from a message string

Downloads

11

Readme

twitch-emote

npm i twitch-emote

initialization

async function initCache(
    channels?: string[],
    settings?: Partial<Settings>
): void

this function must be ran first (and awaited) before spliceMessage or splitMessage will work.

| argument | type | default | description | |------------|---------------------|---------|--------------------------------| | channels | string[] | [] | array of channel names to load | | settings | Partial<Settings> | {} | optional settings |

Settings

| key | type | default | description | |---------------------|-----------|----------------------|--------------------------------------------------------------| | autoRefresh | boolean | true | if true, run indefinitely and regularly check for new data | | refreshInterval | number | 300000 (5 minutes) | time in milliseconds | | cache | boolean | true | caching on the disk | | cacheDir | string | ./cache | directory for cache | | logApiRate | boolean | true | log data about api rate limits | | maxRetryRateLimit | number | 1 | maximum retry attempts when rate limited (the request retries again after the rate limit time so 1 should suffice) |

usage

function spliceMessage<T>(
    message: string,
    channel: string,
    callback?: (emote: EmoteData) => string | T,
    withEmotes?: string,
    strictTwitchEmotes?: boolean
): (string | T)[]

spliceMessage returns an array with strings cut directly where the emotes are, including spaces between emotes and grouping words together.

example: ["emote:EZ", " ", "emote:clap", " too good"]

function splitMessage<T>(
    message: string,
    channel: string,
    callback?: (emote: EmoteData) => string | T,
    withEmotes?: string,
    strictTwitchEmotes?: boolean
): (string | T)[]

splitMessage returns an array of words with some words replaced with emote data.

example: ["emote:EZ", "emote:clap", "too", "good"]

| argument | type | default | description | |----------------------|------------------------------|----------------------------|-------------------------------------------| | message | string | | chat message | | channel | string | | channel name | | callback | (EmoteData) => string \| T | highest quality url string | convert the emote data into something | | withEmotes | string | "" | native twitch emotes given via an IRC tag | | strictTwitchEmotes | boolean | false | if true, native twitch emotes will only be applied through withEmotes; otherwise when false, all twitch and channel emotes will be checked for in the message (i.e. non-subs appear to have sub emotes) |

types


export interface EmoteData {
    provider: Provider
    code: string
    urls: EmoteURL[]
}

export interface EmoteURL {
    size: '1x' | '2x' | '3x' | '4x'
    url: string
}

export enum Provider {
    'Twitch' = 0,
    '7TV' = 1,
    'BetterTTV' = 2,
    'FrankerFaceZ' = 3,
}

example

(see the examples folder for ready and functional examples)

simple

import { initCache, spliceMessage } from 'twitch-emote'

await initCache(['xqc'])

let message = spliceMessage('EZ Clap too good', 'xqc')
console.log(message)

/* 
 * [
 *  'https://cdn.betterttv.net/emote/5590b223b344e2c42a9e28e3/3x',
 *  ' ',
 *  'https://cdn.betterttv.net/emote/55b6f480e66682f576dd94f5/3x',
 *  ' too good'
 * ]
 */

let messageWords = splitMessage('EZ Clap too good', 'xqc')
console.log(messageWords)

/* 
 * [
 *  'https://cdn.betterttv.net/emote/5590b223b344e2c42a9e28e3/3x',
 *  'https://cdn.betterttv.net/emote/55b6f480e66682f576dd94f5/3x',
 *  'too'.
 *  'good'
 * ]
 */

advanced

import { initCache, spliceMessage } from 'twitch-emote'

await initCache(['xqc'])

let message = spliceMessage('EZ Clap too good', 'xqc', emote => {
    return `emote:${emote.code}`
})
console.log(message)

// [ 'emote:EZ', ' ', 'emote:Clap', ' too good' ]

let messageWords = splitMessage('EZ Clap too good', 'xqc', emote => {
    return `emote:${emote.code}`
})
console.log(messageWords)

// [ 'emote:EZ', 'emote:Clap', 'too', 'good' ]