JSTT - JavaScript Text Templates
Installation
$ npm i jtt# or $ yarn add jstt
First Template
const jstt = ; const html = jstt; console;
Using JavaScript
const jstt = ; const html = jstt; console;
Delimiters
Delimiter | Description |
---|---|
<? or <! | Starts a JavaScript code block |
<?= or <!= | Prints an expression as text |
<?- or <!- | Prints an expression as html |
?> or ?> | Ends a JavaScript code block |
<# | Starts a comment block |
#> | Ends a comment block |
Special delimiters
Delimiters that contain "!" they must ignore spaces and line breaks for better readability.
<! for (let i = 0; i < 5; i++) { !>
<h1><!= i !><h1>
<! } !>
is the same as:
<? for (let i = 0; i < 5; i++) { ?><h1><?= i !><h1><? } !>
Pre-parse
If you need to render the same template for a lot of data, you can use the parse function and use its return several times.
const jstt = ; const tableTemplate = jstt; const usersTable = tableTemplate; const todoTable = tableTemplate; consoleconsole
Benchmark
Run npm run benchmark
or yarn benchmark
EJS x 1,614 ops/sec ±1.56% (86 runs sampled)
JSTT x 3,460 ops/sec ±1.60% (89 runs sampled)
Fastest is JSTT