TransInterpolator
Combines
- Variable transposition ( via Transposer )
- Recursive string interpolation
; const interp = some: "!data!": '5000' ; interp;// returns "Total: 5000."
It's also rescursive.
const interp = price: 5000 expressions: a: '${price}' // 5000 b: '${expressions.a} * 1.5 / 2' // 3750 c: '${expressions.b} - ${getOne}' // 3749 "( ${price} - ${price} ) + 1"; interp;// returns "Computed to: 3749"
It can be configured in two ways:
; data: 1 open: "!!!" close: "^^^" { return ` :D :D `; };
or
; open = "<%" close = "%>" depth = 8; const transInterp = {}
API
TransInterpolator([data], [[options]])
class data
- The data to pull in; can contain expressions of itself.
- When an expression resolves to a function, it will be treated just like a
transform
function.
options
depth = 8
Limit the recursion depth.open = "${"
The open tagclose = "}"
The end tagtransform(value, unresolved, expression) {}
.interpolate([expression], [[transform]])
method expression {String}
transform(value, unresolved, expression) { return value; }
- Called when either no open tags are found or when the depth limit is met