Fork
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const functionMap = {
// Basic Arithmetic Operations, with checks for type as numbers
"add": (a, b) => typeof a === "number" && typeof b === "number" ? a + b : null,
"subtract": (a, b) => typeof a === "number" && typeof b === "number" ? a - b : null,
"multiply": (a, b) => typeof a === "number" && typeof b === "number" ? a * b : null,
"mod": (a, b) => typeof a === "number" && typeof b === "number" ? a % b : null,
"pow": (a, b) => typeof a === "number" && typeof b === "number" ? Math.pow(a, b) : null,
"divide": (a, b) => (typeof a === "number" && typeof b === "number" && b !== 0) ? a / b : null,
// Comparison Operations, with checks for type as numbers
"equal": (a, b) => typeof a === "number" && typeof b === "number" ? a === b : null,
"notequal": (a, b) => typeof a === "number" && typeof b === "number" ? a !== b : null,
"greaterthan": (a, b) => typeof a === "number" && typeof b === "number" ? a > b : null,
"lessthan": (a, b) => typeof a === "number" && typeof b === "number" ? a < b : null,
"greaterthanorequal": (a, b) => typeof a === "number" && typeof b === "number" ? a >= b : null,
"lessthanorequal": (a, b) => typeof a === "number" && typeof b === "number" ? a <= b : null,
// Logical Operations, with checks
"and": (a, b, c) => typeof a === "boolean" && typeof b === "string" && typeof c === "string" ? a ? b : c : null,
"or": (a, b) => typeof a === "boolean" && typeof b === "boolean" ? a || b : null,
"not": (a) => typeof a === "boolean" ? !a : null,
"xor": (a, b) => typeof a === "boolean" && typeof b === "boolean" ? a !== b : null,
"nand": (a, b) => typeof a === "boolean" && typeof b === "boolean" ? !(a && b) : null,
"nor": (a, b) => typeof a === "boolean" && typeof b === "boolean" ? !(a || b) : null,
"xnor": (a, b) => typeof a === "boolean" && typeof b === "boolean" ? a === b : null,
// Boolean Values
// true receives a boolean, b is if true, c is if false
"true": (a, b, c) => typeof a === "boolean" && typeof b === "string" && typeof c === "string" ? a ? b : c : null,
"false": (a, b, c) => typeof a === "boolean" && typeof b === "string" && typeof c === "string" ? a ? c : b : null,
// String and Array Operations with checks
"contains": (a, b) => typeof a === "string" || typeof a === "number" || Array.isArray(a) ? a.includes(b) : null,
"length": (a) => typeof a === "string" || typeof a === "number" || Array.isArray(a) ? a.length : null,
"empty": (a) => typeof a === "string" || typeof a === "number" || Array.isArray(a) ? a === "" : null,
"test": (a, b) => typeof a === "string" ? b.includes(a) : null,
"match": (a, b) => typeof a === "string" ? a.match(b) : null,
"replace": (a, b, c) => typeof a === "string" ? a.replace(b, c) : null,
"replaceAll": (a, b, c) => typeof a === "string" ? a.replaceAll(b, c) : null,
"lowercase": (a) => typeof a === "string" ? a.toLowerCase() : null,
"uppercase": (a) => typeof a === "string" ? a.toUpperCase() : null,
"repeat": (a, b) => typeof a === "string" ? a.repeat(b) : null,
"stripformatting": (a) => typeof a === "string" ? a.replace(/<[^>]*>/g, "") : null,
"min": (a) => Array.isArray(a) ? Math.min(...a) : null,
"max": (a) => Array.isArray(a) ? Math.max(...a) : null,
"absolute": (a) => typeof a === "number" ? Math.abs(a) : null,
"round": (a) => typeof a === "number" ? Math.round(a) : null,
"ceiling": (a) => typeof a === "number" ? Math.ceil(a) : null,
"floor": (a) => typeof a === "number" ? Math.floor(a) : null,
"squareroot": (a) => typeof a === "number" ? Math.sqrt(a) : null,
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.
Comments
stevekrouse avatar

So cool! What is this for? I'd love to see a readme with some demos :)