@tixyel/streamelements 6.5.0 → 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,69 +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 Emoji = {
1626
- type: 'emoji';
1627
- name: string;
1628
- id: string;
1629
- gif: boolean;
1630
- urls: {
1631
- '1': string;
1632
- };
1633
- };
1634
- type Emote = TwitchEmote | BttvEmote | SeventvEmote | Emoji;
1635
-
1636
1623
  /**
1637
1624
  * EventProvider class for managing event listeners and emitters.
1638
1625
  * This class allows you to register event listeners, emit events, and manage event subscriptions.
@@ -2121,662 +2108,133 @@ declare class useComfyJs extends EventProvider<ComfyEvents> {
2121
2108
  private connect;
2122
2109
  }
2123
2110
 
2124
- declare namespace Helper {
2125
- namespace number {
2126
- /**
2127
- * Translate number to words
2128
- * @param num - Number to translate
2129
- * @param type - Translation type
2130
- * @returns - Number in words
2131
- * @example
2132
- * ```javascript
2133
- * const cardinal = Simulation.number.translate(42, 'cardinal');
2134
- * console.log(cardinal); // "forty-two"
2135
- * ```
2136
- */
2137
- function translate(num: number, type?: 'cardinal' | 'ordinal' | 'suffix'): string;
2138
- /**
2139
- * Balances a number within a specified range
2140
- * @param amount - Number to balance
2141
- * @param min - Minimum value
2142
- * @param max - Maximum value
2143
- * @param decimals - Number of decimal places to round to (default is 0)
2144
- * @returns - Balanced number
2145
- * @example
2146
- * ```javascript
2147
- * const balancedValue = Simulation.number.balance(150, 0, 100);
2148
- * console.log(balancedValue); // 100
2149
- * ```
2150
- */
2151
- function balance(amount: number, min?: number, max?: number, decimals?: number): number;
2152
- /**
2153
- * Rounds a number to a specified number of decimal places
2154
- * @param value - Number to round
2155
- * @param decimals - Number of decimal places (default is 2)
2156
- * @returns Rounded number
2157
- * @example
2158
- * ```javascript
2159
- * const roundedValue = Simulation.number.round(3.14159, 3);
2160
- * console.log(roundedValue); // 3.142
2161
- * ```
2162
- */
2163
- function round(value: number, decimals?: number): number;
2164
- /**
2165
- * Generate random number
2166
- * @param min - Minimum value
2167
- * @param max - Maximum value
2168
- * @param float - Number of decimal places (0 for integer)
2169
- * @returns - Random number
2170
- * @example
2171
- * ```javascript
2172
- * const intNumber = number.random(1, 10);
2173
- * console.log(intNumber); // e.g. 7
2174
- *
2175
- * const floatNumber = number.random(1, 10, 2);
2176
- * console.log(floatNumber); // e.g. 3.14
2177
- * ```
2178
- */
2179
- function number(min: number, max: number, float?: number): number;
2180
- }
2181
- namespace element {
2182
- interface ScaleOptions<T extends HTMLElement> {
2183
- /**
2184
- * The parent element to use for scaling calculations. If not provided, the element's parent will be used.
2185
- */
2186
- parent?: HTMLElement;
2187
- /**
2188
- * The preferred dimension to base the scaling on. Can be 'width', 'height', or 'auto' (default).
2189
- */
2190
- 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: {
2191
2208
  /**
2192
- * 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.
2193
2214
  */
2194
- min?: number;
2215
+ onWidgetLoad(fields: Record<string, StreamElements.CustomField.Value>, session: StreamElements.Session.Data, currency?: "BRL" | "USD" | "EUR"): Promise<StreamElements.Event.onWidgetLoad>;
2195
2216
  /**
2196
- * 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.
2197
2220
  */
2198
- max?: number;
2221
+ onSessionUpdate(session?: StreamElements.Session.Data, update?: ClientEvents$1): Promise<StreamElements.Event.onSessionUpdate>;
2199
2222
  /**
2200
- * A callback function that is called after scaling is applied.
2201
- * @param this - The HTML element being scaled.
2202
- * @param number - The scale factor applied to the element.
2203
- * @param element - The HTML element being scaled.
2204
- * @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
+ * ```
2205
2236
  */
2206
- apply?: (this: T, number: number, element: T) => void;
2207
- }
2208
- type FitTextOptions = {
2209
- minFontSize?: number;
2210
- maxFontSize?: number;
2211
- parent?: HTMLElement;
2212
- };
2213
- /**
2214
- * Merges outer span styles with inner span styles in the provided HTML string.
2215
- * @param outerStyle - The style string to be applied to the outer span.
2216
- * @param innerHTML - The inner HTML string which may contain a span with its own styles.
2217
- * @returns A new HTML string with merged styles applied to a single span.
2218
- * @example
2219
- * ```javascript
2220
- * const result = mergeSpanStyles("color: red; font-weight: bold;", '<span style="font-size: 14px;">Hello World</span>');
2221
- * console.log(result); // Output: '<span style="font-size: 14px; color: red; font-weight: bold;">Hello World</span>'
2222
- * ```
2223
- */
2224
- function mergeSpanStyles(outerStyle: string, innerHTML: string, className?: string): string;
2225
- /**
2226
- * Scales an HTML element to fit within its parent element based on specified minimum and maximum scale factors.
2227
- * @param element - The HTML element to be scaled.
2228
- * @param min - Minimum scale factor (default is 0).
2229
- * @param max - Maximum scale factor (default is 1).
2230
- * @param options - Optional settings for scaling.
2231
- * @returns - An object containing the new width, height, and scale factor, or void if not applied.
2232
- * @example
2233
- * ```javascript
2234
- * const element = document.getElementById('myElement');
2235
- * scale(element, 0.5, 1, { return: false });
2236
- * ```
2237
- */
2238
- function scale(element: HTMLElement, min?: number, max?: number, options?: {
2239
- return: boolean;
2240
- parent: HTMLElement;
2241
- base: 'width' | 'height';
2242
- }): {
2243
- width: number;
2244
- height: number;
2245
- scale: number;
2246
- } | void;
2247
- /**
2248
- * Scales an HTML element to fit within its parent element based on specified options.
2249
- * @param element - The HTML element to be scaled.
2250
- * @param options - Optional settings for scaling.
2251
- * @returns The scale factor applied to the element.
2252
- * @example
2253
- * ```javascript
2254
- * const element = document.getElementById('myElement');
2255
- * const scaleFactor scalev2(element, {
2256
- * min: 0.5,
2257
- * max: 1,
2258
- * prefer: 'width',
2259
- * apply: (scale, el) => el.style.transform = `scale(${scale})`
2260
- * });
2261
- * console.log(`Element scaled by a factor of ${scaleFactor}`);
2262
- * ```
2263
- */
2264
- function scalev2<T extends HTMLElement>(element: T, options?: ScaleOptions<T>): number;
2265
- /**
2266
- * Fits the text within the parent element by adjusting the font size.
2267
- * @param element - The HTML element containing the text to be fitted.
2268
- * @param compressor - A multiplier to adjust the fitting sensitivity (default is 1).
2269
- * @param options - Optional settings for fitting text.
2270
- * @returns The HTML element with adjusted font size.
2271
- * @example
2272
- * ```javascript
2273
- * const element = document.getElementById('myTextElement');
2274
- * fitText(element, 1, { minFontSize: 12, maxFontSize: 36 });
2275
- * console.log(`Adjusted font size: ${element.style.fontSize}`);
2276
- * ```
2277
- */
2278
- function fitText(element: HTMLElement, compressor?: number, options?: FitTextOptions): HTMLElement;
2279
- /**
2280
- * Wraps formatted HTML text with containers and splits characters into indexed spans.
2281
- * Adds 'container' class and data-index to all parent elements, and wraps each character in a span with class 'char' and data-index.
2282
- * @param htmlString - The input HTML string containing formatted text elements (span, strong, em, etc).
2283
- * @param startIndex - The starting index for the data-index attribute (default is 0).
2284
- * @returns - A new HTML string with containers and character-level indexing.
2285
- * @example
2286
- * ```javascript
2287
- * const result = splitTextToChars('<span>TesTe</span> <strong>bold</strong>', 0);
2288
- * console.log(result);
2289
- * // Output: '<span class="container" data-index="0"><span class="char" data-index="0">T</span><span class="char" data-index="1">e</span>...'
2290
- * ```
2291
- */
2292
- function splitTextToChars(htmlString: string, startIndex?: number, preserveInterElementWhitespace?: boolean): string;
2293
- }
2294
- namespace object {
2295
- /**
2296
- * Flattens a nested object into a single-level object with dot-separated keys.
2297
- * @param obj - The nested object to be flattened.
2298
- * @param prefix - The prefix to be added to each key (used for recursion).
2299
- * @returns A flattened object with dot-separated keys.
2300
- * @example
2301
- * ```javascript
2302
- * const nestedObj = { a: { b: 1, c: { d: 2 } }, e: [3, 4] };
2303
- * const flatObj = flatten(nestedObj);
2304
- * console.log(flatObj);
2305
- * // Output: { 'a.b': '1', 'a.c.d': '2', 'e:0': '3', 'e:1': '4' }
2306
- * ```
2307
- */
2308
- function flatten(obj: Record<string, any>, stringify?: boolean, prefix?: string): Record<string, typeof stringify extends true ? string : string | number | boolean>;
2309
- /**
2310
- * Returns the entries of an object as an array of key-value pairs, with proper typing.
2311
- * @param obj - The object to retrieve entries from.
2312
- * @returns An array of key-value pairs from the object, typed as an array of tuples with key and value types.
2313
- */
2314
- function entries<K extends string, V>(obj: Record<K, V>): [K, V][];
2315
- /**
2316
- * Returns the values of an object as an array, with proper typing.
2317
- * @param obj - The object to retrieve values from.
2318
- * @returns An array of values from the object, typed as an array of the value type.
2319
- */
2320
- function values<K extends string, V>(obj: Record<K, V>): V[];
2321
- /**
2322
- * Returns the keys of an object as an array of strings, with proper typing.
2323
- * @param obj - The object to retrieve keys from.
2324
- * @returns An array of keys from the object, typed as an array of strings.
2325
- */
2326
- function keys<K extends string, V>(obj: Record<K, V>): K[];
2327
- }
2328
- namespace message {
2329
- type BadgeOptions = Twitch.roles[] | Twitch.roles | `${Twitch.roles}/${number}` | `${Twitch.roles}/${number}`[];
2330
- type TwitchResult = {
2331
- keys: Twitch.roles[];
2332
- badges: Twitch.badge[];
2333
- amount: {
2334
- [K in Twitch.roles]?: number;
2335
- };
2336
- };
2337
- type YouTubeResult = {
2338
- isVerified: boolean;
2339
- isChatOwner: boolean;
2340
- isChatSponsor: boolean;
2341
- isChatModerator: boolean;
2342
- };
2343
- /**
2344
- * Finds emotes in a given text.
2345
- * @param text - The text to search for emotes.
2346
- * @param emotes - An array of emotes to search for. Defaults to Local data emotes.
2347
- * @returns An array of emotes found in the text with their positions.
2348
- */
2349
- function findEmotesInText(text: string, emotes?: Emote[]): Emote[];
2350
- /**
2351
- * Replaces emotes in the text with corresponding HTML image tags.
2352
- * @param text - The text containing emotes.
2353
- * @param emotes - An array of emotes with their positions in the text.
2354
- * @returns The text with emotes replaced by HTML image tags.
2355
- */
2356
- function replaceEmotesWithHTML(text: string, emotes: Emote[]): string;
2357
- /**
2358
- * Checks if the text contains only emotes and whitespace.
2359
- * @param text - The text to check.
2360
- * @param emotes - An array of emotes with their positions in the text.
2361
- * @returns True if the text contains only emotes and whitespace, false otherwise.
2362
- */
2363
- function hasOnlyEmotes(text: string, emotes: Emote[]): boolean;
2364
- /**
2365
- * Replaces YouTube emotes in the text with corresponding HTML image tags.
2366
- * @param text - The text containing YouTube emotes.
2367
- * @param emotes - An array of YouTube emotes. Defaults to Local data YouTube emotes.
2368
- * @returns The text with YouTube emotes replaced by HTML image tags.
2369
- */
2370
- function replaceYoutubeEmotesWithHTML(text: string, emotes?: {
2371
- emojiId: string;
2372
- shortcuts: string[];
2373
- searchTerms: string[];
2374
- image: {
2375
- thumbnails: {
2376
- url: string;
2377
- width: number;
2378
- height: number;
2379
- }[];
2380
- accessibility: {
2381
- accessibilityData: {
2382
- label: string;
2383
- };
2384
- };
2385
- };
2386
- isCustomEmoji: boolean;
2387
- index: number;
2388
- }[]): string;
2389
- /**
2390
- * Generates badge data based on the provided badges and platform.
2391
- * @param badges - The badges to generate. Can be an array or a comma-separated string.
2392
- * @param provider - The platform provider ('twitch' or 'youtube'). Defaults to 'twitch'.
2393
- * @returns A promise that resolves to the generated badge data.
2394
- * @example
2395
- * ```javascript
2396
- * // Generate Twitch badges
2397
- * const twitchBadges = await generateBadges(['broadcaster', 'moderator'], 'twitch');
2398
- * // Generate YouTube badges
2399
- * const youtubeBadges = await generateBadges('sponsor, moderator', 'youtube');
2400
- * ```
2401
- */
2402
- function generateBadges<T extends Provider$1>(badges: BadgeOptions | undefined, provider: T): Promise<T extends 'twitch' ? TwitchResult : YouTubeResult>;
2403
- }
2404
- namespace event {
2405
- /**
2406
- * Parses the provider information from the event detail object.
2407
- * @param detail - The event detail object received from the StreamElements event.
2408
- * @returns An object containing the provider and the original event data.
2409
- */
2410
- function parseProvider(detail: StreamElements.Event.onEventReceived, _provider?: Provider$1): ClientEvents$1;
2411
- }
2412
- namespace string {
2413
- type Modifier = (value: string, param: string | null | undefined, values: {
2414
- amount?: number;
2415
- count?: number;
2416
- }) => string;
2417
- const PRESETS: Record<string, string>;
2418
- /**
2419
- * Replaces occurrences in a string based on a pattern with the result of an asynchronous callback function.
2420
- * @param string - The input string to perform replacements on.
2421
- * @param pattern - The pattern to match in the string (can be a string or a regular expression).
2422
- * @param callback - An asynchronous callback function that takes the matched substring and any captured groups as arguments and returns the replacement string.
2423
- * @returns A promise that resolves to the modified string with replacements applied.
2424
- * @example
2425
- * ```javascript
2426
- * const result = await string.replace("Hello World", /World/, async (match) => {
2427
- * return await fetchSomeData(match); // Assume this function fetches data asynchronously
2428
- * });
2429
- * console.log(result); // Output will depend on the fetched data
2430
- * ```
2431
- */
2432
- function replace(string: string, pattern: string, callback: (match: string, ...groups: string[]) => Promise<string> | string): Promise<string>;
2433
- /**
2434
- * Capitalizes the first letter of a given string.
2435
- * @param string - The input string to be capitalized.
2436
- * @returns The capitalized string.
2437
- * @example
2438
- * ```javascript
2439
- * const result = string.capitalize("hello world");
2440
- * console.log(result); // Output: "Hello world"
2441
- * ```
2442
- */
2443
- function capitalize(string: string): Capitalize<string>;
2444
- /**
2445
- * Composes a template string by replacing placeholders with corresponding values and applying optional modifiers.
2446
- * @param template - The template string containing placeholders in the format {key} and optional modifiers in the format [MODIFIER:param=value].
2447
- * @param values - An object containing key-value pairs to replace the placeholders in the template.
2448
- * @param options - Optional settings for the composition process.
2449
- * @returns The composed string with placeholders replaced and modifiers applied.
2450
- * @example
2451
- * ```javascript
2452
- * const { string } = Tixyel.Helper;
2453
- *
2454
- * // Basic usage with placeholders and simple modifiers
2455
- * const template1 = "Hello, {username}! You have {amount} [UPC=messages] and your name is [CAP=name].";
2456
- * const values1 = { username: "john_doe", amount: 5, name: "john" };
2457
- * const result1 = string.compose(template1, values1);
2458
- * // "Hello, john_doe! You have 5 MESSAGES and your name is John."
2459
- *
2460
- * // Multiple modifiers in a single block (HTML enabled)
2461
- * const template2 = "[COLOR:#ff0056,BOLD={username}]";
2462
- * const values2 = { username: "john_doe" };
2463
- * const result2 = string.compose(template2, values2, { html: true });
2464
- * // '<span class="color bold" style="color: #ff0056; font-weight: bold;">john_doe</span>'
2465
- *
2466
- * // Conditional rendering with IF (supports ===, >=, &&, ||, !, etc.)
2467
- * const template3 = "[IF=vip && status === 'live'?VIP Online|Offline]";
2468
- * const values3 = { status: 'live', vip: true };
2469
- * const result3 = string.compose(template3, values3);
2470
- * // "VIP Online"
2471
- *
2472
- * // Pluralization using amount / count or an explicit key
2473
- * const template4 = "You have {amount} [PLURAL=message|messages].";
2474
- * const values4 = { amount: 1 };
2475
- * const values5 = { amount: 3 };
2476
- * const result4a = string.compose(template4, values4); // "You have 1 message."
2477
- * const result4b = string.compose(template4, values5); // "You have 3 messages."
2478
- *
2479
- * // Number formatting
2480
- * const template5 = "Total: [NUMBER:2=amount] {currency}";
2481
- * const values6 = { amount: 1234.5, currency: '$' };
2482
- * const result5 = string.compose(template5, values6);
2483
- * // e.g. "Total: 1,234.50 $" (locale dependent)
2484
- *
2485
- * // Date and time formatting
2486
- * const template6 = "Created at: [DATE:iso=createdAt] ([DATE:relative=createdAt])";
2487
- * const values7 = { createdAt: new Date('2020-01-02T03:04:05.000Z') };
2488
- * const result6 = string.compose(template6, values7);
2489
- * // e.g. "Created at: 2020-01-02T03:04:05.000Z (Xs ago)"
2490
- *
2491
- * // MAP / SWITCH style mapping
2492
- * const template7 = "Status: [MAP:status=live:Online|offline:Offline|default:Unknown]";
2493
- * const values8 = { status: 'offline' };
2494
- * const result7 = string.compose(template7, values8);
2495
- * // "Status: Offline"
2496
- *
2497
- * // Escaping HTML
2498
- * const template8 = "[ESCAPE={message}]";
2499
- * const values9 = { message: '<b>Danger & "HTML"</b>' };
2500
- * const result8 = string.compose(template8, values9);
2501
- * // "&lt;b&gt;Danger &amp; &quot;HTML&quot;&lt;/b&gt;"
2502
- *
2503
- * // Using global presets
2504
- * Helper.string.PRESETS['alert'] = 'BOLD,COLOR:#ff0056';
2505
- * const template10 = "[PRESET:alert={username}]";
2506
- * const values11 = { username: 'john_doe' };
2507
- * const result10 = string.compose(template10, values11, { html: true });
2508
- * // '<span class="color bold" style="color: #ff0056; font-weight: bold;">john_doe</span>'
2509
- * ```
2510
- */
2511
- function compose(template: string, values?: Record<string, any>, options?: {
2512
- method?: 'loop' | 'index';
2513
- html?: boolean;
2514
- debug?: boolean;
2515
- modifiers?: Record<string, Modifier>;
2516
- aliases?: Record<string, string[]>;
2517
- }): string;
2518
- }
2519
- namespace sound {
2520
- let playing: boolean;
2521
- let audio: AudioContext;
2522
- /**
2523
- * Play sound from URL with optional volume and replace parameters
2524
- * @param url - Sound URL to play
2525
- * @param volume - Volume level from 0 to 100 (default: 100)
2526
- * @param replace - If true, replaces currently playing sound (default: false)
2527
- */
2528
- function play(url: string, volume?: number, replace?: boolean): void;
2529
- }
2530
- namespace color {
2531
- /**
2532
- * Generate opacity hex value
2533
- * @param opacity - Opacity value from 0 to 100
2534
- * @param color - Hex color code
2535
- * @returns - Hex color code with opacity
2536
- */
2537
- function opacity(opacity?: number, color?: string): string;
2538
- /**
2539
- * Extract color and opacity from hex code
2540
- * @param hex - Hex color code
2541
- * @returns - Object with color and opacity
2542
- */
2543
- function extract(hex: string): {
2544
- color: string;
2545
- opacity: number;
2546
- };
2547
- /**
2548
- * Validate color string format
2549
- * @param str - Color string to validate
2550
- * @returns Detected color format or false if invalid
2551
- * @example
2552
- * ```javascript
2553
- * const format1 = color.validate("#FF5733"); // "hex"
2554
- * const format2 = color.validate("rgb(255, 87, 51)"); // "rgb"
2555
- * const format3 = color.validate("hsl(14, 100%, 60%)"); // "hsl"
2556
- * const format4 = color.validate("orangered"); // "css-color-name"
2557
- * const format5 = color.validate("invalid-color"); // false
2558
- * ```
2559
- */
2560
- function validate(str: string): false | "hex" | "rgb" | "rgba" | "hsl" | "hsla" | "css-color-name";
2561
- /**
2562
- * Convert color to different format
2563
- * @param str - Color string to convert (e.g. "#FF5733", "rgb(255, 87, 51)")
2564
- * @param format - Target format
2565
- * @returns - Converted color string
2566
- * @example
2567
- * ```javascript
2568
- * const hexColor = color.convert("rgb(255, 87, 51)", "hex"); // "#FF5733"
2569
- * const rgbColor = color.convert("#FF5733", "rgb"); // "rgb(255, 87, 51)"
2570
- * const hslColor = color.convert("#FF5733", "hsl"); // "hsl(14, 100%, 60%)"
2571
- * const colorName = color.convert("#FF5733", "css-color-name"); // "orangered"
2572
- * ```
2573
- */
2574
- function convert(str: string, format: 'hex' | 'rgb' | 'rgba' | 'hsl' | 'hsla' | 'css-color-name'): Promise<string | null>;
2575
- }
2576
- namespace random {
2577
- /**
2578
- * Generate random color
2579
- * @param type - Color format
2580
- * @returns - Random color in specified format
2581
- * @example
2582
- * ```javascript
2583
- * const hexColor = random.color('hex');
2584
- * console.log(hexColor); // e.g. #3e92cc
2585
- *
2586
- * const rgbColor = random.color('rgb');
2587
- * console.log(rgbColor); // e.g. rgb(62, 146, 204)
2588
- * ```
2589
- */
2590
- function color(type?: 'hex' | 'hexa' | 'rgb' | 'rgba' | 'hsl' | 'hsla' | 'css-color-name'): string;
2591
- /**
2592
- * Generate random number
2593
- * @param min - Minimum value
2594
- * @param max - Maximum value
2595
- * @param float - Number of decimal places (0 for integer)
2596
- * @returns - Random number
2597
- * @example
2598
- * ```javascript
2599
- * const intNumber = random.number(1, 10);
2600
- * console.log(intNumber); // e.g. 7
2601
- *
2602
- * const floatNumber = random.number(1, 10, 2);
2603
- * console.log(floatNumber); // e.g. 3.14
2604
- * ```
2605
- */
2606
- function number(min: number, max: number, float?: number): number;
2607
- /**
2608
- * Generate random boolean
2609
- * @param threshold - Threshold between 0 and 1
2610
- * @returns - Random boolean
2611
- * @example
2612
- * ```javascript
2613
- * const boolValue = random.boolean(0.7);
2614
- * console.log(boolValue); // e.g. true (70% chance)
2615
- * ```
2616
- */
2617
- function boolean(threshold?: number): boolean;
2618
- /**
2619
- * Generate random string
2620
- * @param length - Length of the string
2621
- * @param chars - Characters to use
2622
- * @returns - Random string
2623
- * @example
2624
- * ```javascript
2625
- * const randString = random.string(10);
2626
- * console.log(randString); // e.g. "aZ3bT9xYqP"
2627
- * ```
2628
- */
2629
- function string(length: number, chars?: string): string;
2630
- /**
2631
- * Pick random element from array
2632
- * @param arr - Array to pick from
2633
- * @returns - Random element and its index
2634
- * @example
2635
- * ```javascript
2636
- * const [element, index] = random.array(['apple', 'banana', 'cherry']);
2637
- * console.log(element, index); // e.g. "banana", 1
2638
- * ```
2639
- */
2640
- function array<T>(arr: T[]): [value: T, index: number];
2641
- /**
2642
- * Generate random date
2643
- * @param start - Start date
2644
- * @param end - End date
2645
- * @returns - Random date between start and end
2646
- * @example
2647
- * ```javascript
2648
- * const randDate = random.date(new Date(2020, 0, 1), new Date());
2649
- * console.log(randDate); // e.g. 2022-05-15T10:30:00.000Z
2650
- * ```
2651
- */
2652
- function date(start?: Date, end?: Date): Date;
2653
- /**
2654
- * Generate ISO date string offset by days
2655
- * @param daysAgo - Number of days to go back
2656
- * @returns - ISO date string
2657
- * @example
2658
- * ```javascript
2659
- * const isoDate = random.daysOffset(7);
2660
- * console.log(isoDate); // e.g. "2024-06-10T14:23:45.678Z"
2661
- *
2662
- * const isoDate30 = random.daysOffset(30);
2663
- * console.log(isoDate30); // e.g. "2024-05-18T09:15:30.123Z"
2664
- * ```
2665
- */
2666
- function daysOffset(daysAgo: number): string;
2667
- /**
2668
- * Generate UUID v4
2669
- * @returns - UUID string
2670
- * @example
2671
- * ```javascript
2672
- * const uuid = random.uuid();
2673
- * console.log(uuid); // e.g. "3b12f1df-5232-4e3a-9a0c-3f9f1b1b1b1b"
2674
- * ```
2675
- */
2676
- function uuid(): string;
2677
- }
2678
- namespace fn {
2679
- /**
2680
- * Apply function with given thisArg and arguments
2681
- * @param fn - Function to apply
2682
- * @param thisArg - Value to use as this when calling fn
2683
- * @param args - Arguments to pass to fn
2684
- * @returns Result of calling fn with thisArg and args
2685
- */
2686
- function apply<TThis, TArgs extends unknown[], TReturn>(fn: (this: TThis, ...args: TArgs) => TReturn, thisArg: TThis, args: TArgs): TReturn;
2687
- /**
2688
- * Call function with given thisArg and arguments
2689
- * @param fn - Function to call
2690
- * @param thisArg - Value to use as this when calling fn
2691
- * @param args - Arguments to pass to fn
2692
- * @returns Result of calling fn with thisArg and args
2693
- */
2694
- function call<TThis, TArgs extends unknown[], TReturn>(fn: (this: TThis, ...args: TArgs) => TReturn, thisArg: TThis, ...args: TArgs): TReturn;
2695
- }
2696
- namespace utils {
2697
- /**
2698
- * Delays execution for a specified number of milliseconds.
2699
- * @param ms - The number of milliseconds to delay.
2700
- * @returns A Promise that resolves after the specified delay.
2701
- */
2702
- function delay<R extends any, M extends number>(ms: M, callback?: () => R): Promise<R | null>;
2703
- /**
2704
- * Returns typed entries of an object.
2705
- * @param obj - The object to get entries from.
2706
- * @returns An array of key-value pairs from the object.
2707
- */
2708
- function typedEntries<K extends string, V>(obj: Record<K, V> | Array<V>): [K, V][];
2709
- /**
2710
- * Returns typed values of an object.
2711
- * @param obj - The object to get values from.
2712
- * @returns An array of values from the object.
2713
- */
2714
- function typedValues<K extends string, V>(obj: Record<K, V> | Array<V>): V[];
2715
- /**
2716
- * Returns typed keys of an object.
2717
- * @param obj - The object to get keys from.
2718
- * @returns An array of keys from the object.
2719
- */
2720
- function typedKeys<K extends string, V>(obj: Record<K, V> | Array<V>): K[];
2721
- /**
2722
- * Selects an item based on weighted probabilities.
2723
- * @param items - An object where keys are items and values are their weights.
2724
- * @returns A randomly selected item based on the given probabilities.
2725
- */
2726
- function probability<K extends string, V extends number>(items: Record<K, V>): K | undefined;
2727
- }
2728
- }
2729
-
2730
- declare namespace Local {
2731
- type QueueItem = {
2732
- listener: 'onEventReceived';
2733
- data: StreamElements.Event.onEventReceived;
2734
- session?: boolean;
2735
- } | {
2736
- listener: 'onWidgetLoad';
2737
- data: StreamElements.Event.onWidgetLoad;
2738
- } | {
2739
- listener: 'onSessionUpdate';
2740
- data: StreamElements.Event.onSessionUpdate;
2741
- };
2742
- const queue: useQueue<QueueItem>;
2743
- const generate: {
2744
- session: {
2745
- types: Record<string, StreamElements.Session.Config.Any>;
2746
- available(): StreamElements.Session.Config.Available.Data;
2747
- get(startSession?: StreamElements.Session.Data): Promise<StreamElements.Session.Data>;
2748
- };
2749
- event: {
2750
- /**
2751
- * Simulates the onWidgetLoad event for a widget.
2752
- * @param fields - The field values to be included in the event.
2753
- * @param session - The session data to be included in the event.
2754
- * @param currency - The currency to be used (default is 'USD').
2755
- * @returns A Promise that resolves to the simulated onWidgetLoad event data.
2756
- */
2757
- onWidgetLoad(fields: Record<string, StreamElements.CustomField.Value>, session: StreamElements.Session.Data, currency?: "BRL" | "USD" | "EUR"): Promise<StreamElements.Event.onWidgetLoad>;
2758
- /**
2759
- * Simulates the onSessionUpdate event for a widget.
2760
- * @param session - The session data to be included in the event.
2761
- * @returns A Promise that resolves to the simulated onSessionUpdate event data.
2762
- */
2763
- onSessionUpdate(session?: StreamElements.Session.Data, update?: ClientEvents$1): Promise<StreamElements.Event.onSessionUpdate>;
2764
- /**
2765
- * Simulates the onEventReceived event for a widget.
2766
- * @param provider - The provider of the event (default is 'random').
2767
- * @param type - The type of event to simulate (default is 'random').
2768
- * @param options - Additional options to customize the event data.
2769
- * @returns A Promise that resolves to the simulated onEventReceived event data, or null if the event type is not supported.
2770
- * @example
2771
- * ```javascript
2772
- * // Simulate a random event
2773
- * const randomEvent = await Local .generate.event.onEventReceived();
2774
- *
2775
- * // Simulate a Twitch message event with custom options
2776
- * const twitchMessageEvent = await Local .generate.event.onEventReceived('twitch', 'message', { name: 'Streamer', message: 'Hello World!' });
2777
- * ```
2778
- */
2779
- 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>;
2780
2238
  };
2781
2239
  };
2782
2240
  const emulate: {
@@ -2784,7 +2242,7 @@ declare namespace Local {
2784
2242
  message(data?: Partial<{
2785
2243
  name: string;
2786
2244
  message: string;
2787
- badges: Helper.message.BadgeOptions;
2245
+ badges: BadgeOptions;
2788
2246
  color: string;
2789
2247
  userId: string;
2790
2248
  msgId: string;
@@ -2844,7 +2302,7 @@ declare namespace Local {
2844
2302
  message(data?: Partial<{
2845
2303
  name: string;
2846
2304
  message: string;
2847
- badges: Helper.message.BadgeOptions;
2305
+ badges: BadgeOptions;
2848
2306
  color: string;
2849
2307
  userId: string;
2850
2308
  msgId: string;
@@ -2880,6 +2338,568 @@ declare namespace Local {
2880
2338
  function start(fieldsFile?: string[], dataFiles?: string[], session?: StreamElements.Session.Data): Promise<void>;
2881
2339
  }
2882
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
+
2883
2903
  declare namespace Data {
2884
2904
  const avatars: string[];
2885
2905
  const badges: Record<Twitch.roles, Twitch.badge>;