Skip to content

Commit

Permalink
feat: add more expression functions #2515 #2528
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Aug 8, 2023
1 parent 2cfa2b7 commit 36b4a3e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/4_secondary_admin_controls/expressions/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ eg `00:10:15` gives 615

You can do the reverse of this with `secondsToTimestamp(str)`

**randomInt(min, max)**

Generate a random integer in the specified range (inclusive).

##### String operations

**trim(val)**
Expand All @@ -86,12 +90,29 @@ 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.

**concat(str1, str2)**

Combine one or more values into a single string

**includes(val, find)**

Check if a string contains a specific value

eg `includes("Companion is great!", "great")` gives `true`

**indexOf(val, find, offset)**

Find the index of the first occurence of a value within the provided string.

Optionally provide an offset to start the search from.


**lastIndexOf(val, find, offset)**

Find the index of the last occurence of a value within the provided string.

Optionally provide an offset to start the search from.

**toUpperCase(val)**

Coverts all characters in a string to uppercase
Expand Down
12 changes: 12 additions & 0 deletions lib/Shared/Expression/ExpressionFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,28 @@ export const ExpressionFunctions = {
return 0
}
},
randomInt: (min = 0, max = 10) => {
min = Number(min)
max = Number(max)
return min + Math.round(Math.random() * (max - min))
},

// String operations
trim: (v) => (v + '').trim(),
strlen: (v) => (v + '').length,
substr: (str, start, end) => {
return (str + '').slice(start, end)
},
concat: (...strs) => ''.concat(...strs),
includes: (str, arg) => {
return (str + '').includes(arg)
},
indexOf: (str, arg, offset) => {
return (str + '').indexOf(arg, offset)
},
lastIndexOf: (str, arg, offset) => {
return (str + '').lastIndexOf(arg, offset)
},
toUpperCase: (str) => {
return (str + '').toUpperCase()
},
Expand Down

0 comments on commit 36b4a3e

Please sign in to comment.