From 1087b33ed6da77d910b226b8ffbefdce712a8f62 Mon Sep 17 00:00:00 2001 From: bryce <50299051+bryce-seifert@users.noreply.github.com> Date: Sat, 8 Jul 2023 15:57:31 -0500 Subject: [PATCH] feat: add additional string expressions (#2517) --- .../expressions/functions.md | 20 +++++++++++++++++++ lib/Shared/Expression/ExpressionFunctions.js | 12 +++++++++++ 2 files changed, 32 insertions(+) diff --git a/docs/4_secondary_admin_controls/expressions/functions.md b/docs/4_secondary_admin_controls/expressions/functions.md index 059f4d8ea4..c42a001f34 100644 --- a/docs/4_secondary_admin_controls/expressions/functions.md +++ b/docs/4_secondary_admin_controls/expressions/functions.md @@ -86,6 +86,26 @@ substr() extracts characters from indexStart up to but not including indexEnd. Tip: If you don't want the behaviour of negative numbers, you can use `max(0, index)` to limit the value to never be below 0. +**includes(val, find)** + +Check if a string contains a specific value + +eg `includes("Companion is great!", "great")` gives `true` + +**toUpperCase(val)** + +Coverts all characters in a string to uppercase + +**toLowerCase(val)** + +Coverts all characters in a string to lowercase + +**replaceAll(val, find, replace)** + +Searches a string for a specific value, and then replaces all instances of that value with a new string + +eg `replaceAll("This is great!", "This", "Companion")` gives `Companion is great!` + **secondsToTimestamp(seconds, format)** Convert a number of seconds into a timestamp of format 'HH:mm:ss'. diff --git a/lib/Shared/Expression/ExpressionFunctions.js b/lib/Shared/Expression/ExpressionFunctions.js index 39b50b04bc..94be566124 100644 --- a/lib/Shared/Expression/ExpressionFunctions.js +++ b/lib/Shared/Expression/ExpressionFunctions.js @@ -38,6 +38,18 @@ export const ExpressionFunctions = { substr: (str, start, end) => { return (str + '').slice(start, end) }, + includes: (str, arg) => { + return (str + '').includes(arg) + }, + toUpperCase: (str) => { + return (str + '').toUpperCase() + }, + toLowerCase: (str) => { + return (str + '').toLowerCase() + }, + replaceAll: (str, find, replace) => { + return (str + '').replaceAll(find, replace) + }, secondsToTimestamp: (v, type) => { v = Math.max(0, v)