-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20-string-interpolation.ts
More file actions
33 lines (27 loc) · 1.28 KB
/
Copy path20-string-interpolation.ts
File metadata and controls
33 lines (27 loc) · 1.28 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
// String Interpolation with Template Literals
//
// Write natural template strings — the compiler maps them to the
// appropriate ASL representation for your chosen query language.
//
// JSONata mode (default):
// `Hello ${name}` → "Hello " & $name
// `${a} and ${b}` → $a & " and " & $b
// `Total: ${a + b}` → "Total: " & ($a + $b)
//
// JSONPath mode (--query-language jsonpath):
// `Hello ${name}` → States.Format('Hello {}', name)
// `${a} and ${b}` → States.Format('{} and {}', a, b)
// `Total: ${a + b}` → States.Format('Total: {}', States.MathAdd(a, b))
import { Steps, SimpleStepContext } from '../../packages/core/src/runtime/index';
export const stringInterpolation = Steps.createFunction(
async (context: SimpleStepContext, input: { name: string; orderId: string; price: number; tax: number }) => {
const total = input.price + input.tax;
// Simple interpolation
const greeting = `Hello, ${input.name}!`;
// Multiple substitutions
const summary = `Order ${input.orderId}: $${total} (including tax)`;
// Nested expressions in template
const receipt = `Receipt for ${input.name} — Order #${input.orderId}, Total: $${Steps.add(input.price, input.tax)}`;
return { greeting, summary, receipt };
},
);