@codeandmoney/jargal 0.0.0-rc.4 → 0.0.0-rc.6

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/jargal.ts CHANGED
@@ -42,11 +42,11 @@ export class Jargal<const in out Context> {
42
42
  return this as any;
43
43
  }
44
44
 
45
- render(params?: {
46
- composeRenderData?: (ctx: Context) => RenderEntry[];
45
+ async render(params?: {
46
+ composeRenderData?: (ctx: Context) => RenderEntry[] | Promise<RenderEntry[]>;
47
47
  scope?: Context extends { templates: { [key: string]: any } } ? keyof Context["templates"] : "default";
48
- }): Jargal<Context & { renderedContent: { savePath: string; content: string }[] }> {
49
- const composeData: (ctx: Context) => RenderEntry[] =
48
+ }): Promise<Jargal<Context & { renderedContent: { savePath: string; content: string }[] }>> {
49
+ const composeData: (ctx: Context) => RenderEntry[] | Promise<RenderEntry[]> =
50
50
  params?.composeRenderData ??
51
51
  // @ts-expect-error
52
52
  ((ctx: Context) => ctx.renderData);
@@ -54,7 +54,7 @@ export class Jargal<const in out Context> {
54
54
  // @ts-expect-error
55
55
  const templatesToRender = this.#context.templates[params?.scope ?? "default"] as TemplatesMap;
56
56
 
57
- const composedData = composeData(this.#context);
57
+ const composedData = await composeData(this.#context);
58
58
 
59
59
  for (const renderEntry of composedData) {
60
60
  if (!renderEntry.control || renderEntry.control === "auto") {
package/lib.ts CHANGED
@@ -89,3 +89,13 @@ class ReadOnlyProxyWriteError extends Error {
89
89
  export function readonly<T extends object>(target: T) {
90
90
  return new Proxy<T>(target, ReadOnlyProxyDescriptor);
91
91
  }
92
+
93
+ export const utilHelpers = {
94
+ isdefined: function (value: unknown) {
95
+ return value !== undefined;
96
+ },
97
+
98
+ is: function (left: unknown, right: unknown) {
99
+ return left === right;
100
+ },
101
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeandmoney/jargal",
3
- "version": "0.0.0-rc.4",
3
+ "version": "0.0.0-rc.6",
4
4
  "description": "Renderer",
5
5
  "license": "MIT",
6
6
  "author": "Code & Money Team",
package/renderer.ts CHANGED
@@ -2,11 +2,11 @@ import { get, set } from "es-toolkit/compat";
2
2
  import handlebars from "handlebars";
3
3
 
4
4
  import type { GetReturnType, HelperFn, Helpers, MappingScope, Partials, SetOptions, Setter, SetterScope } from "./types.ts";
5
- import { readonly, textHelpers } from "./lib.ts";
5
+ import { readonly, textHelpers, utilHelpers } from "./lib.ts";
6
6
 
7
7
  export class Renderer {
8
8
  #partials: Partials = {};
9
- #helpers: Helpers = textHelpers;
9
+ #helpers: Helpers = { ...textHelpers, ...utilHelpers };
10
10
 
11
11
  #mapping: { partial: Partials; helper: Helpers } = {
12
12
  partial: this.#partials,