@tixyel/streamelements 5.4.0 → 6.0.0

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
@@ -2248,6 +2248,7 @@ declare namespace Helper {
2248
2248
  amount?: number;
2249
2249
  count?: number;
2250
2250
  }) => string;
2251
+ const PRESETS: Record<string, string>;
2251
2252
  /**
2252
2253
  * Replaces occurrences in a string based on a pattern with the result of an asynchronous callback function.
2253
2254
  * @param string - The input string to perform replacements on.
@@ -2282,15 +2283,69 @@ declare namespace Helper {
2282
2283
  * @returns The composed string with placeholders replaced and modifiers applied.
2283
2284
  * @example
2284
2285
  * ```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."
2286
+ * const { string } = Tixyel.Helper;
2287
+ *
2288
+ * // Basic usage with placeholders and simple modifiers
2289
+ * const template1 = "Hello, {username}! You have {amount} [UPC=messages] and your name is [CAP=name].";
2290
+ * const values1 = { username: "john_doe", amount: 5, name: "john" };
2291
+ * const result1 = string.compose(template1, values1);
2292
+ * // "Hello, john_doe! You have 5 MESSAGES and your name is John."
2293
+ *
2294
+ * // Multiple modifiers in a single block (HTML enabled)
2295
+ * const template2 = "[COLOR:#ff0056,BOLD={username}]";
2296
+ * const values2 = { username: "john_doe" };
2297
+ * const result2 = string.compose(template2, values2, { html: true });
2298
+ * // '<span class="color bold" style="color: #ff0056; font-weight: bold;">john_doe</span>'
2299
+ *
2300
+ * // Conditional rendering with IF (supports ===, >=, &&, ||, !, etc.)
2301
+ * const template3 = "[IF=vip && status === 'live'?VIP Online|Offline]";
2302
+ * const values3 = { status: 'live', vip: true };
2303
+ * const result3 = string.compose(template3, values3);
2304
+ * // "VIP Online"
2305
+ *
2306
+ * // Pluralization using amount / count or an explicit key
2307
+ * const template4 = "You have {amount} [PLURAL=message|messages].";
2308
+ * const values4 = { amount: 1 };
2309
+ * const values5 = { amount: 3 };
2310
+ * const result4a = string.compose(template4, values4); // "You have 1 message."
2311
+ * const result4b = string.compose(template4, values5); // "You have 3 messages."
2312
+ *
2313
+ * // Number formatting
2314
+ * const template5 = "Total: [NUMBER:2=amount] {currency}";
2315
+ * const values6 = { amount: 1234.5, currency: '$' };
2316
+ * const result5 = string.compose(template5, values6);
2317
+ * // e.g. "Total: 1,234.50 $" (locale dependent)
2318
+ *
2319
+ * // Date and time formatting
2320
+ * const template6 = "Created at: [DATE:iso=createdAt] ([DATE:relative=createdAt])";
2321
+ * const values7 = { createdAt: new Date('2020-01-02T03:04:05.000Z') };
2322
+ * const result6 = string.compose(template6, values7);
2323
+ * // e.g. "Created at: 2020-01-02T03:04:05.000Z (Xs ago)"
2324
+ *
2325
+ * // MAP / SWITCH style mapping
2326
+ * const template7 = "Status: [MAP:status=live:Online|offline:Offline|default:Unknown]";
2327
+ * const values8 = { status: 'offline' };
2328
+ * const result7 = string.compose(template7, values8);
2329
+ * // "Status: Offline"
2330
+ *
2331
+ * // Escaping HTML
2332
+ * const template8 = "[ESCAPE={message}]";
2333
+ * const values9 = { message: '<b>Danger & "HTML"</b>' };
2334
+ * const result8 = string.compose(template8, values9);
2335
+ * // "&lt;b&gt;Danger &amp; &quot;HTML&quot;&lt;/b&gt;"
2336
+ *
2337
+ * // Using global presets
2338
+ * Helper.string.PRESETS['alert'] = 'BOLD,COLOR:#ff0056';
2339
+ * const template10 = "[PRESET:alert={username}]";
2340
+ * const values11 = { username: 'john_doe' };
2341
+ * const result10 = string.compose(template10, values11, { html: true });
2342
+ * // '<span class="color bold" style="color: #ff0056; font-weight: bold;">john_doe</span>'
2289
2343
  * ```
2290
2344
  */
2291
2345
  function compose(template: string, values?: Record<string, any>, options?: {
2292
2346
  method?: 'loop' | 'index';
2293
2347
  html?: boolean;
2348
+ debug?: boolean;
2294
2349
  modifiers?: Record<string, Modifier>;
2295
2350
  aliases?: Record<string, string[]>;
2296
2351
  }): string;