### Install Twitch Emoticons via npm/pnpm/yarn/deno Source: https://github.com/mkody/twitch-emoticons/blob/master/README.md Install the library using your preferred package manager. The `@next` tag is recommended for the latest features. ```sh npm install @mkody/twitch-emoticons@next # or pnpm add @mkody/twitch-emoticons@next # or yarn add @mkody/twitch-emoticons@next # or deno add npm:@mkody/twitch-emoticons@next ``` -------------------------------- ### FFZEmote Constructor and Setup Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_FFZEmote.js.html Initializes an FFZEmote instance and sets up its properties based on raw data. Handles different emote types and image formats. ```javascript import Emote from './Emote.js' import Constants from '../util/Constants.js' /** @augments Emote */ class FFZEmote extends Emote { /** * An FFZ emote. * @param {Channel} channel - {@linkcode Channel} this emote belongs to. * @param {string} id - ID of the emote. * @param {data} data - The raw emote data. */ constructor (channel, id, data) { super(channel, id, data) this.type = 'ffz' } _setup (data) { /** * The code or name of the emote. * @type {string} */ this.code = data.name /** * The name of the emote owner. * Might be null for global emotes. * @type {string | null} */ this.ownerName = 'owner' in data ? data.owner.name : null /** * Available image sizes. * @type {string[]} */ this.sizes = 'animated' in data ? Object.keys(data.animated) : Object.keys(data.urls) /** * The image type of the emote. * @type {'png' | 'webp'} */ this.imageType = 'animated' in data ? 'webp' : 'png' /** * If the emote is animated. * @type {boolean} */ this.animated = 'animated' in data /** * If emote can be zero-width (overlaying). * @type {boolean} */ this.zeroWidth = data.modifier && data.modifier_flags === 0 /** * If the emote is a modifier (effect) and should be hidden. * @type {boolean} */ this.modifier = data.modifier && (data.modifier_flags & 1) !== 0 } ``` -------------------------------- ### Install Twitch Emoticons via JSR Source: https://github.com/mkody/twitch-emoticons/blob/master/README.md Install the library from the JSR registry. Note that version specification might be required for pre-release versions. ```sh npx jsr add @mkody/twitch-emoticons # or pnpm add jsr:@mkody/twitch-emoticons # or yarn add jsr:@mkody/twitch-emoticons # or (version has to be specified while it is a pre-release) deno add jsr:@mkody/twitch-emoticons@3.0.0-beta.6 ``` -------------------------------- ### Private Method to Setup Channel Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_EmoteFetcher.js.html Internal method to initialize or retrieve a Channel instance. It ensures a Channel object exists for a given channel ID and optionally updates its format preference. ```javascript /** * Sets up a channel * @private * @param {number} channelId - ID of the channel. * @param {string} [format] - The type file format to use (webp/avif). * @throws {Error} When Twitch Client ID or Client Secret were not provided. * @returns {Channel} - A Channel instance. */ _setupChannel (channelId, format) { let channel = this.channels.get(channelId) if (!channel) { channel = new Channel(this, channelId) this.channels.set(channelId, channel) } if (format) channel.format = format.toLowerCase() return channel } ``` -------------------------------- ### BTTVEmote.toLink() Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/BTTVEmote.html Gets the image link of the emote. ```APIDOC ## BTTVEmote.toLink() ### Description Gets the image link of the emote. ### Method GET ### Endpoint N/A (Instance method) ### Parameters #### Query Parameters - **options** (object) - Optional - Options for generating the link. ``` -------------------------------- ### Define BTTVEmote class Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_BTTVEmote.js.html The BTTVEmote class implementation, including constructor, setup, link generation, and object serialization methods. ```javascript import Emote from './Emote.js' import Constants from '../util/Constants.js' /** @augments Emote */ class BTTVEmote extends Emote { /** * A BTTV emote. * @param {Channel} channel - {@linkcode Channel} this emote belongs to. * @param {string} id - ID of the emote. * @param {data} data - The raw emote data. */ constructor (channel, id, data) { super(channel, id, data) this.type = 'bttv' } _setup (data) { super._setup(data) /** * The name of the emote owner. * Might be null for global emotes. * @type {string | null} */ this.ownerName = 'user' in data ? data.user.name : null /** * The image type of the emote. * @type {string} */ this.imageType = 'webp' /** * If the emote is animated. * @type {boolean} */ this.animated = data.animated } /** * Gets the image link of the emote. * @param {object} [options] - Options for the link. * @param {number} [options.size=0] - Size (scale) for the emote. * @param {boolean} [options.forceStatic] - Whether to force the emote to be static (non-animated). Defaults to the fetcher's forceStatic or `false`. * @returns {string} - The URL to the emote. */ toLink (options) { const { size = 0, forceStatic = this.fetcher.forceStatic || false, } = options || {} return Constants.BTTV.CDN(this.id, size, forceStatic) } /** * Override of the override for `toObject`. * Will result in an Object representation of a {@linkcode BTTVEmote}. * @returns {object} - Object representation of the {@linkcode BTTVEmote}. */ toObject () { return { ...super.toObject(), type: this.type, ownerName: this.ownerName, animated: this.animated, } } /** * Converts an emote Object into a {@linkcode BTTVEmote} * @param {object} [emoteObject] - Object representation of this emote * @param {Channel} [channel] - {@linkcode Channel} this emote belongs to. * @returns {BTTVEmote} - A {@linkcode BTTVEmote} instance. */ static fromObject (emoteObject, channel) { return new BTTVEmote( channel, emoteObject.id, { code: emoteObject.code, animated: emoteObject.animated, user: { name: emoteObject.ownerName, }, } ) } } export default BTTVEmote ``` -------------------------------- ### toLink(options) Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/SevenTVEmote.html Gets the image link of the emote. Allows specifying size and whether to force a static image. ```APIDOC ## toLink(options) ### Description Gets the image link of the emote. Allows specifying size and whether to force a static image. ### Method (Implicitly a method call on a SevenTVEmote instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters #### Options Object - **size** (number, optional) - Size (scale) for the emote. Defaults to 0. - **forceStatic** (boolean, optional) - Whether to force the emote to be static (non-animated). Defaults to the fetcher's forceStatic or `false`. ### Returns * **string** - The URL to the emote. ``` -------------------------------- ### _setupChannel Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/EmoteFetcher.html Initializes a channel instance for emote processing. ```APIDOC ## _setupChannel ### Description Sets up a channel for emote fetching. ### Parameters #### Path Parameters - **channelId** (number) - Required - ID of the channel. - **format** (string) - Optional - The type file format to use (webp/avif). ### Response - **Channel** (Channel) - A Channel instance. ### Errors - Throws error if Twitch Client ID or Client Secret were not provided. ``` -------------------------------- ### Constructor: new FFZEmote Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/FFZEmote.html Initializes a new instance of the FFZEmote class. ```APIDOC ## new FFZEmote(channel, id, data) ### Description Creates a new FFZ emote instance. ### Parameters #### Path Parameters - **channel** (Channel) - Required - The Channel this emote belongs to. - **id** (string) - Required - ID of the emote. - **data** (data) - Required - The raw emote data. ### Members - **code** (string) - The code or name of the emote. - **ownerName** (string|null) - The name of the emote owner (null for global emotes). - **sizes** (Array.) - Available image sizes. - **imageType** ('png'|'webp') - The image type of the emote. - **animated** (boolean) - If the emote is animated. - **zeroWidth** (boolean) - If emote can be zero-width (overlaying). - **modifier** (boolean) - If the emote is a modifier (effect) and should be hidden. - **fetcher** (EmoteFetcher) - The EmoteFetcher being used. - **channel** (Channel) - The Channel this emote belongs to. ``` -------------------------------- ### GET FFZ Emotes Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_EmoteFetcher.js.html Retrieves raw FrankerFaceZ (FFZ) emote data from a specific set or channel. ```APIDOC ## GET /ffz/emotes ### Description Fetches raw FFZ emote data. Can retrieve emotes from a specific set ID or all emotes associated with a channel ID. ### Method GET ### Parameters #### Query Parameters - **id** (number) - Required - The ID of the set or channel to fetch emotes for. ### Response #### Success Response (200) - **emotes** (array) - An array of raw FFZ emote data objects. ``` -------------------------------- ### SevenTVEmote Constructor and _setup Method Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_SevenTVEmote.js.html Initializes a SevenTVEmote instance and sets up its properties based on raw emote data. Includes logic for parsing emote flags and determining image sizes and animation status. ```javascript import Emote from './Emote.js' import Constants from '../util/Constants.js' /** @augments Emote */ class SevenTVEmote extends Emote { /** * A 7TV emote. * @param {Channel} channel - {@linkcode Channel} this emote belongs to. * @param {string} id - ID of the emote. * @param {data} data - The raw emote data. */ constructor (channel, id, data) { super(channel, id, data) this.type = '7tv' } _setup (data) { // "Active" Emote flag's bitfield (copied in full for reference) // https://github.com/SevenTV/SevenTV/blob/cd3d3b183caff640f2f3c41041794d5c71bc2d5d/shared/src/old_types/mod.rs#L710-L715 const ActiveEmoteFlags = { ZeroWidth: 1, // 1 << 0 OverrideTwitchGlobal: 65536, // 1 << 16 OverrideTwitchSubscriber: 131072, // 1 << 17 OverrideBetterTTV: 262144, // 1 << 18 } // Emote flags' bitfield (copied in full for reference) // https://github.com/SevenTV/SevenTV/blob/cd3d3b183caff640f2f3c41041794d5c71bc2d5d/shared/src/old_types/mod.rs#L624-L632 const EmoteFlags = { Private: 1, // 1 << 0 Authentic: 2, // 1 << 1 ZeroWidth: 256, // 1 << 8 Sexual: 65536, // 1 << 16 Epilepsy: 131072, // 1 << 17 Edgy: 262144, // 1 << 18 TwitchDisallowed: 16777216, // 1 << 24 } /** * The code or name of the emote. * @type {string} */ this.code = data.name || data.data.name /** * The name of the emote owner. * Might be null for global emotes. * @type {string | null} */ this.ownerName = data.data.owner?.display_name || null /** * Available image sizes. * @type {string[]} */ this.sizes = data.data.host.files .map((el) => el.name.replace(/x\.(\w+)/, '')) .sort((a, b) => Number(a) - Number(b)) if (this.sizes.length === 0) { // This is the current (2026-03-16) documented default, in case the above breaks this.sizes = ['1', '2', '3', '4'] } /** * The image type of the emote. * @type {string} */ this.imageType = this.channel.format /** * If the emote is animated. * @type {boolean} */ this.animated = Boolean(data.data.animated) /** * If emote can be zero-width (overlaying). * @type {boolean} */ this.zeroWidth = (data.flags & ActiveEmoteFlags.ZeroWidth) !== 0 || (data.data.flags & EmoteFlags.ZeroWidth) !== 0 /** * If emote is NSFW/unlisted (or Twitch disallowed, just in case). * Do note that this flag isn't always applied to what *looks* NSFW. * @type {boolean} */ this.nsfw = (data.data.flags & EmoteFlags.Sexual) !== 0 || (data.data.flags & EmoteFlags.TwitchDisallowed) !== 0 || data.data.listed === false } /** * Gets the image link of the emote. * @param {object} [options] - Options for the link. ``` -------------------------------- ### FFZEmote fromObject Static Method Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_FFZEmote.js.html Creates an FFZEmote instance from a plain JavaScript object. Requires a Channel object for context. ```javascript /** * Converts an emote Object into a {@linkcode FFZEmote} * @param {object} [emoteObject] - Object representation of this emote * @param {Channel} [channel] - {@linkcode Channel} this emote belongs to. * @returns {FFZEmote} - A {@linkcode FFZEmote} instance. */ static fromObject (emoteObject, channel) { // Need to convert sizes array to object, e.g. [1, 2, 4] -> { 1: '1', 2: '2', 4: '4' } ``` -------------------------------- ### GET BTTV Emotes Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_EmoteFetcher.js.html Retrieves raw BetterTTV (BTTV) emote data for a specific channel or global emotes. ```APIDOC ## GET /bttv/emotes ### Description Fetches raw BTTV emote data. Uses a channel ID to fetch channel-specific and shared emotes, or fetches global emotes if no ID is provided. ### Method GET ### Parameters #### Query Parameters - **id** (number) - Optional - The ID of the channel to fetch emotes for. ### Response #### Success Response (200) - **emotes** (array) - An array of raw BTTV emote data objects. ``` -------------------------------- ### GET Twitch Emotes Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_EmoteFetcher.js.html Retrieves raw emote data from Twitch, either for a specific channel or global emotes. ```APIDOC ## GET /twitch/emotes ### Description Fetches raw Twitch emote data. If an ID is provided, it retrieves channel-specific emotes; otherwise, it fetches global emotes. ### Method GET ### Parameters #### Query Parameters - **id** (number) - Optional - The ID of the channel to fetch emotes for. ### Response #### Success Response (200) - **emotes** (array) - An array of raw Twitch emote data objects. ``` -------------------------------- ### BTTVEmote Constructor Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/BTTVEmote.html Initializes a new BTTVEmote instance. ```APIDOC ## BTTVEmote Constructor ### Description Creates a new BTTVEmote instance. ### Parameters #### Parameters - **channel** (Channel) - Required - The Channel this emote belongs to. - **id** (string) - Required - ID of the emote. - **data** (data) - Required - The raw emote data. ``` -------------------------------- ### Initialize EmoteFetcher with Twitch App Credentials Source: https://github.com/mkody/twitch-emoticons/blob/master/README.md Instantiate `EmoteFetcher` and provide Twitch app credentials for authentication. Alternatively, an existing `ApiClient` from `@twurple/api` can be passed. Options to force static emotes or set theme mode are also available. ```js const fetcher = new EmoteFetcher({ // If you want to use emotes from twitch.tv, you will need to be authenticated to use their API. // Option 1: Provide your app ID and secret here (get them at https://dev.twitch.tv/console/apps). twitchAppID, // twitchAppSecret, // // Option 2: If you need a different way to auth or already use `@twurple/api`, // you can provide your ApiClient object here. apiClient, // // Force emotes to be static (non-animated). forceStatic, // - Default: false // Theme mode (background color) preference for Twitch emotes. twitchThemeMode, // <'dark' | 'light'> - Default: 'dark' }) ``` -------------------------------- ### Get Raw FFZ Emotes Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_EmoteFetcher.js.html Fetches raw FFZ emote data for a channel. Aggregates emotes from all sets associated with the channel. ```javascript _getRawFFZEmotes (id) { const endpoint = Constants.FFZ.Channel(id) return fetch(endpoint) .then((response) => response.json()) .then((data) => { const emotes = [] for (const key of Object.keys(data.sets)) { const set = data.sets[key] emotes.push(...set.emoticons) } return emotes }) } ``` -------------------------------- ### Get Raw Twitch Emotes Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_EmoteFetcher.js.html Fetches raw emote data for a specific channel or global emotes. Requires an initialized API client. ```javascript _getRawTwitchEmotes (id) { if (!this.apiClient) { throw new Error('Client id or client secret not provided.') } if (id) { return this.apiClient.chat.getChannelEmotes(id) } else { return this.apiClient.chat.getGlobalEmotes() } } ``` -------------------------------- ### Initialize EmoteParser Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/index.html Create an EmoteParser instance with an EmoteFetcher and optional settings for parsing behavior. ```javascript const parser = new EmoteParser( // The first parameter is our EmoteFetcher, the object that holds the list of fetched emotes. fetcher, // // The second parameter is an *optional* object with settings. { // Allow, or explicitly disallow, rendering emotes we flag as "NSFW" (7TV only) allowNSFW, // - Default: false // What output should be used when you parse messages? There are two ways to set that up: // Option 1: Use one of the provided templates: // - 'html': `{name}` // - 'markdown': `![{name}]({link} "{name}")` // - 'bbcode': `[img]{link}[/img]` // - 'plain': `{link}` type, // <'html' | 'markdown' | 'bbcode' | 'plain'> - Default: 'html' // Option 2: Make your own template; this has priority over option 1. // You can use those: `{link}`, `{name}`, `{size}`, `{creator}`, // `{is-animated}`, `{is-nsfw}`, `{is-zero-width}`. template, // - Default: '' // You can customize the regular expression used to find possible emotes. match, // - Default: /([^s]+)/g }, ) ``` -------------------------------- ### Create FFZEmote Instance Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_FFZEmote.js.html Constructs a new FFZEmote instance from raw emote data. It processes sizes into an object and conditionally includes animated properties. Ensure emoteObject has all required properties like id, code, ownerName, animated, zeroWidth, and modifier. ```javascript const sizesObj = emoteObject.sizes.reduce( (acc, curr) => { acc[curr] = curr return acc }, {} ) return new FFZEmote( channel, emoteObject.id, { code: emoteObject.code, name: emoteObject.code, urls: sizesObj, ...emoteObject.animated ? { animated: sizesObj } : {}, owner: { name: emoteObject.ownerName }, modifier: (emoteObject.zeroWidth || emoteObject.modifier), modifier_flags: (emoteObject.modifier ? 1 : 0), } ) } } export default FFZEmote ``` -------------------------------- ### Get Raw FFZ Emote Set Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_EmoteFetcher.js.html Fetches raw FFZ emote data for a specific emote set ID. Extracts emoticon data from the response. ```javascript _getRawFFZEmoteSet (id) { const endpoint = Constants.FFZ.Set(id) return fetch(endpoint) .then((response) => response.json()) .then((data) => { return data.set.emoticons }) } ``` -------------------------------- ### Get Raw 7TV Emotes Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_EmoteFetcher.js.html Fetches raw 7TV emote data for a channel, with support for specifying image format (webp or avif). Uses GraphQL for the request. ```javascript _getRawSevenTVEmotes (id, format) { return fetch( Constants.SevenTV.GQL, { method: 'POST', headers: { 'content-type': 'application/json', }, body: JSON.stringify({ ``` -------------------------------- ### FFZEmote Class Methods Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_FFZEmote.js.html Documentation for the FFZEmote class, which handles FrankerFaceZ emote data, link generation, and object serialization. ```APIDOC ## FFZEmote.toLink ### Description Gets the image link of the FFZ emote based on size and animation preferences. ### Parameters #### Query Parameters - **options** (object) - Optional - Options for the link. - **options.size** (number) - Optional - Size (scale) for the emote. Defaults to 0. - **options.forceStatic** (boolean) - Optional - Whether to force the emote to be static. Defaults to fetcher's forceStatic or false. ### Response - **string** - The URL to the emote. --- ## FFZEmote.toObject ### Description Returns an object representation of the FFZEmote instance. ### Response - **object** - Object containing type, ownerName, sizes, animated, zeroWidth, and modifier properties. --- ## FFZEmote.fromObject ### Description Converts an emote object back into an FFZEmote instance. ### Parameters - **emoteObject** (object) - Required - Object representation of the emote. - **channel** (Channel) - Required - The channel this emote belongs to. ### Response - **FFZEmote** - A new instance of FFZEmote. ``` -------------------------------- ### Initialize EmoteFetcher Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/index.html Create a new EmoteFetcher instance. Provide Twitch API credentials or an ApiClient for authentication. Configure options like forcing static emotes or setting the theme mode. ```javascript const fetcher = new EmoteFetcher({ // If you want to use emotes from twitch.tv, you will need to be authenticated to use their API. // Option 1: Provide your app ID and secret here (get them at https://dev.twitch.tv/console/apps). twitchAppID, twitchAppSecret, // Option 2: If you need a different way to auth or already use `@twurple/api`, // you can provide your ApiClient object here. apiClient, // Force emotes to be static (non-animated). forceStatic, // - Default: false // Theme mode (background color) preference for Twitch emotes. twitchThemeMode, // <'dark' | 'light'> - Default: 'dark' }) ``` -------------------------------- ### Get Raw BTTV Emotes Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_EmoteFetcher.js.html Fetches raw BTTV emote data for a channel or global emotes. Handles different response formats for channel and global emotes. ```javascript _getRawBTTVEmotes (id) { const endpoint = id ? Constants.BTTV.Channel(id) : Constants.BTTV.Global return fetch(endpoint) .then((response) => response.json()) .then((data) => { // Global emotes if (Array.isArray(data)) return data // Channel emotes if (data?.channelEmotes && data?.sharedEmotes) { return [ ...data.channelEmotes, ...data.sharedEmotes, ] } // Fallback - in case the response format is unexpected return data || [] }) } ``` -------------------------------- ### EmoteParser Constructor Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_EmoteParser.js.html Initializes an EmoteParser with a fetcher and customizable options. Options include allowing NSFW emotes, defining a template for emote representation, specifying the output type (html, markdown, bbcode, plain), and providing a custom regex for matching emotes. Defaults are provided for all options. ```javascript import Constants from '../util/Constants.js' class EmoteParser { /** * A parser to replace text with emotes. * @param {EmoteFetcher} fetcher - The {@linkcode EmoteFetcher} to use the cache of. * @param {object} [options={}] - Options for the parser. * @param {boolean} [options.allowNSFW=false] - Only for 7TV: allow usage of NSFW/unlisted emotes. * @param {string} [options.template=''] - The template to be used. * The strings that can be interpolated are: * - `{link}` The link of the emote. * - `{name}` The name of the emote. * - `{size}` The size index of the image. * - `{creator}` The channel/owner name of the emote. * @param {'html' | 'markdown' | 'bbcode' | 'plain'} [options.type='html'] - The type of the parser. * Can be one of `html`, `markdown`, `bbcode`, or `plain`. * If the `template` option is provided, this is ignored. * @param {RegExp} [options.match=/([^ ]+)/g] - The regular expression that matches an emote. * Must be a global regex, with one capture group for the emote code. */ constructor (fetcher, options = {}) { /** * The {@linkcode EmoteFetcher} being used. * @type {EmoteFetcher} */ this.fetcher = fetcher /** * The parser's options. * @type {object} */ this.options = { allowNSFW: false, template: '', type: 'html', match: /([^ ]+)/g, ...options, } this._validateOptions(this.options) } /** * Validates the parser options. * @private * @param {object} [options] - Options for the parser. * @param {string} [options.template] - The template to be used. * The strings that can be interpolated are: * - `{link}` The link of the emote. * - `{name}` The name of the emote. * - `{size}` The size of the image. * - `{creator}` The channel/owner name of the emote. * @param {'html' | 'markdown' | 'bbcode' | 'plain'} [options.type] - The type of the parser. * Can be one of `html`, `markdown`, `bbcode`, or `plain`. * If the `template` option is provided, this is ignored. * @param {RegExp} [options.match] - The regular expression that matches an emote. * Must be a global regex, with one capture group for the emote code. * @throws {TypeError} When template is not a string. * @throws {TypeError} When type is not one of the supported types. * @throws {TypeError} When match is not a global RegExp. */ _validateOptions (options) { if (options.template && typeof options.template !== 'string') { throw new TypeError('Template must be a string') } if (!['html', 'markdown', 'bbcode', 'plain'].includes(options.type)) { throw new TypeError('Parse type must be one of `html`, `markdown`, `bbcode`, or `plain`') } if (!(options.match instanceof RegExp) || !options.match.global) { throw new TypeError('Match must be a global RegExp.') } } /** * Parses text. ``` -------------------------------- ### TwitchEmote Constructor Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/TwitchEmote.html Initializes a new instance of the TwitchEmote class. ```APIDOC ## Constructor: new TwitchEmote(channel, id, data) ### Description Creates a new instance of a Twitch emote. ### Parameters #### Path Parameters - **channel** (Channel) - Required - The Channel this emote belongs to. - **id** (string) - Required - ID of the emote. - **data** (data) - Required - The raw emote data. ``` -------------------------------- ### Accessing and Using Emotes Source: https://github.com/mkody/twitch-emoticons/blob/master/README.md After fetching emotes, you can access them using the `get` method on the `emotes` property. Emotes can be retrieved by their case-sensitive name and provide properties like ID, code, and a link to the image. ```APIDOC ## Accessing and Using Emotes ### Description After fetching emotes, you can access them using the `get` method on the `emotes` property. Emotes can be retrieved by their case-sensitive name and provide properties like ID, code, and a link to the image. ### Usage `fetcher.emotes.get(emoteName: string): Emote | undefined` ### Emote Properties - `.id` (string) - `.code` (string) - `.ownerName` (string) - `.animated` (boolean) - `.imageType` (string) - `.type` (string) - `.toLink(): string` ### Extended Emote Properties - **FFZ Emotes**: - `.zeroWidth` (boolean) - Indicates if the emote can overlay another. - `.modifier` (boolean) - Indicates if the emote is a modifier effect. - **7TV Emotes**: - `.zeroWidth` (boolean) - Indicates if the emote can overlay another. - `.nsfw` (boolean) - Indicates if the emote is flagged as NSFW or unlisted. ``` -------------------------------- ### EmoteParser Constructor Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/EmoteParser.html Initializes a new EmoteParser instance. It requires an EmoteFetcher and accepts optional configuration for parsing behavior, including NSFW content, templating, output type, and custom matching. ```APIDOC ## new EmoteParser(fetcher, options) ### Description A parser to replace text with emotes. ### Parameters #### Parameters * **fetcher** ([EmoteFetcher](EmoteFetcher.html)) - Required - The [`EmoteFetcher`](EmoteFetcher.html) to use the cache of. * **options** (object) - Optional - Options for the parser. ##### Properties * **allowNSFW** (boolean) - Optional - Only for 7TV: allow usage of NSFW/unlisted emotes. Defaults to `false`. * **template** (string) - Optional - The template to be used. The strings that can be interpolated are: * `{link}` The link of the emote. * `{name}` The name of the emote. * `{size}` The size index of the image. * `{creator}` The channel/owner name of the emote. * **type** ('html' | 'markdown' | 'bbcode' | 'plain') - Optional - The type of the parser. Can be one of `html`, `markdown`, `bbcode`, or `plain`. If the `template` option is provided, this is ignored. Defaults to `'html'`. * **match** (RegExp) - Optional - The regular expression that matches an emote. Must be a global regex, with one capture group for the emote code. Defaults to `/([^\\s]+)/g`. ``` -------------------------------- ### Twitch Emoticons 3.x Initialization and Usage Source: https://github.com/mkody/twitch-emoticons/blob/master/README.md Illustrates the updated way to initialize EmoteFetcher and EmoteParser in version 3.x, using an options object for configuration and demonstrating new parsing and linking methods. ```javascript import { EmoteFetcher, EmoteParser } from '@mkody/twitch-emoticons' // <- Proper imports! const fetcher = new EmoteFetcher({ twitchAppID: '', twitchAppSecret: '', }) // Those next three lines do not have breaking changes await fetcher.fetchTwitchEmotes() const parser = new EmoteParser(fetcher) const emote = emoteFetcher.emotes.get('Kappa') console.log(emote.toLink({ size: 2 })) // <- Uses an object! // https://static-cdn.jtvnw.net/emoticons/v2/25/default/dark/3.0 console.log(parser.parse('Hello CoolCat!')) // <- Does not require :colons: and returns HTML by default! // Hello CoolCat ``` -------------------------------- ### Initialize EmoteFetcher with Existing ApiClient Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_EmoteFetcher.js.html Provide an existing Twurple ApiClient instance to EmoteFetcher if you are already managing API authentication elsewhere. This avoids redundant client creation. ```javascript import { ApiClient } from '@twurple/api' // ... inside EmoteFetcher constructor ... if (options.apiClient) { /** * Provided Twitch {@linkcode ApiClient}. * @type {ApiClient} */ this.apiClient = options.apiClient } ``` -------------------------------- ### FFZEmote toLink Method Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_FFZEmote.js.html Generates the URL for an FFZ emote image. Supports different sizes and can force static images. ```javascript /** * Gets the image link of the emote. * @param {object} [options] - Options for the link. * @param {number} [options.size=0] - Size (scale) for the emote. * @param {boolean} [options.forceStatic] - Whether to force the emote to be static (non-animated). Defaults to the fetcher's forceStatic or `false`. * @returns {string} - The URL to the emote. */ toLink (options) { const { size = 0, forceStatic = this.fetcher.forceStatic || false, } = options || {} const sizeKey = this.sizes[size] if (this.animated && !forceStatic) return Constants.FFZ.CDNAnimated(this.id, sizeKey) return Constants.FFZ.CDN(this.id, sizeKey) } ``` -------------------------------- ### Twitch Emoticons 2.x Initialization and Usage Source: https://github.com/mkody/twitch-emoticons/blob/master/README.md Shows the older method of initializing EmoteFetcher and EmoteParser, including how to fetch Twitch emotes and parse text with emotes in version 2.x. ```javascript import TwitchEmoticons from '@mkody/twitch-emoticons' // This actually still works, for compatibility's sake, const { EmoteFetcher, EmoteParser } = TwitchEmoticons // but you should move away from this... const fetcher = new EmoteFetcher('', '') // <- The first two parameters were for the Twitch app ID/secret // Those next three lines do not have breaking changes await fetcher.fetchTwitchEmotes() // Do note that CommonJS does not handle `await` at the top level const parser = new EmoteParser(fetcher) const emote = emoteFetcher.emotes.get('Kappa') console.log(emote.toLink(2)) // <- Only the size was available and set as the first parameter // https://static-cdn.jtvnw.net/emoticons/v2/25/default/dark/3.0 console.log(parser.parse('Hello :CoolCat:!')) // <- Used colons and returned Markdown by default // Hello ![CoolCat](https://static-cdn.jtvnw.net/emoticons/v2/58127/default/dark/1.0 "CoolCat")! ``` -------------------------------- ### CommonJS Import for Twitch Emoticons Source: https://github.com/mkody/twitch-emoticons/blob/master/README.md Demonstrates how to import the library using CommonJS syntax, which is compatible with the build provided by the library. ```javascript const { EmoteFetcher, EmoteParser } = require('@mkody/twitch-emoticons') ``` -------------------------------- ### BTTVEmote from Object Creation Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/BTTVEmote.html Creates a BTTVEmote instance from an object representation. ```APIDOC ## POST /emotes/fromObject ### Description Converts an emote Object into a [`BTTVEmote`](BTTVEmote.html). ### Method POST ### Endpoint /emotes/fromObject ### Parameters #### Request Body - **emoteObject** (object) - Optional - Object representation of this emote. - **channel** (Channel) - Optional - [`Channel`](Channel.html) this emote belongs to. ### Response #### Success Response (200) - **btvEmote** ([BTTVEmote](BTTVEmote.html)) - A [`BTTVEmote`](BTTVEmote.html) instance. #### Response Example { "btvEmote": { "id": "5d5a9f4297f44300073492f2", "code": "PogChamp", "userId": "54c1021697f44300073492f0", "name": "PogChamp", "images": { "url": "https://cdn.betterttv.net/emote/5d5a9f4297f44300073492f2/2x.webp", "staticUrl": "https://cdn.betterttv.net/emote/5d5a9f4297f44300073492f2/1x.webp" }, "emoteType": "betterttv", "subscriptions": [ "54c1021697f44300073492f0" ] } } ``` -------------------------------- ### FFZEmote toObject Method Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_FFZEmote.js.html Converts an FFZEmote instance into a plain JavaScript object representation. ```javascript /** * Override of the override for `toObject`. * Will result in an Object representation of a {@linkcode FFZEmote}. * @returns {object} - Object representation of the {@linkcode FFZEmote}. */ toObject () { return { ...super.toObject(), type: this.type, ownerName: this.ownerName, sizes: this.sizes, animated: this.animated, zeroWidth: this.zeroWidth, modifier: this.modifier, } } ``` -------------------------------- ### TwitchEmote Methods Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/TwitchEmote.html Methods available on the TwitchEmote instance. ```APIDOC ## Method: toLink(options) ### Description Gets the image link of the emote. ### Parameters #### Query Parameters - **options** (object) - Optional - Configuration options for the link generation. ### Response #### Success Response (200) - **string** - The URL of the emote image. ``` -------------------------------- ### Configure EmoteFetcher Options Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_EmoteFetcher.js.html Set various options during EmoteFetcher initialization, such as forcing static emotes, specifying Twitch theme mode, or providing a pre-configured ApiClient. ```javascript /** * Fetches and caches emotes. * @param {object} [options={}] Fetcher's options. * @param {string} [options.twitchAppID] Your app ID for the Twitch API. * @param {string} [options.twitchAppSecret] Your app secret for the Twitch API. * @param {ApiClient} [options.apiClient] - Bring your own Twurple {@linkcode ApiClient}. * @param {boolean} [options.forceStatic=false] - Force emotes to be static (non-animated). * @param {'dark' | 'light'} [options.twitchThemeMode='dark'] - Theme mode (background color) preference for Twitch emotes. */ constructor (options = {}) { // ... constructor logic ... this.forceStatic = options.forceStatic || false this.twitchThemeMode = options.twitchThemeMode || 'dark' // ... constructor logic ... } ``` -------------------------------- ### Fetch 7TV Emotes in AVIF Format Source: https://github.com/mkody/twitch-emoticons/blob/master/README.md Retrieve 7TV global emotes in AVIF format by calling `fetchSevenTVEmotes` with `null` for the channel ID and `{ format: 'avif' }`. The default format is WEBP. ```javascript // (setup) import { EmoteFetcher } from '@mkody/twitch-emoticons' const fetcher = new EmoteFetcher() // Fetch global emotes in AVIF (channel id has to be `null` for global) await fetcher.fetchSevenTVEmotes(null, { format: 'avif' }) // Fetch 0kody's emotes with the package's default format (WEBP) await fetcher.fetchSevenTVEmotes(44317909) // ... which is currently the same as await fetcher.fetchSevenTVEmotes(44317909, { format: 'webp' }) // Fetch Nerixyz's emotes in AVIF await fetcher.fetchSevenTVEmotes(129546453, { format: 'avif' }) ``` -------------------------------- ### fromObject Source: https://github.com/mkody/twitch-emoticons/blob/master/docs/struct_SevenTVEmote.js.html Creates a SevenTVEmote instance from a given object representation. ```APIDOC ## fromObject(emoteObject, channel) ### Description Constructs a `SevenTVEmote` instance from an object that contains its data. ### Method static fromObject ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **emoteObject** (object) - Optional. The object representation of the emote. * **channel** (Channel) - Optional. The `Channel` object this emote belongs to. ### Returns * **SevenTVEmote** - A new `SevenTVEmote` instance created from the provided object. ``` -------------------------------- ### Basic Twitch Emote Parsing Source: https://github.com/mkody/twitch-emoticons/blob/master/README.md Demonstrates basic emote fetching and parsing with Markdown output. Requires Twitch app credentials and loads global emotes. ```javascript import { EmoteFetcher, EmoteParser } from '@mkody/twitch-emoticons' const fetcher = new EmoteFetcher({ // Put your Twitch app keys here. twitchAppID: '', twitchAppSecret: '', }) const parser = new EmoteParser(fetcher, { type: 'markdown', // Can be `html` (default), `markdown`, `bbcode`, or `plain`. // You can also set your own output, see example 3. match: /:(.+?):/g, // Requires emotes to be between colons (:Kappa:). // The default `/([^ ]+)/g` matches any non-whitespace // characters, similar to regular Twitch chat. }) await fetcher.fetchTwitchEmotes(null) // `null` or a missing parameter will load "global" emotes. const kappa = fetcher.emotes.get('Kappa').toLink() console.log(kappa) // https://static-cdn.jtvnw.net/emoticons/v2/25/default/dark/1.0 const text = 'Hello :CoolCat:!' const parsed = parser.parse(text) console.log(parsed) // Hello ![CoolCat](https://static-cdn.jtvnw.net/emoticons/v2/58127/default/dark/1.0 "CoolCat")! ```