@rg-3/rstl.js v2.4.0
rstl.js
Table of contents
- Introduction
- Examples
- Install
- License
Introduction
rstl.js is a Really Simple Template Language implemented as a simple function.
Examples
#1
This example replaces Hello, {{planet}}
with Hello, Earth
by
substituting the variable name with the Earth
value.
import rstl from 'rstl.js';
rstl('Hello, {{planet}}', {planet: 'Earth'}); // => "Hello, Earth"
#2
It's possible for a function to be passed as a variable's value. It will be called by rstl and its return value inserted in place of the variable name:
import rstl from 'rstl.js';
rstl('Hello, {{planet}}', {planet: () => 'Earth'}); // => "Hello, Earth"
#3
By default rstl will escape HTML entities from a variable's value, but it can
be disabled by providing the escapeHTML
option:
import rstl from 'rstl.js';
rstl('Hello, {{planet}}', {planet: '<b>Earth</b>'}, {escapeHTML: false}); // => "Hello, <b>Earth</b>"
Limitations
A variable name can use the characters a-z, A-Z, and 0-9. If other characters are used an error will be thrown.
Install
NPM
If you're in an NPM environment there's an NPM package to use.
The package should be required or imported as @rg-3/rstl.js
.
# npm users
$ npm i --save @rg-3/rstl.js
# yarn users
$ yarn add @rg-3/rstl.js
Old school method
If you're in a browser environment that's not using NPM, save
dist/rstl.min.js
to your project and link to it from a <script>
tag. It has been trans-piled
to ES5, and adds window.rstl
.
License
MIT license. See ./LICENSE.txt.