Object path - misonou/waterpipe GitHub Wiki
The basic construct consist of an object path in a double-braced expression {{path}}
where path is basically Javascript's dot notation (.) except that array indices are also accepted.
Consider the following input object:
{ zero: 0, string: "foo", array: [1, 2, 3, 4] }The following object path will be interpolated as:
{{string}} ➜ foo
{{array}} ➜ [1,2,3,4]
{{array.0}} ➜ 1
{{array.length}} ➜ 4
In addition, any parts of the object path can be itself evaluated by a preceding dollar sign ($).
{{array.$zero}} = {{array.0}} ➜ 1
{{array.$(array.0)}} = {{array.1}} ➜ 2
When interpolating, it is short-circuited if at any step it evaluates to undefined or null.
It is commonly equivalent to the ?. operator by other languages or template engines:
{{blah}} ➜
{{array.foo.bar}} ➜
Invalid path has a stricter sense then nonexistent path that, the first part of the object path does not exist as a property on all visible objects in the interpolation context.
Referencing the example in the previous section, {{array.foo.bar}} is a nonexistent path,
while {{blah}} is an invalid path.
Special handling is done on invalid path when executing the pipe. See Pipe for more information.
Waterpipe supports declaring global variables. See Global variables for more details.
// the following returns the string "foobar"
// even though `myGlobal` is not found on the input data object
waterpipe('{{myGlobal}}', { /* no properties */ }, {
globals: {
myGlobal: 'foobar'
}
});