dff-util 1.3.8 → 1.3.9

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/README.md CHANGED
@@ -530,6 +530,7 @@ Based on the `dff-hbs` service in the local `hbs` repository (`src/models.rs`, `
530
530
  | Object property values | JSON string, number, boolean, null, object, or array | Nested data is supported, for example `{ user: { name: 'Prasad' }, active: true }` |
531
531
  | Single result | `string` | Rendered text from `/render` |
532
532
  | Batch result | `string[]` | Rendered strings in input order from `/multi`; an empty array returns `[]` |
533
+ | `data` is `null`/`undefined` | no request | Returns `template` unchanged; `[template]` when `multi = true` |
533
534
 
534
535
  #### Template helper reference
535
536
 
@@ -593,7 +594,7 @@ console.log(rendered); // ['Hello, Prasad!', 'Hello, Monika!']
593
594
 
594
595
  The third argument defaults to `false`. Set it to `true` to render the same template once per array item, preserving order. An empty batch returns `[]`. With `false`, an array is treated as a single template context, for example with `{{#each this}}`.
595
596
 
596
- Both endpoints receive JSON in the form `{ template, data }`. Templates can use the string helpers and `switch` helper registered by HBS. Data must be a JSON object or an array of JSON objects; batch rendering requires an array of objects. Empty templates are allowed. Omitting `multi` is equivalent to passing `false`.
597
+ Both endpoints receive JSON in the form `{ template, data }`. Templates can use the string helpers and `switch` helper registered by HBS. Data must be a JSON object or an array of JSON objects; batch rendering requires an array of objects. If `data` is `null` or `undefined`, no request is made and the template is returned unchanged, or as `[template]` when `multi = true`. Empty templates are allowed. Omitting `multi` is equivalent to passing `false`.
597
598
 
598
599
  #### Handle failures
599
600
 
@@ -1,6 +1,6 @@
1
1
  import { RequestBodyType } from './const-type';
2
2
  /** Render an inline Handlebars template using the hosted HBS service. */
3
- export declare function CallHbs(template: string, data: RequestBodyType | RequestBodyType[], multi?: boolean): string | string[];
3
+ export declare function CallHbs(template: string, data: RequestBodyType | RequestBodyType[] | null | undefined, multi?: boolean): string | string[];
4
4
  export declare const CallLangText: (data: string, source: string, target: string) => string;
5
5
  /** Return the exchange rate for one unit of the source currency. */
6
6
  export declare const CallCurrencyConvert: (from: string, to: string) => number;
@@ -20,8 +20,13 @@ function requestText(url, label, body) {
20
20
  }
21
21
  /** Render an inline Handlebars template using the hosted HBS service. */
22
22
  function CallHbs(template, data, multi = false) {
23
- if (typeof template !== 'string' || data === undefined) {
24
- throw new Error('Invalid input: template must be a string and data is required');
23
+ if (typeof template !== 'string') {
24
+ throw new Error('Invalid input: template must be a string');
25
+ }
26
+ // With no data, no request is made: return the template unchanged,
27
+ // or a single-item array when rendering in multi mode.
28
+ if (data === null || data === undefined) {
29
+ return multi ? [template] : template;
25
30
  }
26
31
  const isObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
27
32
  if (!(Array.isArray(data) ? data.every(isObject) : isObject(data))) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dff-util",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {