2.4.0 • Published 3 years ago

@rg-3/rstl.js v2.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

rstl.js

Table of contents

  1. Introduction
  2. Examples
  3. Install
  4. 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.

2.4.0

3 years ago

2.3.8

4 years ago

2.3.7

4 years ago

2.3.6

4 years ago

2.3.4

4 years ago

2.3.3

4 years ago

2.3.5

4 years ago

2.3.2

4 years ago

2.3.1

4 years ago

2.3.0

4 years ago

2.2.0

4 years ago

2.1.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago