RGJS6 Templer module.
Methods
-
<static> get(template, data)
-
Generate a filled out template.
Example data object: {a: 0, b: false, c: null, x: 0, y: '1', z: {u: 'string', v: 'alert('oi');'}, w: '<tag attr='1'>'}
SIMPLE EXAMPLES
Normal usage: {a} = '0'.
Deep usage: {z.u} = 'string'.
Fallback usage: {a||fallback} {b||fallback} {c||fallback} = '0' 'fallback'.'fallback'
If usage: {a?true:false} {b?true:false} {b?true:false} = 'true' 'false' 'false'.
ADVANCED EXAMPLES -
Nested fallback: {a||{b}} = '0' (or 'false').
Nested if: {b?{a}:{c}} = 'null' (or '0').
FUNCTIONS EXAMPLES
Cast integer: {(int)y} = 1 (not '1').
Eval string: {(eval}z.v} = eval('alert('oi');').
Escape html: {(escHtml)z.w} = '<tag attr='1'>'.
Escape html attr: {(escAttr)z.w} = '<tag attr="e;1"e;>'.
MORE FEATURES
Values are trimmed using .trim(). To allow a value with newlines, spaces, etc, double-escape them like '\n', '\ '.Parameters:
Name Type Description template
string The template to be filled out.
data
object The data to use to fill out the template.
Returns:
A filled out template.
- Type
- string
Example
const template = 'Hello my name is {name}. I'm a {profession}.'; const values = {name: 'John', profession: 'doctor'}; rgjs.templer.get(template, values) // 'Hello my name is John. I'm a doctor.'