From e73d6d4e1c68d278397c2c9d812004b6da971d5b Mon Sep 17 00:00:00 2001 From: metal Date: Sat, 4 Sep 2021 17:14:33 +0100 Subject: [PATCH] Add template functions: strlen, round (#265) --- backend/src/templateFormatter.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/src/templateFormatter.ts b/backend/src/templateFormatter.ts index 7b61af1e..2ed902d9 100644 --- a/backend/src/templateFormatter.ts +++ b/backend/src/templateFormatter.ts @@ -388,6 +388,10 @@ const baseValues = { ucfirst(arg) { return baseValues.upperFirst(arg); }, + strlen(arg) { + if (typeof arg !== "string") return 0; + return [...arg].length; + }, rand(from, to, seed = null) { if (isNaN(from)) return 0; @@ -406,6 +410,10 @@ const baseValues = { return Math.round(randValue * (to - from) + from); }, + round(arg, decimals = 0) { + if (isNaN(arg)) return 0; + return decimals === 0 ? Math.round(arg) : arg.toFixed(decimals); + }, add(...args) { return args.reduce((result, arg) => { if (isNaN(arg)) return result;