forked from msironi/expr-eval
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexamples.js
More file actions
107 lines (107 loc) · 3.6 KB
/
Copy pathexamples.js
File metadata and controls
107 lines (107 loc) · 3.6 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Example cases for the language service sample
const exampleCases = [
{
id: 'math',
title: 'Mathematical Expression',
description: 'Basic math operations with variables',
expression: '(x + y) * multiplier + sqrt(16)',
context: {
x: 10,
y: 5,
multiplier: 3
}
},
{
id: 'arrays',
title: 'Working with Arrays',
description: 'Array functions like sum, min, max',
expression: 'sum(numbers) + max(numbers) - min(numbers)',
context: {
numbers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
values: [15, 25, 35]
}
},
{
id: 'objects',
title: 'Object Manipulation',
description: 'Access nested object properties',
expression: 'user.profile.score * level.multiplier + bonus.points',
context: {
user: {
name: "Alice",
profile: {
score: 85,
rank: "Gold"
}
},
level: {
current: 5,
multiplier: 1.5
},
bonus: {
points: 100,
active: true
}
}
},
{
id: 'map-filter',
title: 'Map and Filter Functions',
description: 'Transform and filter data with callbacks',
expression: 'sum(\n map(\n f(x) = x * 2, \n filter(\n f(i) = i > threshold, \n items\n )\n )\n) / length(items)',
context: {
items: [1, 2, 3, 4, 5, 6, 7, 8],
threshold: 3
}
},
{
id: 'complex',
title: 'Complex Objects',
description: 'Work with deeply nested data structures',
expression: 'length(company.departments[0].employees) * company.settings.bonusRate + sum(map(f(d) = d.budget, company.departments))',
context: {
company: {
name: "TechCorp",
departments: [
{
name: "Engineering",
budget: 500000,
employees: ["John", "Jane", "Bob"]
},
{
name: "Marketing",
budget: 200000,
employees: ["Alice", "Carol"]
}
],
settings: {
bonusRate: 0.15,
fiscalYear: 2024
}
}
}
},
{
id: 'data-transform',
title: 'Data Transformation',
description: 'Flatten nested objects and transform rows',
expression: "map(f(row) = {_id: row.rowId} + flatten(row.data, ''), $event)",
context: {
"$event": [
{"rowId": 1, "state": "saved", "data": { "InventoryId": 1256, "Description": "Bal", "Weight": { "Unit": "g", "Amount": 120 } }},
{"rowId": 2, "state": "new", "data": { "InventoryId": 2344, "Description": "Basket", "Weight": { "Unit": "g", "Amount": 300 } }},
{"rowId": 3, "state": "unchanged", "data": { "InventoryId": 9362, "Description": "Wood", "Weight": { "Unit": "kg", "Amount": 18 } }}
]
}
},
{
id: 'diagnostics-demo',
title: 'Diagnostics Demo',
description: 'Shows error highlighting for incorrect function arguments',
expression: '// Try functions with wrong argument counts:\n// pow() needs 2 args, random() needs 0-1 args\npow(2) + random(1, 2, 3)',
context: {
x: 5,
y: 10
}
}
];