@tixyel/streamelements 6.4.9 → 6.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -220,6 +220,69 @@ declare namespace YoutubeEvents {
220
220
  }
221
221
  }
222
222
 
223
+ type TwitchEmote = {
224
+ type: 'twitch';
225
+ name: string;
226
+ id: string;
227
+ gif: boolean;
228
+ urls: {
229
+ '1': string;
230
+ '2': string;
231
+ '4': string;
232
+ };
233
+ start: number;
234
+ end: number;
235
+ };
236
+ type SeventvEmote = {
237
+ type: '7tv';
238
+ name: string;
239
+ id: string;
240
+ gif: boolean;
241
+ animated: boolean;
242
+ urls: {
243
+ '1': string;
244
+ '2': string;
245
+ '3': string;
246
+ '4': string;
247
+ };
248
+ start: number;
249
+ end: number;
250
+ cords: {
251
+ x: number;
252
+ y: number;
253
+ };
254
+ };
255
+ type BttvEmote = {
256
+ type: 'bttv';
257
+ name: string;
258
+ id: string;
259
+ gif: boolean;
260
+ animated: boolean;
261
+ urls: {
262
+ '1': string;
263
+ '2': string;
264
+ '4': string;
265
+ };
266
+ start: number;
267
+ end: number;
268
+ coords: {
269
+ x: number;
270
+ y: number;
271
+ width: number;
272
+ height: number;
273
+ };
274
+ };
275
+ type Emoji = {
276
+ type: 'emoji';
277
+ name: string;
278
+ id: string;
279
+ gif: boolean;
280
+ urls: {
281
+ '1': string;
282
+ };
283
+ };
284
+ type Emote = TwitchEmote | BttvEmote | SeventvEmote | Emoji;
285
+
223
286
  type PathValue<T, P extends string> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? PathValue<T[K], Rest> : never : P extends keyof T ? T[P] : never;
224
287
  type MapNumberValuesToString<T> = {
225
288
  [K in keyof T]: T[K] extends number ? `${T[K]}` | ReturnType<T[K]['toString']> : T[K];
@@ -419,19 +482,6 @@ declare namespace TwitchEvents {
419
482
  description: string;
420
483
  url: string;
421
484
  };
422
- type Emote = {
423
- type: string;
424
- name: string;
425
- id: string;
426
- gif: boolean;
427
- urls: {
428
- '1': string;
429
- '2': string;
430
- '4': string;
431
- };
432
- start: number;
433
- end: number;
434
- };
435
485
  export {};
436
486
  }
437
487
  namespace DeleteMessage {
@@ -1570,60 +1620,6 @@ declare namespace StreamElementsEvents {
1570
1620
  }
1571
1621
  }
1572
1622
 
1573
- type TwitchEmote = {
1574
- type: 'twitch';
1575
- name: string;
1576
- id: string;
1577
- gif: boolean;
1578
- urls: {
1579
- '1': string;
1580
- '2': string;
1581
- '4': string;
1582
- };
1583
- start: number;
1584
- end: number;
1585
- };
1586
- type SeventvEmote = {
1587
- type: '7tv';
1588
- name: string;
1589
- id: string;
1590
- gif: boolean;
1591
- animated: boolean;
1592
- urls: {
1593
- '1': string;
1594
- '2': string;
1595
- '3': string;
1596
- '4': string;
1597
- };
1598
- start: number;
1599
- end: number;
1600
- cords: {
1601
- x: number;
1602
- y: number;
1603
- };
1604
- };
1605
- type BttvEmote = {
1606
- type: 'bttv';
1607
- name: string;
1608
- id: string;
1609
- gif: boolean;
1610
- animated: boolean;
1611
- urls: {
1612
- '1': string;
1613
- '2': string;
1614
- '4': string;
1615
- };
1616
- start: number;
1617
- end: number;
1618
- coords: {
1619
- x: number;
1620
- y: number;
1621
- width: number;
1622
- height: number;
1623
- };
1624
- };
1625
- type Emote = TwitchEmote | BttvEmote | SeventvEmote;
1626
-
1627
1623
  /**
1628
1624
  * EventProvider class for managing event listeners and emitters.
1629
1625
  * This class allows you to register event listeners, emit events, and manage event subscriptions.
@@ -2112,655 +2108,133 @@ declare class useComfyJs extends EventProvider<ComfyEvents> {
2112
2108
  private connect;
2113
2109
  }
2114
2110
 
2115
- declare namespace Helper {
2116
- namespace number {
2117
- /**
2118
- * Translate number to words
2119
- * @param num - Number to translate
2120
- * @param type - Translation type
2121
- * @returns - Number in words
2122
- * @example
2123
- * ```javascript
2124
- * const cardinal = Simulation.number.translate(42, 'cardinal');
2125
- * console.log(cardinal); // "forty-two"
2126
- * ```
2127
- */
2128
- function translate(num: number, type?: 'cardinal' | 'ordinal' | 'suffix'): string;
2129
- /**
2130
- * Balances a number within a specified range
2131
- * @param amount - Number to balance
2132
- * @param min - Minimum value
2133
- * @param max - Maximum value
2134
- * @param decimals - Number of decimal places to round to (default is 0)
2135
- * @returns - Balanced number
2136
- * @example
2137
- * ```javascript
2138
- * const balancedValue = Simulation.number.balance(150, 0, 100);
2139
- * console.log(balancedValue); // 100
2140
- * ```
2141
- */
2142
- function balance(amount: number, min?: number, max?: number, decimals?: number): number;
2143
- /**
2144
- * Rounds a number to a specified number of decimal places
2145
- * @param value - Number to round
2146
- * @param decimals - Number of decimal places (default is 2)
2147
- * @returns Rounded number
2148
- * @example
2149
- * ```javascript
2150
- * const roundedValue = Simulation.number.round(3.14159, 3);
2151
- * console.log(roundedValue); // 3.142
2152
- * ```
2153
- */
2154
- function round(value: number, decimals?: number): number;
2155
- /**
2156
- * Generate random number
2157
- * @param min - Minimum value
2158
- * @param max - Maximum value
2159
- * @param float - Number of decimal places (0 for integer)
2160
- * @returns - Random number
2161
- * @example
2162
- * ```javascript
2163
- * const intNumber = number.random(1, 10);
2164
- * console.log(intNumber); // e.g. 7
2165
- *
2166
- * const floatNumber = number.random(1, 10, 2);
2167
- * console.log(floatNumber); // e.g. 3.14
2168
- * ```
2169
- */
2170
- function number(min: number, max: number, float?: number): number;
2171
- }
2172
- namespace element {
2173
- interface ScaleOptions<T extends HTMLElement> {
2174
- /**
2175
- * The parent element to use for scaling calculations. If not provided, the element's parent will be used.
2176
- */
2177
- parent?: HTMLElement;
2178
- /**
2179
- * The preferred dimension to base the scaling on. Can be 'width', 'height', or 'auto' (default).
2180
- */
2181
- prefer?: 'width' | 'height' | 'auto';
2111
+ type BadgeOptions = Twitch.roles[] | Twitch.roles | `${Twitch.roles}/${number}` | `${Twitch.roles}/${number}`[];
2112
+ type TwitchResult = {
2113
+ keys: Twitch.roles[];
2114
+ badges: Twitch.badge[];
2115
+ amount: {
2116
+ [K in Twitch.roles]?: number;
2117
+ };
2118
+ };
2119
+ type YouTubeResult = {
2120
+ isVerified: boolean;
2121
+ isChatOwner: boolean;
2122
+ isChatSponsor: boolean;
2123
+ isChatModerator: boolean;
2124
+ };
2125
+ declare class MessageHelper {
2126
+ /**
2127
+ * Finds emotes in a given text.
2128
+ * @param text - The text to search for emotes.
2129
+ * @param emotes - An array of emotes to search for. Defaults to Local data emotes.
2130
+ * @returns An array of emotes found in the text with their positions.
2131
+ */
2132
+ findEmotesInText(text: string, emotes?: Emote[]): Emote[];
2133
+ /**
2134
+ * Replaces emotes in the text with corresponding HTML image tags.
2135
+ * @param text - The text containing emotes.
2136
+ * @param emotes - An array of emotes with their positions in the text.
2137
+ * @returns The text with emotes replaced by HTML image tags.
2138
+ */
2139
+ replaceEmotesWithHTML(text: string, emotes: Emote[]): string;
2140
+ /**
2141
+ * Checks if the text contains only emotes and whitespace.
2142
+ * @param text - The text to check.
2143
+ * @param emotes - An array of emotes with their positions in the text.
2144
+ * @returns True if the text contains only emotes and whitespace, false otherwise.
2145
+ */
2146
+ hasOnlyEmotes(text: string, emotes: Emote[]): boolean;
2147
+ /**
2148
+ * Replaces YouTube emotes in the text with corresponding HTML image tags.
2149
+ * @param text - The text containing YouTube emotes.
2150
+ * @param emotes - An array of YouTube emotes. Defaults to Local data YouTube emotes.
2151
+ * @returns The text with YouTube emotes replaced by HTML image tags.
2152
+ */
2153
+ replaceYoutubeEmotesWithHTML(text: string, emotes?: {
2154
+ emojiId: string;
2155
+ shortcuts: string[];
2156
+ searchTerms: string[];
2157
+ image: {
2158
+ thumbnails: {
2159
+ url: string;
2160
+ width: number;
2161
+ height: number;
2162
+ }[];
2163
+ accessibility: {
2164
+ accessibilityData: {
2165
+ label: string;
2166
+ };
2167
+ };
2168
+ };
2169
+ isCustomEmoji: boolean;
2170
+ index: number;
2171
+ }[]): string;
2172
+ /**
2173
+ * Generates badge data based on the provided badges and platform.
2174
+ * @param badges - The badges to generate. Can be an array or a comma-separated string.
2175
+ * @param provider - The platform provider ('twitch' or 'youtube'). Defaults to 'twitch'.
2176
+ * @returns A promise that resolves to the generated badge data.
2177
+ * @example
2178
+ * ```javascript
2179
+ * // Generate Twitch badges
2180
+ * const twitchBadges = await generateBadges(['broadcaster', 'moderator'], 'twitch');
2181
+ * // Generate YouTube badges
2182
+ * const youtubeBadges = await generateBadges('sponsor, moderator', 'youtube');
2183
+ * ```
2184
+ */
2185
+ generateBadges<T extends Provider$1>(badges: BadgeOptions | undefined, provider: T): Promise<T extends 'twitch' ? TwitchResult : YouTubeResult>;
2186
+ }
2187
+
2188
+ declare namespace Local {
2189
+ type QueueItem = {
2190
+ listener: 'onEventReceived';
2191
+ data: StreamElements.Event.onEventReceived;
2192
+ session?: boolean;
2193
+ } | {
2194
+ listener: 'onWidgetLoad';
2195
+ data: StreamElements.Event.onWidgetLoad;
2196
+ } | {
2197
+ listener: 'onSessionUpdate';
2198
+ data: StreamElements.Event.onSessionUpdate;
2199
+ };
2200
+ const queue: useQueue<QueueItem>;
2201
+ const generate: {
2202
+ session: {
2203
+ types: Record<string, StreamElements.Session.Config.Any>;
2204
+ available(): StreamElements.Session.Config.Available.Data;
2205
+ get(startSession?: StreamElements.Session.Data): Promise<StreamElements.Session.Data>;
2206
+ };
2207
+ event: {
2182
2208
  /**
2183
- * The minimum percentage of the parent size to scale to. Default is 0.
2209
+ * Simulates the onWidgetLoad event for a widget.
2210
+ * @param fields - The field values to be included in the event.
2211
+ * @param session - The session data to be included in the event.
2212
+ * @param currency - The currency to be used (default is 'USD').
2213
+ * @returns A Promise that resolves to the simulated onWidgetLoad event data.
2184
2214
  */
2185
- min?: number;
2215
+ onWidgetLoad(fields: Record<string, StreamElements.CustomField.Value>, session: StreamElements.Session.Data, currency?: "BRL" | "USD" | "EUR"): Promise<StreamElements.Event.onWidgetLoad>;
2186
2216
  /**
2187
- * The maximum percentage of the parent size to scale to. Default is 1 (100%).
2217
+ * Simulates the onSessionUpdate event for a widget.
2218
+ * @param session - The session data to be included in the event.
2219
+ * @returns A Promise that resolves to the simulated onSessionUpdate event data.
2188
2220
  */
2189
- max?: number;
2221
+ onSessionUpdate(session?: StreamElements.Session.Data, update?: ClientEvents$1): Promise<StreamElements.Event.onSessionUpdate>;
2190
2222
  /**
2191
- * A callback function that is called after scaling is applied.
2192
- * @param this - The HTML element being scaled.
2193
- * @param number - The scale factor applied to the element.
2194
- * @param element - The HTML element being scaled.
2195
- * @returns void
2223
+ * Simulates the onEventReceived event for a widget.
2224
+ * @param provider - The provider of the event (default is 'random').
2225
+ * @param type - The type of event to simulate (default is 'random').
2226
+ * @param options - Additional options to customize the event data.
2227
+ * @returns A Promise that resolves to the simulated onEventReceived event data, or null if the event type is not supported.
2228
+ * @example
2229
+ * ```javascript
2230
+ * // Simulate a random event
2231
+ * const randomEvent = await Local .generate.event.onEventReceived();
2232
+ *
2233
+ * // Simulate a Twitch message event with custom options
2234
+ * const twitchMessageEvent = await Local .generate.event.onEventReceived('twitch', 'message', { name: 'Streamer', message: 'Hello World!' });
2235
+ * ```
2196
2236
  */
2197
- apply?: (this: T, number: number, element: T) => void;
2198
- }
2199
- type FitTextOptions = {
2200
- minFontSize?: number;
2201
- maxFontSize?: number;
2202
- parent?: HTMLElement;
2203
- };
2204
- /**
2205
- * Merges outer span styles with inner span styles in the provided HTML string.
2206
- * @param outerStyle - The style string to be applied to the outer span.
2207
- * @param innerHTML - The inner HTML string which may contain a span with its own styles.
2208
- * @returns A new HTML string with merged styles applied to a single span.
2209
- * @example
2210
- * ```javascript
2211
- * const result = mergeSpanStyles("color: red; font-weight: bold;", '<span style="font-size: 14px;">Hello World</span>');
2212
- * console.log(result); // Output: '<span style="font-size: 14px; color: red; font-weight: bold;">Hello World</span>'
2213
- * ```
2214
- */
2215
- function mergeSpanStyles(outerStyle: string, innerHTML: string, className?: string): string;
2216
- /**
2217
- * Scales an HTML element to fit within its parent element based on specified minimum and maximum scale factors.
2218
- * @param element - The HTML element to be scaled.
2219
- * @param min - Minimum scale factor (default is 0).
2220
- * @param max - Maximum scale factor (default is 1).
2221
- * @param options - Optional settings for scaling.
2222
- * @returns - An object containing the new width, height, and scale factor, or void if not applied.
2223
- * @example
2224
- * ```javascript
2225
- * const element = document.getElementById('myElement');
2226
- * scale(element, 0.5, 1, { return: false });
2227
- * ```
2228
- */
2229
- function scale(element: HTMLElement, min?: number, max?: number, options?: {
2230
- return: boolean;
2231
- parent: HTMLElement;
2232
- base: 'width' | 'height';
2233
- }): {
2234
- width: number;
2235
- height: number;
2236
- scale: number;
2237
- } | void;
2238
- /**
2239
- * Scales an HTML element to fit within its parent element based on specified options.
2240
- * @param element - The HTML element to be scaled.
2241
- * @param options - Optional settings for scaling.
2242
- * @returns The scale factor applied to the element.
2243
- * @example
2244
- * ```javascript
2245
- * const element = document.getElementById('myElement');
2246
- * const scaleFactor scalev2(element, {
2247
- * min: 0.5,
2248
- * max: 1,
2249
- * prefer: 'width',
2250
- * apply: (scale, el) => el.style.transform = `scale(${scale})`
2251
- * });
2252
- * console.log(`Element scaled by a factor of ${scaleFactor}`);
2253
- * ```
2254
- */
2255
- function scalev2<T extends HTMLElement>(element: T, options?: ScaleOptions<T>): number;
2256
- /**
2257
- * Fits the text within the parent element by adjusting the font size.
2258
- * @param element - The HTML element containing the text to be fitted.
2259
- * @param compressor - A multiplier to adjust the fitting sensitivity (default is 1).
2260
- * @param options - Optional settings for fitting text.
2261
- * @returns The HTML element with adjusted font size.
2262
- * @example
2263
- * ```javascript
2264
- * const element = document.getElementById('myTextElement');
2265
- * fitText(element, 1, { minFontSize: 12, maxFontSize: 36 });
2266
- * console.log(`Adjusted font size: ${element.style.fontSize}`);
2267
- * ```
2268
- */
2269
- function fitText(element: HTMLElement, compressor?: number, options?: FitTextOptions): HTMLElement;
2270
- /**
2271
- * Wraps formatted HTML text with containers and splits characters into indexed spans.
2272
- * Adds 'container' class and data-index to all parent elements, and wraps each character in a span with class 'char' and data-index.
2273
- * @param htmlString - The input HTML string containing formatted text elements (span, strong, em, etc).
2274
- * @param startIndex - The starting index for the data-index attribute (default is 0).
2275
- * @returns - A new HTML string with containers and character-level indexing.
2276
- * @example
2277
- * ```javascript
2278
- * const result = splitTextToChars('<span>TesTe</span> <strong>bold</strong>', 0);
2279
- * console.log(result);
2280
- * // Output: '<span class="container" data-index="0"><span class="char" data-index="0">T</span><span class="char" data-index="1">e</span>...'
2281
- * ```
2282
- */
2283
- function splitTextToChars(htmlString: string, startIndex?: number, preserveInterElementWhitespace?: boolean): string;
2284
- }
2285
- namespace object {
2286
- /**
2287
- * Flattens a nested object into a single-level object with dot-separated keys.
2288
- * @param obj - The nested object to be flattened.
2289
- * @param prefix - The prefix to be added to each key (used for recursion).
2290
- * @returns A flattened object with dot-separated keys.
2291
- * @example
2292
- * ```javascript
2293
- * const nestedObj = { a: { b: 1, c: { d: 2 } }, e: [3, 4] };
2294
- * const flatObj = flatten(nestedObj);
2295
- * console.log(flatObj);
2296
- * // Output: { 'a.b': '1', 'a.c.d': '2', 'e:0': '3', 'e:1': '4' }
2297
- * ```
2298
- */
2299
- function flatten(obj: Record<string, any>, stringify?: boolean, prefix?: string): Record<string, typeof stringify extends true ? string : string | number | boolean>;
2300
- /**
2301
- * Returns the entries of an object as an array of key-value pairs, with proper typing.
2302
- * @param obj - The object to retrieve entries from.
2303
- * @returns An array of key-value pairs from the object, typed as an array of tuples with key and value types.
2304
- */
2305
- function entries<K extends string, V>(obj: Record<K, V>): [K, V][];
2306
- /**
2307
- * Returns the values of an object as an array, with proper typing.
2308
- * @param obj - The object to retrieve values from.
2309
- * @returns An array of values from the object, typed as an array of the value type.
2310
- */
2311
- function values<K extends string, V>(obj: Record<K, V>): V[];
2312
- /**
2313
- * Returns the keys of an object as an array of strings, with proper typing.
2314
- * @param obj - The object to retrieve keys from.
2315
- * @returns An array of keys from the object, typed as an array of strings.
2316
- */
2317
- function keys<K extends string, V>(obj: Record<K, V>): K[];
2318
- }
2319
- namespace message {
2320
- type BadgeOptions = Twitch.roles[] | Twitch.roles | `${Twitch.roles}/${number}` | `${Twitch.roles}/${number}`[];
2321
- type TwitchResult = {
2322
- keys: Twitch.roles[];
2323
- badges: Twitch.badge[];
2324
- amount: {
2325
- [K in Twitch.roles]?: number;
2326
- };
2327
- };
2328
- type YouTubeResult = {
2329
- isVerified: boolean;
2330
- isChatOwner: boolean;
2331
- isChatSponsor: boolean;
2332
- isChatModerator: boolean;
2333
- };
2334
- /**
2335
- * Finds emotes in a given text.
2336
- * @param text - The text to search for emotes.
2337
- * @param emotes - An array of emotes to search for. Defaults to Local data emotes.
2338
- * @returns An array of emotes found in the text with their positions.
2339
- */
2340
- function findEmotesInText(text: string, emotes?: Emote[]): Emote[];
2341
- /**
2342
- * Replaces emotes in the text with corresponding HTML image tags.
2343
- * @param text - The text containing emotes.
2344
- * @param emotes - An array of emotes with their positions in the text.
2345
- * @returns The text with emotes replaced by HTML image tags.
2346
- */
2347
- function replaceEmotesWithHTML(text: string, emotes: Emote[]): string;
2348
- /**
2349
- * Replaces YouTube emotes in the text with corresponding HTML image tags.
2350
- * @param text - The text containing YouTube emotes.
2351
- * @param emotes - An array of YouTube emotes. Defaults to Local data YouTube emotes.
2352
- * @returns The text with YouTube emotes replaced by HTML image tags.
2353
- */
2354
- function replaceYoutubeEmotesWithHTML(text: string, emotes?: {
2355
- emojiId: string;
2356
- shortcuts: string[];
2357
- searchTerms: string[];
2358
- image: {
2359
- thumbnails: {
2360
- url: string;
2361
- width: number;
2362
- height: number;
2363
- }[];
2364
- accessibility: {
2365
- accessibilityData: {
2366
- label: string;
2367
- };
2368
- };
2369
- };
2370
- isCustomEmoji: boolean;
2371
- index: number;
2372
- }[]): string;
2373
- /**
2374
- * Generates badge data based on the provided badges and platform.
2375
- * @param badges - The badges to generate. Can be an array or a comma-separated string.
2376
- * @param provider - The platform provider ('twitch' or 'youtube'). Defaults to 'twitch'.
2377
- * @returns A promise that resolves to the generated badge data.
2378
- * @example
2379
- * ```javascript
2380
- * // Generate Twitch badges
2381
- * const twitchBadges = await generateBadges(['broadcaster', 'moderator'], 'twitch');
2382
- * // Generate YouTube badges
2383
- * const youtubeBadges = await generateBadges('sponsor, moderator', 'youtube');
2384
- * ```
2385
- */
2386
- function generateBadges<T extends Provider$1>(badges: BadgeOptions | undefined, provider: T): Promise<T extends 'twitch' ? TwitchResult : YouTubeResult>;
2387
- }
2388
- namespace event {
2389
- /**
2390
- * Parses the provider information from the event detail object.
2391
- * @param detail - The event detail object received from the StreamElements event.
2392
- * @returns An object containing the provider and the original event data.
2393
- */
2394
- function parseProvider(detail: StreamElements.Event.onEventReceived, _provider?: Provider$1): ClientEvents$1;
2395
- }
2396
- namespace string {
2397
- type Modifier = (value: string, param: string | null | undefined, values: {
2398
- amount?: number;
2399
- count?: number;
2400
- }) => string;
2401
- const PRESETS: Record<string, string>;
2402
- /**
2403
- * Replaces occurrences in a string based on a pattern with the result of an asynchronous callback function.
2404
- * @param string - The input string to perform replacements on.
2405
- * @param pattern - The pattern to match in the string (can be a string or a regular expression).
2406
- * @param callback - An asynchronous callback function that takes the matched substring and any captured groups as arguments and returns the replacement string.
2407
- * @returns A promise that resolves to the modified string with replacements applied.
2408
- * @example
2409
- * ```javascript
2410
- * const result = await string.replace("Hello World", /World/, async (match) => {
2411
- * return await fetchSomeData(match); // Assume this function fetches data asynchronously
2412
- * });
2413
- * console.log(result); // Output will depend on the fetched data
2414
- * ```
2415
- */
2416
- function replace(string: string, pattern: string, callback: (match: string, ...groups: string[]) => Promise<string> | string): Promise<string>;
2417
- /**
2418
- * Capitalizes the first letter of a given string.
2419
- * @param string - The input string to be capitalized.
2420
- * @returns The capitalized string.
2421
- * @example
2422
- * ```javascript
2423
- * const result = string.capitalize("hello world");
2424
- * console.log(result); // Output: "Hello world"
2425
- * ```
2426
- */
2427
- function capitalize(string: string): Capitalize<string>;
2428
- /**
2429
- * Composes a template string by replacing placeholders with corresponding values and applying optional modifiers.
2430
- * @param template - The template string containing placeholders in the format {key} and optional modifiers in the format [MODIFIER:param=value].
2431
- * @param values - An object containing key-value pairs to replace the placeholders in the template.
2432
- * @param options - Optional settings for the composition process.
2433
- * @returns The composed string with placeholders replaced and modifiers applied.
2434
- * @example
2435
- * ```javascript
2436
- * const { string } = Tixyel.Helper;
2437
- *
2438
- * // Basic usage with placeholders and simple modifiers
2439
- * const template1 = "Hello, {username}! You have {amount} [UPC=messages] and your name is [CAP=name].";
2440
- * const values1 = { username: "john_doe", amount: 5, name: "john" };
2441
- * const result1 = string.compose(template1, values1);
2442
- * // "Hello, john_doe! You have 5 MESSAGES and your name is John."
2443
- *
2444
- * // Multiple modifiers in a single block (HTML enabled)
2445
- * const template2 = "[COLOR:#ff0056,BOLD={username}]";
2446
- * const values2 = { username: "john_doe" };
2447
- * const result2 = string.compose(template2, values2, { html: true });
2448
- * // '<span class="color bold" style="color: #ff0056; font-weight: bold;">john_doe</span>'
2449
- *
2450
- * // Conditional rendering with IF (supports ===, >=, &&, ||, !, etc.)
2451
- * const template3 = "[IF=vip && status === 'live'?VIP Online|Offline]";
2452
- * const values3 = { status: 'live', vip: true };
2453
- * const result3 = string.compose(template3, values3);
2454
- * // "VIP Online"
2455
- *
2456
- * // Pluralization using amount / count or an explicit key
2457
- * const template4 = "You have {amount} [PLURAL=message|messages].";
2458
- * const values4 = { amount: 1 };
2459
- * const values5 = { amount: 3 };
2460
- * const result4a = string.compose(template4, values4); // "You have 1 message."
2461
- * const result4b = string.compose(template4, values5); // "You have 3 messages."
2462
- *
2463
- * // Number formatting
2464
- * const template5 = "Total: [NUMBER:2=amount] {currency}";
2465
- * const values6 = { amount: 1234.5, currency: '$' };
2466
- * const result5 = string.compose(template5, values6);
2467
- * // e.g. "Total: 1,234.50 $" (locale dependent)
2468
- *
2469
- * // Date and time formatting
2470
- * const template6 = "Created at: [DATE:iso=createdAt] ([DATE:relative=createdAt])";
2471
- * const values7 = { createdAt: new Date('2020-01-02T03:04:05.000Z') };
2472
- * const result6 = string.compose(template6, values7);
2473
- * // e.g. "Created at: 2020-01-02T03:04:05.000Z (Xs ago)"
2474
- *
2475
- * // MAP / SWITCH style mapping
2476
- * const template7 = "Status: [MAP:status=live:Online|offline:Offline|default:Unknown]";
2477
- * const values8 = { status: 'offline' };
2478
- * const result7 = string.compose(template7, values8);
2479
- * // "Status: Offline"
2480
- *
2481
- * // Escaping HTML
2482
- * const template8 = "[ESCAPE={message}]";
2483
- * const values9 = { message: '<b>Danger & "HTML"</b>' };
2484
- * const result8 = string.compose(template8, values9);
2485
- * // "&lt;b&gt;Danger &amp; &quot;HTML&quot;&lt;/b&gt;"
2486
- *
2487
- * // Using global presets
2488
- * Helper.string.PRESETS['alert'] = 'BOLD,COLOR:#ff0056';
2489
- * const template10 = "[PRESET:alert={username}]";
2490
- * const values11 = { username: 'john_doe' };
2491
- * const result10 = string.compose(template10, values11, { html: true });
2492
- * // '<span class="color bold" style="color: #ff0056; font-weight: bold;">john_doe</span>'
2493
- * ```
2494
- */
2495
- function compose(template: string, values?: Record<string, any>, options?: {
2496
- method?: 'loop' | 'index';
2497
- html?: boolean;
2498
- debug?: boolean;
2499
- modifiers?: Record<string, Modifier>;
2500
- aliases?: Record<string, string[]>;
2501
- }): string;
2502
- }
2503
- namespace sound {
2504
- let playing: boolean;
2505
- let audio: AudioContext;
2506
- /**
2507
- * Play sound from URL with optional volume and replace parameters
2508
- * @param url - Sound URL to play
2509
- * @param volume - Volume level from 0 to 100 (default: 100)
2510
- * @param replace - If true, replaces currently playing sound (default: false)
2511
- */
2512
- function play(url: string, volume?: number, replace?: boolean): void;
2513
- }
2514
- namespace color {
2515
- /**
2516
- * Generate opacity hex value
2517
- * @param opacity - Opacity value from 0 to 100
2518
- * @param color - Hex color code
2519
- * @returns - Hex color code with opacity
2520
- */
2521
- function opacity(opacity?: number, color?: string): string;
2522
- /**
2523
- * Extract color and opacity from hex code
2524
- * @param hex - Hex color code
2525
- * @returns - Object with color and opacity
2526
- */
2527
- function extract(hex: string): {
2528
- color: string;
2529
- opacity: number;
2530
- };
2531
- /**
2532
- * Validate color string format
2533
- * @param str - Color string to validate
2534
- * @returns Detected color format or false if invalid
2535
- * @example
2536
- * ```javascript
2537
- * const format1 = color.validate("#FF5733"); // "hex"
2538
- * const format2 = color.validate("rgb(255, 87, 51)"); // "rgb"
2539
- * const format3 = color.validate("hsl(14, 100%, 60%)"); // "hsl"
2540
- * const format4 = color.validate("orangered"); // "css-color-name"
2541
- * const format5 = color.validate("invalid-color"); // false
2542
- * ```
2543
- */
2544
- function validate(str: string): false | "hex" | "rgb" | "rgba" | "hsl" | "hsla" | "css-color-name";
2545
- /**
2546
- * Convert color to different format
2547
- * @param str - Color string to convert (e.g. "#FF5733", "rgb(255, 87, 51)")
2548
- * @param format - Target format
2549
- * @returns - Converted color string
2550
- * @example
2551
- * ```javascript
2552
- * const hexColor = color.convert("rgb(255, 87, 51)", "hex"); // "#FF5733"
2553
- * const rgbColor = color.convert("#FF5733", "rgb"); // "rgb(255, 87, 51)"
2554
- * const hslColor = color.convert("#FF5733", "hsl"); // "hsl(14, 100%, 60%)"
2555
- * const colorName = color.convert("#FF5733", "css-color-name"); // "orangered"
2556
- * ```
2557
- */
2558
- function convert(str: string, format: 'hex' | 'rgb' | 'rgba' | 'hsl' | 'hsla' | 'css-color-name'): Promise<string | null>;
2559
- }
2560
- namespace random {
2561
- /**
2562
- * Generate random color
2563
- * @param type - Color format
2564
- * @returns - Random color in specified format
2565
- * @example
2566
- * ```javascript
2567
- * const hexColor = random.color('hex');
2568
- * console.log(hexColor); // e.g. #3e92cc
2569
- *
2570
- * const rgbColor = random.color('rgb');
2571
- * console.log(rgbColor); // e.g. rgb(62, 146, 204)
2572
- * ```
2573
- */
2574
- function color(type?: 'hex' | 'hexa' | 'rgb' | 'rgba' | 'hsl' | 'hsla' | 'css-color-name'): string;
2575
- /**
2576
- * Generate random number
2577
- * @param min - Minimum value
2578
- * @param max - Maximum value
2579
- * @param float - Number of decimal places (0 for integer)
2580
- * @returns - Random number
2581
- * @example
2582
- * ```javascript
2583
- * const intNumber = random.number(1, 10);
2584
- * console.log(intNumber); // e.g. 7
2585
- *
2586
- * const floatNumber = random.number(1, 10, 2);
2587
- * console.log(floatNumber); // e.g. 3.14
2588
- * ```
2589
- */
2590
- function number(min: number, max: number, float?: number): number;
2591
- /**
2592
- * Generate random boolean
2593
- * @param threshold - Threshold between 0 and 1
2594
- * @returns - Random boolean
2595
- * @example
2596
- * ```javascript
2597
- * const boolValue = random.boolean(0.7);
2598
- * console.log(boolValue); // e.g. true (70% chance)
2599
- * ```
2600
- */
2601
- function boolean(threshold?: number): boolean;
2602
- /**
2603
- * Generate random string
2604
- * @param length - Length of the string
2605
- * @param chars - Characters to use
2606
- * @returns - Random string
2607
- * @example
2608
- * ```javascript
2609
- * const randString = random.string(10);
2610
- * console.log(randString); // e.g. "aZ3bT9xYqP"
2611
- * ```
2612
- */
2613
- function string(length: number, chars?: string): string;
2614
- /**
2615
- * Pick random element from array
2616
- * @param arr - Array to pick from
2617
- * @returns - Random element and its index
2618
- * @example
2619
- * ```javascript
2620
- * const [element, index] = random.array(['apple', 'banana', 'cherry']);
2621
- * console.log(element, index); // e.g. "banana", 1
2622
- * ```
2623
- */
2624
- function array<T>(arr: T[]): [value: T, index: number];
2625
- /**
2626
- * Generate random date
2627
- * @param start - Start date
2628
- * @param end - End date
2629
- * @returns - Random date between start and end
2630
- * @example
2631
- * ```javascript
2632
- * const randDate = random.date(new Date(2020, 0, 1), new Date());
2633
- * console.log(randDate); // e.g. 2022-05-15T10:30:00.000Z
2634
- * ```
2635
- */
2636
- function date(start?: Date, end?: Date): Date;
2637
- /**
2638
- * Generate ISO date string offset by days
2639
- * @param daysAgo - Number of days to go back
2640
- * @returns - ISO date string
2641
- * @example
2642
- * ```javascript
2643
- * const isoDate = random.daysOffset(7);
2644
- * console.log(isoDate); // e.g. "2024-06-10T14:23:45.678Z"
2645
- *
2646
- * const isoDate30 = random.daysOffset(30);
2647
- * console.log(isoDate30); // e.g. "2024-05-18T09:15:30.123Z"
2648
- * ```
2649
- */
2650
- function daysOffset(daysAgo: number): string;
2651
- /**
2652
- * Generate UUID v4
2653
- * @returns - UUID string
2654
- * @example
2655
- * ```javascript
2656
- * const uuid = random.uuid();
2657
- * console.log(uuid); // e.g. "3b12f1df-5232-4e3a-9a0c-3f9f1b1b1b1b"
2658
- * ```
2659
- */
2660
- function uuid(): string;
2661
- }
2662
- namespace fn {
2663
- /**
2664
- * Apply function with given thisArg and arguments
2665
- * @param fn - Function to apply
2666
- * @param thisArg - Value to use as this when calling fn
2667
- * @param args - Arguments to pass to fn
2668
- * @returns Result of calling fn with thisArg and args
2669
- */
2670
- function apply<TThis, TArgs extends unknown[], TReturn>(fn: (this: TThis, ...args: TArgs) => TReturn, thisArg: TThis, args: TArgs): TReturn;
2671
- /**
2672
- * Call function with given thisArg and arguments
2673
- * @param fn - Function to call
2674
- * @param thisArg - Value to use as this when calling fn
2675
- * @param args - Arguments to pass to fn
2676
- * @returns Result of calling fn with thisArg and args
2677
- */
2678
- function call<TThis, TArgs extends unknown[], TReturn>(fn: (this: TThis, ...args: TArgs) => TReturn, thisArg: TThis, ...args: TArgs): TReturn;
2679
- }
2680
- namespace utils {
2681
- /**
2682
- * Delays execution for a specified number of milliseconds.
2683
- * @param ms - The number of milliseconds to delay.
2684
- * @returns A Promise that resolves after the specified delay.
2685
- */
2686
- function delay<R extends any, M extends number>(ms: M, callback?: () => R): Promise<R | null>;
2687
- /**
2688
- * Returns typed entries of an object.
2689
- * @param obj - The object to get entries from.
2690
- * @returns An array of key-value pairs from the object.
2691
- */
2692
- function typedEntries<K extends string, V>(obj: Record<K, V> | Array<V>): [K, V][];
2693
- /**
2694
- * Returns typed values of an object.
2695
- * @param obj - The object to get values from.
2696
- * @returns An array of values from the object.
2697
- */
2698
- function typedValues<K extends string, V>(obj: Record<K, V> | Array<V>): V[];
2699
- /**
2700
- * Returns typed keys of an object.
2701
- * @param obj - The object to get keys from.
2702
- * @returns An array of keys from the object.
2703
- */
2704
- function typedKeys<K extends string, V>(obj: Record<K, V> | Array<V>): K[];
2705
- /**
2706
- * Selects an item based on weighted probabilities.
2707
- * @param items - An object where keys are items and values are their weights.
2708
- * @returns A randomly selected item based on the given probabilities.
2709
- */
2710
- function probability<K extends string, V extends number>(items: Record<K, V>): K | undefined;
2711
- }
2712
- }
2713
-
2714
- declare namespace Local {
2715
- type QueueItem = {
2716
- listener: 'onEventReceived';
2717
- data: StreamElements.Event.onEventReceived;
2718
- session?: boolean;
2719
- } | {
2720
- listener: 'onWidgetLoad';
2721
- data: StreamElements.Event.onWidgetLoad;
2722
- } | {
2723
- listener: 'onSessionUpdate';
2724
- data: StreamElements.Event.onSessionUpdate;
2725
- };
2726
- const queue: useQueue<QueueItem>;
2727
- const generate: {
2728
- session: {
2729
- types: Record<string, StreamElements.Session.Config.Any>;
2730
- available(): StreamElements.Session.Config.Available.Data;
2731
- get(startSession?: StreamElements.Session.Data): Promise<StreamElements.Session.Data>;
2732
- };
2733
- event: {
2734
- /**
2735
- * Simulates the onWidgetLoad event for a widget.
2736
- * @param fields - The field values to be included in the event.
2737
- * @param session - The session data to be included in the event.
2738
- * @param currency - The currency to be used (default is 'USD').
2739
- * @returns A Promise that resolves to the simulated onWidgetLoad event data.
2740
- */
2741
- onWidgetLoad(fields: Record<string, StreamElements.CustomField.Value>, session: StreamElements.Session.Data, currency?: "BRL" | "USD" | "EUR"): Promise<StreamElements.Event.onWidgetLoad>;
2742
- /**
2743
- * Simulates the onSessionUpdate event for a widget.
2744
- * @param session - The session data to be included in the event.
2745
- * @returns A Promise that resolves to the simulated onSessionUpdate event data.
2746
- */
2747
- onSessionUpdate(session?: StreamElements.Session.Data, update?: ClientEvents$1): Promise<StreamElements.Event.onSessionUpdate>;
2748
- /**
2749
- * Simulates the onEventReceived event for a widget.
2750
- * @param provider - The provider of the event (default is 'random').
2751
- * @param type - The type of event to simulate (default is 'random').
2752
- * @param options - Additional options to customize the event data.
2753
- * @returns A Promise that resolves to the simulated onEventReceived event data, or null if the event type is not supported.
2754
- * @example
2755
- * ```javascript
2756
- * // Simulate a random event
2757
- * const randomEvent = await Local .generate.event.onEventReceived();
2758
- *
2759
- * // Simulate a Twitch message event with custom options
2760
- * const twitchMessageEvent = await Local .generate.event.onEventReceived('twitch', 'message', { name: 'Streamer', message: 'Hello World!' });
2761
- * ```
2762
- */
2763
- onEventReceived(provider?: Provider$1 | "random", type?: StreamElements.Event.onEventReceived["listener"] | "random" | "tip" | "cheer" | "follower" | "raid" | "subscriber", options?: Record<string, string | number | boolean>): Promise<StreamElements.Event.onEventReceived | null>;
2237
+ onEventReceived(provider?: Provider$1 | "random", type?: StreamElements.Event.onEventReceived["listener"] | "random" | "tip" | "cheer" | "follower" | "raid" | "subscriber", options?: Record<string, string | number | boolean>): Promise<StreamElements.Event.onEventReceived | null>;
2764
2238
  };
2765
2239
  };
2766
2240
  const emulate: {
@@ -2768,7 +2242,7 @@ declare namespace Local {
2768
2242
  message(data?: Partial<{
2769
2243
  name: string;
2770
2244
  message: string;
2771
- badges: Helper.message.BadgeOptions;
2245
+ badges: BadgeOptions;
2772
2246
  color: string;
2773
2247
  userId: string;
2774
2248
  msgId: string;
@@ -2828,7 +2302,7 @@ declare namespace Local {
2828
2302
  message(data?: Partial<{
2829
2303
  name: string;
2830
2304
  message: string;
2831
- badges: Helper.message.BadgeOptions;
2305
+ badges: BadgeOptions;
2832
2306
  color: string;
2833
2307
  userId: string;
2834
2308
  msgId: string;
@@ -2864,6 +2338,568 @@ declare namespace Local {
2864
2338
  function start(fieldsFile?: string[], dataFiles?: string[], session?: StreamElements.Session.Data): Promise<void>;
2865
2339
  }
2866
2340
 
2341
+ /**
2342
+ * NumberHelper class provides utility methods for working with numbers, including translation to words, balancing within a range, rounding, and generating random numbers.
2343
+ */
2344
+ declare class NumberHelper {
2345
+ /**
2346
+ * Translate number to words
2347
+ * @param num - Number to translate
2348
+ * @param type - Translation type
2349
+ * @returns - Number in words
2350
+ * @example
2351
+ * ```javascript
2352
+ * const cardinal = translate(42, 'cardinal');
2353
+ * console.log(cardinal); // "forty-two"
2354
+ * const ordinal = translate(42, 'ordinal');
2355
+ * console.log(ordinal); // "forty-second"
2356
+ * const suffix = translate(42, 'suffix');
2357
+ * console.log(suffix); // "42nd"
2358
+ * ```
2359
+ */
2360
+ translate(num: number, type?: 'cardinal' | 'ordinal' | 'suffix'): string;
2361
+ /**
2362
+ * Balances a number within a specified range
2363
+ * @param amount - Number to balance
2364
+ * @param min - Minimum value
2365
+ * @param max - Maximum value
2366
+ * @param decimals - Number of decimal places to round to (default is 0)
2367
+ * @returns - Balanced number
2368
+ * @example
2369
+ * ```javascript
2370
+ * const balancedValue = balance(150, 0, 100);
2371
+ * console.log(balancedValue); // 100
2372
+ * ```
2373
+ */
2374
+ balance(amount: number, min?: number, max?: number, decimals?: number): number;
2375
+ /**
2376
+ * Rounds a number to a specified number of decimal places
2377
+ * @param value - Number to round
2378
+ * @param decimals - Number of decimal places (default is 2)
2379
+ * @returns Rounded number
2380
+ * @example
2381
+ * ```javascript
2382
+ * const roundedValue = round(3.14159, 3);
2383
+ * console.log(roundedValue); // 3.142
2384
+ * const roundedValueDefault = round(3.14159);
2385
+ * console.log(roundedValueDefault); // 3.14
2386
+ * const roundedValueZero = round(3.14159, 0);
2387
+ * console.log(roundedValueZero); // 3
2388
+ * ```
2389
+ */
2390
+ round(value: number, decimals?: number): number;
2391
+ /**
2392
+ * Generate random number
2393
+ * @param min - Minimum value
2394
+ * @param max - Maximum value
2395
+ * @param float - Number of decimal places (0 for integer)
2396
+ * @returns - Random number
2397
+ * @example
2398
+ * ```javascript
2399
+ * const intNumber = random(1, 10);
2400
+ * console.log(intNumber); // e.g. 7
2401
+ *
2402
+ * const floatNumber = random(1, 10, 2);
2403
+ * console.log(floatNumber); // e.g. 3.14
2404
+ * ```
2405
+ */
2406
+ random(min: number, max: number, float?: number): number;
2407
+ }
2408
+
2409
+ interface ScaleOptions<T extends HTMLElement> {
2410
+ /**
2411
+ * The parent element to use for scaling calculations. If not provided, the element's parent will be used.
2412
+ */
2413
+ parent?: HTMLElement;
2414
+ /**
2415
+ * The preferred dimension to base the scaling on. Can be 'width', 'height', or 'auto' (default).
2416
+ */
2417
+ prefer?: 'width' | 'height' | 'auto';
2418
+ /**
2419
+ * The minimum percentage of the parent size to scale to. Default is 0.
2420
+ */
2421
+ min?: number;
2422
+ /**
2423
+ * The maximum percentage of the parent size to scale to. Default is 1 (100%).
2424
+ */
2425
+ max?: number;
2426
+ /**
2427
+ * A callback function that is called after scaling is applied.
2428
+ * @param this - The HTML element being scaled.
2429
+ * @param number - The scale factor applied to the element.
2430
+ * @param element - The HTML element being scaled.
2431
+ * @returns void
2432
+ */
2433
+ apply?: (this: T, number: number, element: T) => void;
2434
+ }
2435
+ type FitTextOptions = {
2436
+ minFontSize?: number;
2437
+ maxFontSize?: number;
2438
+ parent?: HTMLElement;
2439
+ };
2440
+ declare class ElementHelper {
2441
+ /**
2442
+ * Merges outer span styles with inner span styles in the provided HTML string.
2443
+ * @param outerStyle - The style string to be applied to the outer span.
2444
+ * @param innerHTML - The inner HTML string which may contain a span with its own styles.
2445
+ * @returns A new HTML string with merged styles applied to a single span.
2446
+ * @example
2447
+ * ```javascript
2448
+ * const result = mergeSpanStyles("color: red; font-weight: bold;", '<span style="font-size: 14px;">Hello World</span>');
2449
+ * console.log(result); // Output: '<span style="font-size: 14px; color: red; font-weight: bold;">Hello World</span>'
2450
+ * ```
2451
+ */
2452
+ mergeSpanStyles(outerStyle: string, innerHTML: string, className?: string): string;
2453
+ /**
2454
+ * Scales an HTML element to fit within its parent element based on specified minimum and maximum scale factors.
2455
+ * @param element - The HTML element to be scaled.
2456
+ * @param min - Minimum scale factor (default is 0).
2457
+ * @param max - Maximum scale factor (default is 1).
2458
+ * @param options - Optional settings for scaling.
2459
+ * @returns - An object containing the new width, height, and scale factor, or void if not applied.
2460
+ * @example
2461
+ * ```javascript
2462
+ * const element = document.getElementById('myElement');
2463
+ * scale(element, 0.5, 1, { return: false });
2464
+ * ```
2465
+ */
2466
+ scale(element: HTMLElement, min?: number, max?: number, options?: {
2467
+ return: boolean;
2468
+ parent: HTMLElement;
2469
+ base: 'width' | 'height';
2470
+ }): {
2471
+ width: number;
2472
+ height: number;
2473
+ scale: number;
2474
+ } | void;
2475
+ /**
2476
+ * Scales an HTML element to fit within its parent element based on specified options.
2477
+ * @param element - The HTML element to be scaled.
2478
+ * @param options - Optional settings for scaling.
2479
+ * @returns The scale factor applied to the element.
2480
+ * @example
2481
+ * ```javascript
2482
+ * const element = document.getElementById('myElement');
2483
+ * const scaleFactor scalev2(element, {
2484
+ * min: 0.5,
2485
+ * max: 1,
2486
+ * prefer: 'width',
2487
+ * apply: (scale, el) => el.style.transform = `scale(${scale})`
2488
+ * });
2489
+ * console.log(`Element scaled by a factor of ${scaleFactor}`);
2490
+ * ```
2491
+ */
2492
+ scalev2<T extends HTMLElement>(element: T, options?: ScaleOptions<T>): number;
2493
+ /**
2494
+ * Fits the text within the parent element by adjusting the font size.
2495
+ * @param element - The HTML element containing the text to be fitted.
2496
+ * @param compressor - A multiplier to adjust the fitting sensitivity (default is 1).
2497
+ * @param options - Optional settings for fitting text.
2498
+ * @returns The HTML element with adjusted font size.
2499
+ * @example
2500
+ * ```javascript
2501
+ * const element = document.getElementById('myTextElement');
2502
+ * fitText(element, 1, { minFontSize: 12, maxFontSize: 36 });
2503
+ * console.log(`Adjusted font size: ${element.style.fontSize}`);
2504
+ * ```
2505
+ */
2506
+ fitText(element: HTMLElement, compressor?: number, options?: FitTextOptions): HTMLElement;
2507
+ /**
2508
+ * Wraps formatted HTML text with containers and splits characters into indexed spans.
2509
+ * Adds 'container' class and data-index to all parent elements, and wraps each character in a span with class 'char' and data-index.
2510
+ * @param htmlString - The input HTML string containing formatted text elements (span, strong, em, etc).
2511
+ * @param startIndex - The starting index for the data-index attribute (default is 0).
2512
+ * @returns - A new HTML string with containers and character-level indexing.
2513
+ * @example
2514
+ * ```javascript
2515
+ * const result = splitTextToChars('<span>TesTe</span> <strong>bold</strong>', 0);
2516
+ * console.log(result);
2517
+ * // Output: '<span class="container" data-index="0"><span class="char" data-index="0">T</span><span class="char" data-index="1">e</span>...'
2518
+ * ```
2519
+ */
2520
+ splitTextToChars(htmlString: string, startIndex?: number, preserveInterElementWhitespace?: boolean): string;
2521
+ }
2522
+
2523
+ declare class ObjectHelper {
2524
+ /**
2525
+ * Flattens a nested object into a single-level object with dot-separated keys.
2526
+ * @param obj - The nested object to be flattened.
2527
+ * @param prefix - The prefix to be added to each key (used for recursion).
2528
+ * @returns A flattened object with dot-separated keys.
2529
+ * @example
2530
+ * ```javascript
2531
+ * const nestedObj = { a: { b: 1, c: { d: 2 } }, e: [3, 4] };
2532
+ * const flatObj = flatten(nestedObj);
2533
+ * console.log(flatObj);
2534
+ * // Output: { 'a.b': '1', 'a.c.d': '2', 'e:0': '3', 'e:1': '4' }
2535
+ * ```
2536
+ */
2537
+ flatten(obj: Record<string, any>, stringify?: boolean, prefix?: string): Record<string, typeof stringify extends true ? string : string | number | boolean>;
2538
+ /**
2539
+ * Returns the entries of an object as an array of key-value pairs, with proper typing.
2540
+ * @param obj - The object to retrieve entries from.
2541
+ * @returns An array of key-value pairs from the object, typed as an array of tuples with key and value types.
2542
+ */
2543
+ entries<K extends string, V>(obj: Record<K, V>): [K, V][];
2544
+ /**
2545
+ * Returns the values of an object as an array, with proper typing.
2546
+ * @param obj - The object to retrieve values from.
2547
+ * @returns An array of values from the object, typed as an array of the value type.
2548
+ */
2549
+ values<K extends string, V>(obj: Record<K, V>): V[];
2550
+ /**
2551
+ * Returns the keys of an object as an array of strings, with proper typing.
2552
+ * @param obj - The object to retrieve keys from.
2553
+ * @returns An array of keys from the object, typed as an array of strings.
2554
+ */
2555
+ keys<K extends string, V>(obj: Record<K, V>): K[];
2556
+ }
2557
+
2558
+ declare class RandomHelper {
2559
+ /**
2560
+ * Generate random color
2561
+ * @param type - Color format
2562
+ * @returns - Random color in specified format
2563
+ * @example
2564
+ * ```javascript
2565
+ * const hexColor = random.color('hex');
2566
+ * console.log(hexColor); // e.g. #3e92cc
2567
+ *
2568
+ * const rgbColor = random.color('rgb');
2569
+ * console.log(rgbColor); // e.g. rgb(62, 146, 204)
2570
+ * ```
2571
+ */
2572
+ color(type?: 'hex' | 'hexa' | 'rgb' | 'rgba' | 'hsl' | 'hsla' | 'css-color-name'): string;
2573
+ /**
2574
+ * Generate random number
2575
+ * @param min - Minimum value
2576
+ * @param max - Maximum value
2577
+ * @param float - Number of decimal places (0 for integer)
2578
+ * @returns - Random number
2579
+ * @example
2580
+ * ```javascript
2581
+ * const intNumber = random.number(1, 10);
2582
+ * console.log(intNumber); // e.g. 7
2583
+ *
2584
+ * const floatNumber = random.number(1, 10, 2);
2585
+ * console.log(floatNumber); // e.g. 3.14
2586
+ * ```
2587
+ */
2588
+ number(min: number, max: number, float?: number): number;
2589
+ /**
2590
+ * Generate random boolean
2591
+ * @param threshold - Threshold between 0 and 1
2592
+ * @returns - Random boolean
2593
+ * @example
2594
+ * ```javascript
2595
+ * const boolValue = random.boolean(0.7);
2596
+ * console.log(boolValue); // e.g. true (70% chance)
2597
+ * ```
2598
+ */
2599
+ boolean(threshold?: number): boolean;
2600
+ /**
2601
+ * Generate random string
2602
+ * @param length - Length of the string
2603
+ * @param chars - Characters to use
2604
+ * @returns - Random string
2605
+ * @example
2606
+ * ```javascript
2607
+ * const randString = random.string(10);
2608
+ * console.log(randString); // e.g. "aZ3bT9xYqP"
2609
+ * ```
2610
+ */
2611
+ string(length: number, chars?: string): string;
2612
+ /**
2613
+ * Pick random element from array
2614
+ * @param arr - Array to pick from
2615
+ * @returns - Random element and its index
2616
+ * @example
2617
+ * ```javascript
2618
+ * const [element, index] = random.array(['apple', 'banana', 'cherry']);
2619
+ * console.log(element, index); // e.g. "banana", 1
2620
+ * ```
2621
+ */
2622
+ array<T>(arr: T[]): [value: T, index: number];
2623
+ /**
2624
+ * Generate random date
2625
+ * @param start - Start date
2626
+ * @param end - End date
2627
+ * @returns - Random date between start and end
2628
+ * @example
2629
+ * ```javascript
2630
+ * const randDate = random.date(new Date(2020, 0, 1), new Date());
2631
+ * console.log(randDate); // e.g. 2022-05-15T10:30:00.000Z
2632
+ * ```
2633
+ */
2634
+ date(start?: Date, end?: Date): Date;
2635
+ /**
2636
+ * Generate ISO date string offset by days
2637
+ * @param daysAgo - Number of days to go back
2638
+ * @returns - ISO date string
2639
+ * @example
2640
+ * ```javascript
2641
+ * const isoDate = random.daysOffset(7);
2642
+ * console.log(isoDate); // e.g. "2024-06-10T14:23:45.678Z"
2643
+ *
2644
+ * const isoDate30 = random.daysOffset(30);
2645
+ * console.log(isoDate30); // e.g. "2024-05-18T09:15:30.123Z"
2646
+ * ```
2647
+ */
2648
+ daysOffset(daysAgo: number): string;
2649
+ /**
2650
+ * Generate UUID v4
2651
+ * @returns - UUID string
2652
+ * @example
2653
+ * ```javascript
2654
+ * const uuid = random.uuid();
2655
+ * console.log(uuid); // e.g. "3b12f1df-5232-4e3a-9a0c-3f9f1b1b1b1b"
2656
+ * ```
2657
+ */
2658
+ uuid(): string;
2659
+ }
2660
+
2661
+ declare class EventHelper {
2662
+ /**
2663
+ * Parses the provider information from the event detail object.
2664
+ * @param detail - The event detail object received from the StreamElements event.
2665
+ * @returns An object containing the provider and the original event data.
2666
+ */
2667
+ parseProvider(detail: StreamElements.Event.onEventReceived, _provider?: Provider$1): ClientEvents$1;
2668
+ }
2669
+
2670
+ type Modifier = (value: string, param: string | null | undefined, values: {
2671
+ amount?: number;
2672
+ count?: number;
2673
+ }) => string;
2674
+ declare class StringHelper {
2675
+ /**
2676
+ * Replaces occurrences in a string based on a pattern with the result of an asynchronous callback function.
2677
+ * @param string - The input string to perform replacements on.
2678
+ * @param pattern - The pattern to match in the string (can be a string or a regular expression).
2679
+ * @param callback - An asynchronous callback function that takes the matched substring and any captured groups as arguments and returns the replacement string.
2680
+ * @returns A promise that resolves to the modified string with replacements applied.
2681
+ * @example
2682
+ * ```javascript
2683
+ * const result = await string.replace("Hello World", /World/, async (match) => {
2684
+ * return await fetchSomeData(match); // Assume this function fetches data asynchronously
2685
+ * });
2686
+ * console.log(result); // Output will depend on the fetched data
2687
+ * ```
2688
+ */
2689
+ replace(string: string, pattern: string, callback: (match: string, ...groups: string[]) => Promise<string> | string): Promise<string>;
2690
+ /**
2691
+ * Capitalizes the first letter of a given string.
2692
+ * @param string - The input string to be capitalized.
2693
+ * @returns The capitalized string.
2694
+ * @example
2695
+ * ```javascript
2696
+ * const result = string.capitalize("hello world");
2697
+ * console.log(result); // Output: "Hello world"
2698
+ * ```
2699
+ */
2700
+ capitalize(string: string): Capitalize<string>;
2701
+ PRESETS: Record<string, string>;
2702
+ /**
2703
+ * Composes a template string by replacing placeholders with corresponding values and applying optional modifiers.
2704
+ * @param template - The template string containing placeholders in the format {key} and optional modifiers in the format [MODIFIER:param=value].
2705
+ * @param values - An object containing key-value pairs to replace the placeholders in the template.
2706
+ * @param options - Optional settings for the composition process.
2707
+ * @returns The composed string with placeholders replaced and modifiers applied.
2708
+ * @example
2709
+ * ```javascript
2710
+ * const { string } = Tixyel.Helper;
2711
+ *
2712
+ * // Basic usage with placeholders and simple modifiers
2713
+ * const template1 = "Hello, {username}! You have {amount} [UPC=messages] and your name is [CAP=name].";
2714
+ * const values1 = { username: "john_doe", amount: 5, name: "john" };
2715
+ * const result1 = string.compose(template1, values1);
2716
+ * // "Hello, john_doe! You have 5 MESSAGES and your name is John."
2717
+ *
2718
+ * // Multiple modifiers in a single block (HTML enabled)
2719
+ * const template2 = "[COLOR:#ff0056,BOLD={username}]";
2720
+ * const values2 = { username: "john_doe" };
2721
+ * const result2 = string.compose(template2, values2, { html: true });
2722
+ * // '<span class="color bold" style="color: #ff0056; font-weight: bold;">john_doe</span>'
2723
+ *
2724
+ * // Conditional rendering with IF (supports ===, >=, &&, ||, !, etc.)
2725
+ * const template3 = "[IF=vip && status === 'live'?VIP Online|Offline]";
2726
+ * const values3 = { status: 'live', vip: true };
2727
+ * const result3 = string.compose(template3, values3);
2728
+ * // "VIP Online"
2729
+ *
2730
+ * // Pluralization using amount / count or an explicit key
2731
+ * const template4 = "You have {amount} [PLURAL=message|messages].";
2732
+ * const values4 = { amount: 1 };
2733
+ * const values5 = { amount: 3 };
2734
+ * const result4a = string.compose(template4, values4); // "You have 1 message."
2735
+ * const result4b = string.compose(template4, values5); // "You have 3 messages."
2736
+ *
2737
+ * // Number formatting
2738
+ * const template5 = "Total: [NUMBER:2=amount] {currency}";
2739
+ * const values6 = { amount: 1234.5, currency: '$' };
2740
+ * const result5 = string.compose(template5, values6);
2741
+ * // e.g. "Total: 1,234.50 $" (locale dependent)
2742
+ *
2743
+ * // Date and time formatting
2744
+ * const template6 = "Created at: [DATE:iso=createdAt] ([DATE:relative=createdAt])";
2745
+ * const values7 = { createdAt: new Date('2020-01-02T03:04:05.000Z') };
2746
+ * const result6 = string.compose(template6, values7);
2747
+ * // e.g. "Created at: 2020-01-02T03:04:05.000Z (Xs ago)"
2748
+ *
2749
+ * // MAP / SWITCH style mapping
2750
+ * const template7 = "Status: [MAP:status=live:Online|offline:Offline|default:Unknown]";
2751
+ * const values8 = { status: 'offline' };
2752
+ * const result7 = string.compose(template7, values8);
2753
+ * // "Status: Offline"
2754
+ *
2755
+ * // Escaping HTML
2756
+ * const template8 = "[ESCAPE={message}]";
2757
+ * const values9 = { message: '<b>Danger & "HTML"</b>' };
2758
+ * const result8 = string.compose(template8, values9);
2759
+ * // "&lt;b&gt;Danger &amp; &quot;HTML&quot;&lt;/b&gt;"
2760
+ *
2761
+ * // Using global presets
2762
+ * Helper.string.PRESETS['alert'] = 'BOLD,COLOR:#ff0056';
2763
+ * const template10 = "[PRESET:alert={username}]";
2764
+ * const values11 = { username: 'john_doe' };
2765
+ * const result10 = string.compose(template10, values11, { html: true });
2766
+ * // '<span class="color bold" style="color: #ff0056; font-weight: bold;">john_doe</span>'
2767
+ * ```
2768
+ */
2769
+ compose(template: string, values?: Record<string, any>, options?: {
2770
+ method?: 'loop' | 'index';
2771
+ html?: boolean;
2772
+ debug?: boolean;
2773
+ modifiers?: Record<string, Modifier>;
2774
+ aliases?: Record<string, string[]>;
2775
+ }): string;
2776
+ }
2777
+
2778
+ declare class ColorHelper {
2779
+ /**
2780
+ * Generate opacity hex value
2781
+ * @param opacity - Opacity value from 0 to 100
2782
+ * @param color - Hex color code
2783
+ * @returns - Hex color code with opacity
2784
+ */
2785
+ opacity(opacity?: number, color?: string): string;
2786
+ /**
2787
+ * Extract color and opacity from hex code
2788
+ * @param hex - Hex color code
2789
+ * @returns - Object with color and opacity
2790
+ */
2791
+ extract(hex: string): {
2792
+ color: string;
2793
+ opacity: number;
2794
+ };
2795
+ /**
2796
+ * Validate color string format
2797
+ * @param str - Color string to validate
2798
+ * @returns Detected color format or false if invalid
2799
+ * @example
2800
+ * ```javascript
2801
+ * const format1 = color.validate("#FF5733"); // "hex"
2802
+ * const format2 = color.validate("rgb(255, 87, 51)"); // "rgb"
2803
+ * const format3 = color.validate("hsl(14, 100%, 60%)"); // "hsl"
2804
+ * const format4 = color.validate("orangered"); // "css-color-name"
2805
+ * const format5 = color.validate("invalid-color"); // false
2806
+ * ```
2807
+ */
2808
+ validate(str: string): false | "hex" | "rgb" | "rgba" | "hsl" | "hsla" | "css-color-name";
2809
+ /**
2810
+ * Convert color to different format
2811
+ * @param str - Color string to convert (e.g. "#FF5733", "rgb(255, 87, 51)")
2812
+ * @param format - Target format
2813
+ * @returns - Converted color string
2814
+ * @example
2815
+ * ```javascript
2816
+ * const hexColor = color.convert("rgb(255, 87, 51)", "hex"); // "#FF5733"
2817
+ * const rgbColor = color.convert("#FF5733", "rgb"); // "rgb(255, 87, 51)"
2818
+ * const hslColor = color.convert("#FF5733", "hsl"); // "hsl(14, 100%, 60%)"
2819
+ * const colorName = color.convert("#FF5733", "css-color-name"); // "orangered"
2820
+ * ```
2821
+ */
2822
+ convert(str: string, format: 'hex' | 'rgb' | 'rgba' | 'hsl' | 'hsla' | 'css-color-name'): Promise<string | null>;
2823
+ }
2824
+
2825
+ declare class SoundHelper {
2826
+ playing: boolean;
2827
+ audio: AudioContext;
2828
+ /**
2829
+ * Play sound from URL with optional volume and replace parameters
2830
+ * @param url - Sound URL to play
2831
+ * @param volume - Volume level from 0 to 100 (default: 100)
2832
+ * @param replace - If true, replaces currently playing sound (default: false)
2833
+ */
2834
+ play(url: string, volume?: number, replace?: boolean): void;
2835
+ }
2836
+
2837
+ declare class FunctionHelper {
2838
+ /**
2839
+ * Apply function with given thisArg and arguments
2840
+ * @param fn - Function to apply
2841
+ * @param thisArg - Value to use as this when calling fn
2842
+ * @param args - Arguments to pass to fn
2843
+ * @returns Result of calling fn with thisArg and args
2844
+ */
2845
+ apply<TThis, TArgs extends unknown[], TReturn>(fn: (this: TThis, ...args: TArgs) => TReturn, thisArg: TThis, args: TArgs): TReturn;
2846
+ /**
2847
+ * Call function with given thisArg and arguments
2848
+ * @param fn - Function to call
2849
+ * @param thisArg - Value to use as this when calling fn
2850
+ * @param args - Arguments to pass to fn
2851
+ * @returns Result of calling fn with thisArg and args
2852
+ */
2853
+ call<TThis, TArgs extends unknown[], TReturn>(fn: (this: TThis, ...args: TArgs) => TReturn, thisArg: TThis, ...args: TArgs): TReturn;
2854
+ }
2855
+
2856
+ declare class UtilsHelper {
2857
+ /**
2858
+ * Delays execution for a specified number of milliseconds.
2859
+ * @param ms - The number of milliseconds to delay.
2860
+ * @returns A Promise that resolves after the specified delay.
2861
+ */
2862
+ delay<R extends any, M extends number>(ms: M, callback?: () => R): Promise<R | null>;
2863
+ /**
2864
+ * Returns typed entries of an object.
2865
+ * @param obj - The object to get entries from.
2866
+ * @returns An array of key-value pairs from the object.
2867
+ */
2868
+ typedEntries<K extends string, V>(obj: Record<K, V> | Array<V>): [K, V][];
2869
+ /**
2870
+ * Returns typed values of an object.
2871
+ * @param obj - The object to get values from.
2872
+ * @returns An array of values from the object.
2873
+ */
2874
+ typedValues<K extends string, V>(obj: Record<K, V> | Array<V>): V[];
2875
+ /**
2876
+ * Returns typed keys of an object.
2877
+ * @param obj - The object to get keys from.
2878
+ * @returns An array of keys from the object.
2879
+ */
2880
+ typedKeys<K extends string, V>(obj: Record<K, V> | Array<V>): K[];
2881
+ /**
2882
+ * Selects an item based on weighted probabilities.
2883
+ * @param items - An object where keys are items and values are their weights.
2884
+ * @returns A randomly selected item based on the given probabilities.
2885
+ */
2886
+ probability<K extends string, V extends number>(items: Record<K, V>): K | undefined;
2887
+ }
2888
+
2889
+ declare namespace Helper {
2890
+ const number: NumberHelper;
2891
+ const element: ElementHelper;
2892
+ const object: ObjectHelper;
2893
+ const message: MessageHelper;
2894
+ const event: EventHelper;
2895
+ const string: StringHelper;
2896
+ const sound: SoundHelper;
2897
+ const color: ColorHelper;
2898
+ const random: RandomHelper;
2899
+ const fn: FunctionHelper;
2900
+ const utils: UtilsHelper;
2901
+ }
2902
+
2867
2903
  declare namespace Data {
2868
2904
  const avatars: string[];
2869
2905
  const badges: Record<Twitch.roles, Twitch.badge>;
@@ -2996,4 +3032,4 @@ declare global {
2996
3032
  }
2997
3033
 
2998
3034
  export { Alejo, Button, Command, EventProvider, StreamElements, StreamElementsEvents, Twitch, TwitchEvents, YoutubeEvents, main as default, useComfyJs, useLogger, useQueue, useStorage };
2999
- export type { BttvEmote, ClientEvents$1 as ClientEvents, Emote, Provider$1 as Provider, SeventvEmote, TwitchEmote };
3035
+ export type { BttvEmote, ClientEvents$1 as ClientEvents, Emoji, Emote, Provider$1 as Provider, SeventvEmote, TwitchEmote };