Skip to content

Commit 2925a4e

Browse files
committed
feat(kleros-sdk): predefined-lambdas-for-mustache
1 parent 0b75799 commit 2925a4e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export const lambdas = {
2+
// Converts a value to hex representation
3+
hex: function () {
4+
return function (text: string, render: Function) {
5+
const originalValueStr = render(text);
6+
const num = parseInt(originalValueStr, 10);
7+
if (!isNaN(num)) {
8+
return "0x" + num.toString(16).toLowerCase();
9+
}
10+
return originalValueStr;
11+
};
12+
},
13+
};

kleros-sdk/src/dataMappings/utils/populateTemplate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import mustache from "mustache";
22
import { DisputeDetails } from "./disputeDetailsTypes";
33
import DisputeDetailsSchema, { RefuseToArbitrateAnswer } from "./disputeDetailsSchema";
4+
import { lambdas } from "./lambdas";
45

56
export const populateTemplate = (mustacheTemplate: string, data: any): DisputeDetails => {
6-
const render = mustache.render(mustacheTemplate, data);
7+
const render = mustache.render(mustacheTemplate, { ...data, ...lambdas });
78
const dispute = JSON.parse(render);
89

910
const validation = DisputeDetailsSchema.safeParse(dispute);

0 commit comments

Comments
 (0)