@tixyel/streamelements 5.5.0 → 6.0.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
@@ -1919,7 +1919,7 @@ type QueueProps = {
1919
1919
  type QueueItem<T> = {
1920
1920
  value: T;
1921
1921
  } & QueueProps;
1922
- type QueueProcessor<T> = (item: T, queue: useQueue<T>) => Promise<any>;
1922
+ type QueueProcessor<T> = (this: useQueue<T>, item: T, queue: useQueue<T>) => Promise<any>;
1923
1923
  type QueueDuration = number | boolean | undefined;
1924
1924
  interface QueueOptions<T> {
1925
1925
  /**
@@ -1939,7 +1939,7 @@ interface QueueOptions<T> {
1939
1939
  * ```javascript
1940
1940
  * const myQueue = new useQueue({
1941
1941
  * duration: 1000,
1942
- * processor: async (item) => {
1942
+ * processor: async function (item) {
1943
1943
  * console.log('Processing item:', item);
1944
1944
  * },
1945
1945
  * });
@@ -1958,12 +1958,59 @@ declare class useQueue<T> extends EventProvider<QueueEvents<T>> {
1958
1958
  private loaded;
1959
1959
  processor: QueueProcessor<T>;
1960
1960
  constructor(options: QueueOptions<T>);
1961
+ /**
1962
+ * Enqueue an item or multiple items into the queue with optional processing options.
1963
+ * @param value - The item or items to be enqueued. Can be a single value of type T or an array of objects containing the value and options.
1964
+ * @param options - Optional processing options for the item(s) being enqueued. Ignored if an array of items is provided, as each item can have its own options.
1965
+ * @returns The instance of the queue for chaining.
1966
+ * @example
1967
+ * ```javascript
1968
+ * myQueue.enqueue('Single Item', { isPriority: true });
1969
+ * myQueue.enqueue([
1970
+ * { value: 'Item 1', options: { isPriority: true } },
1971
+ * { value: 'Item 2', options: { isLoop: true } }
1972
+ * ]);
1973
+ * ```
1974
+ */
1961
1975
  enqueue(value: T, options?: Partial<QueueProps>): this;
1976
+ enqueue(items: {
1977
+ value: T;
1978
+ options?: Partial<QueueProps>;
1979
+ }[]): this;
1962
1980
  private run;
1963
1981
  private next;
1982
+ /**
1983
+ * Resume processing the queue if it is paused. If the queue is already running, it will be restarted, which can be useful if new items have been added or if you want to reset the processing timer.
1984
+ * If the queue was empty before, it will start processing immediately.
1985
+ * @returns - The instance of the queue for chaining.
1986
+ * @example
1987
+ * ```javascript
1988
+ * myQueue.resume();
1989
+ * ```
1990
+ */
1964
1991
  resume(): this;
1992
+ /**
1993
+ * Update the queue's state with new values. This can be used to replace the current queue, priority queue, history, or timeouts with new data. If the queue is not currently running and there are items in the queue after the update, it will start processing immediately.
1994
+ * @param save - An object containing the new state for the queue, priority queue, history, and timeouts. Each property is optional, and if not provided, the current state will be retained.
1995
+ * @returns - The instance of the queue for chaining.
1996
+ * @example
1997
+ * ```javascript
1998
+ * myQueue.update({
1999
+ * queue: newQueueItems,
2000
+ * priorityQueue: newPriorityItems,
2001
+ * history: newHistory,
2002
+ * });
2003
+ * ```
2004
+ */
1965
2005
  update(save: Partial<useQueue<T>>): this;
2006
+ /**
2007
+ * Cancel all pending timeouts and stop the queue from processing further items. This will clear any scheduled processing and prevent any new items from being processed until `resume()` is called again. The current state of the queue, priority queue, and history will be retained, allowing you to resume processing later without losing any data.
2008
+ */
1966
2009
  cancel(): void;
2010
+ /**
2011
+ * Check if there are any items in the queue or priority queue. This method returns `true` if there are items waiting to be processed in either the main queue or the priority queue, and `false` if both queues are empty.
2012
+ * @returns - A boolean indicating whether there are items in the queue or priority queue.
2013
+ */
1967
2014
  hasItems(): boolean;
1968
2015
  on<K extends keyof QueueEvents<T>>(eventName: K, callback: (this: useQueue<T>, ...args: QueueEvents<T>[K]) => void): this;
1969
2016
  }
@@ -2248,6 +2295,7 @@ declare namespace Helper {
2248
2295
  amount?: number;
2249
2296
  count?: number;
2250
2297
  }) => string;
2298
+ const PRESETS: Record<string, string>;
2251
2299
  /**
2252
2300
  * Replaces occurrences in a string based on a pattern with the result of an asynchronous callback function.
2253
2301
  * @param string - The input string to perform replacements on.
@@ -2282,15 +2330,69 @@ declare namespace Helper {
2282
2330
  * @returns The composed string with placeholders replaced and modifiers applied.
2283
2331
  * @example
2284
2332
  * ```javascript
2285
- * const template = "Hello, {username}! You have {amount} [UPPERCASE=messages] and your name is [CAPITALIZE=name].";
2286
- * const values = { username: "john_doe", amount: 5, name: "john" };
2287
- * const result = string.compose(template, values);
2288
- * console.log(result); // Output: "Hello, john_doe! You have 5 MESSAGES and your name is John."
2333
+ * const { string } = Tixyel.Helper;
2334
+ *
2335
+ * // Basic usage with placeholders and simple modifiers
2336
+ * const template1 = "Hello, {username}! You have {amount} [UPC=messages] and your name is [CAP=name].";
2337
+ * const values1 = { username: "john_doe", amount: 5, name: "john" };
2338
+ * const result1 = string.compose(template1, values1);
2339
+ * // "Hello, john_doe! You have 5 MESSAGES and your name is John."
2340
+ *
2341
+ * // Multiple modifiers in a single block (HTML enabled)
2342
+ * const template2 = "[COLOR:#ff0056,BOLD={username}]";
2343
+ * const values2 = { username: "john_doe" };
2344
+ * const result2 = string.compose(template2, values2, { html: true });
2345
+ * // '<span class="color bold" style="color: #ff0056; font-weight: bold;">john_doe</span>'
2346
+ *
2347
+ * // Conditional rendering with IF (supports ===, >=, &&, ||, !, etc.)
2348
+ * const template3 = "[IF=vip && status === 'live'?VIP Online|Offline]";
2349
+ * const values3 = { status: 'live', vip: true };
2350
+ * const result3 = string.compose(template3, values3);
2351
+ * // "VIP Online"
2352
+ *
2353
+ * // Pluralization using amount / count or an explicit key
2354
+ * const template4 = "You have {amount} [PLURAL=message|messages].";
2355
+ * const values4 = { amount: 1 };
2356
+ * const values5 = { amount: 3 };
2357
+ * const result4a = string.compose(template4, values4); // "You have 1 message."
2358
+ * const result4b = string.compose(template4, values5); // "You have 3 messages."
2359
+ *
2360
+ * // Number formatting
2361
+ * const template5 = "Total: [NUMBER:2=amount] {currency}";
2362
+ * const values6 = { amount: 1234.5, currency: '$' };
2363
+ * const result5 = string.compose(template5, values6);
2364
+ * // e.g. "Total: 1,234.50 $" (locale dependent)
2365
+ *
2366
+ * // Date and time formatting
2367
+ * const template6 = "Created at: [DATE:iso=createdAt] ([DATE:relative=createdAt])";
2368
+ * const values7 = { createdAt: new Date('2020-01-02T03:04:05.000Z') };
2369
+ * const result6 = string.compose(template6, values7);
2370
+ * // e.g. "Created at: 2020-01-02T03:04:05.000Z (Xs ago)"
2371
+ *
2372
+ * // MAP / SWITCH style mapping
2373
+ * const template7 = "Status: [MAP:status=live:Online|offline:Offline|default:Unknown]";
2374
+ * const values8 = { status: 'offline' };
2375
+ * const result7 = string.compose(template7, values8);
2376
+ * // "Status: Offline"
2377
+ *
2378
+ * // Escaping HTML
2379
+ * const template8 = "[ESCAPE={message}]";
2380
+ * const values9 = { message: '<b>Danger & "HTML"</b>' };
2381
+ * const result8 = string.compose(template8, values9);
2382
+ * // "&lt;b&gt;Danger &amp; &quot;HTML&quot;&lt;/b&gt;"
2383
+ *
2384
+ * // Using global presets
2385
+ * Helper.string.PRESETS['alert'] = 'BOLD,COLOR:#ff0056';
2386
+ * const template10 = "[PRESET:alert={username}]";
2387
+ * const values11 = { username: 'john_doe' };
2388
+ * const result10 = string.compose(template10, values11, { html: true });
2389
+ * // '<span class="color bold" style="color: #ff0056; font-weight: bold;">john_doe</span>'
2289
2390
  * ```
2290
2391
  */
2291
2392
  function compose(template: string, values?: Record<string, any>, options?: {
2292
2393
  method?: 'loop' | 'index';
2293
2394
  html?: boolean;
2395
+ debug?: boolean;
2294
2396
  modifiers?: Record<string, Modifier>;
2295
2397
  aliases?: Record<string, string[]>;
2296
2398
  }): string;