11// Complete JavaScript Pattern Reference
22//
33// Every JS pattern the compiler maps to ASL, in one place.
4+ // The TypeScript source is identical regardless of backend —
5+ // only the ASL output differs.
46//
5- // See also 34-37 for JSONata-only methods (string, math, array,
6- // and higher-order functions like map/filter/reduce).
7+ // JSONata mode (default):
8+ // a + b (numbers) → native JSONata addition
9+ // a - 5 → native JSONata subtraction
10+ // a * b, a / b, a % b → native JSONata operators (JSONata only)
11+ // `${a} text ${b}` → JSONata & concatenation
12+ // str.split(delim) → $split(str, delim)
13+ // JSON.parse(str) → $eval(str)
14+ // JSON.stringify(obj) → $string(obj)
15+ // arr.includes(val) → val in arr
16+ // arr.length → $count(arr)
17+ // Steps.uuid() → States.UUID() (intrinsic in both)
718//
8- // Mapping table :
19+ // JSONPath mode (--query-language jsonpath) :
920// a + b (numbers) → States.MathAdd(a, b)
1021// a - 5 (literal right) → States.MathAdd(a, -5)
1122// `${a} text ${b}` → States.Format('{} text {}', a, b)
1526// arr.includes(val) → States.ArrayContains(arr, val)
1627// arr.length → States.ArrayLength(arr)
1728// Steps.uuid() → States.UUID()
29+ //
30+ // See also 34-37 for JSONata-only methods (string, math, array,
31+ // and higher-order functions like map/filter/reduce).
1832
1933import { Steps , SimpleStepContext } from '../../packages/core/src/runtime/index' ;
2034
@@ -23,31 +37,31 @@ export const jsPatterns = Steps.createFunction(
2337 items : string [ ] ; csv : string ; data : string ;
2438 price : number ; tax : number ; name : string
2539 } ) => {
26- // Arithmetic: + → States.MathAdd
40+ // Arithmetic: JSONata: native +, JSONPath: States.MathAdd
2741 const total = input . price + input . tax ;
2842
29- // Subtraction: - literal → States.MathAdd(a, -literal)
43+ // Subtraction: JSONata: native -, JSONPath: States.MathAdd(a, -literal)
3044 const discounted = input . price - 5 ;
3145
32- // Template literals → States.Format
46+ // Template literals: JSONata: & concat, JSONPath: States.Format
3347 const message = `Hello ${ input . name } , your total is ${ total } ` ;
3448
35- // String split → States.StringSplit
49+ // String split: JSONata: $split(), JSONPath: States.StringSplit
3650 const parts = input . csv . split ( ',' ) ;
3751
38- // JSON.parse → States.StringToJson
52+ // JSON.parse: JSONata: $eval(), JSONPath: States.StringToJson
3953 const parsed = JSON . parse ( input . data ) ;
4054
41- // JSON.stringify → States.JsonToString
55+ // JSON.stringify: JSONata: $string(), JSONPath: States.JsonToString
4256 const serialized = JSON . stringify ( parsed ) ;
4357
44- // Array includes → States.ArrayContains
58+ // Array includes: JSONata: `in` operator, JSONPath: States.ArrayContains
4559 const hasItem = input . items . includes ( 'special' ) ;
4660
47- // Array length → States.ArrayLength
61+ // Array length: JSONata: $count(), JSONPath: States.ArrayLength
4862 const count = input . items . length ;
4963
50- // Steps.uuid → States.UUID
64+ // Steps.uuid: States.UUID() in both backends
5165 const id = Steps . uuid ( ) ;
5266
5367 return { total, discounted, message, parts, parsed, serialized, hasItem, count, id } ;
0 commit comments