A tagged template function that renders a text string including the deep values of trees. See also Tree.indent
, which normalizes whitespace indentation.
As discussed in template expressions, Origami template strings can directly include the contents of arrays, objects, or trees. JavaScript template literals do not provide useful results for such objects:
// JavaScript
`Hello, ${ { name: 'Alice' } }.`; // "Hello, [object Object]."
Origami provides more useful results for such complex values through the Tree.text
template literal. This is implicitly used for all template literals in Origami expressions, so it’s use is optional. Both of these produce the same result:
// Origami
`Hello, ${ { name: 'Alice' } }.` // "Hello, Alice."
Tree.text`Hello, ${ { name: 'Alice' } }.` // "Hello, Alice."
Calling from JavaScript #
The Tree.text
builtin is provided so that JavaScript programs can use it to render trees the same way Origami does.
import { Tree } from "@weborigami/async-tree";
const object = {
Alice: "Hello, Alice!",
Bob: "Hello, Bob!",
Carol: "Hello, Carol!",
};
export default await Tree.text`${object}`;
Since text
is a tagged template function, it is followed immediately by a backtick instead of an opening parenthesis. Also note the use of await
, since text
is an asynchronous function.
The above module exports this string:
Hello, Alice!Hello, Bob!Hello, Carol!