Optional
dict404Optional
doAllow escape character '!'
before the opening tag to escape tags.
Do not allow for better performance.
Note: If possible, it is advised to change options.tags
opposed to enabling this option.
false
import MigascTemplate from 'migasc-template';
const mt = new MigascTemplate(
// MigascTemplate Options
{ doAllowEscapeChar: true },
// MigascTemplate Dictionary
{
adjective: 'mysterious',
animal: 'Cats',
author: 'Sir Walter Scott',
date: new Date().toDateString(),
}
);
const template =
'{{animal}} are a {{adjective}} kind of folk - {{author}} : !{{date}} -> {{date}}.';
mt.compile(template);
// -> Cats are a mysterious kind of folk - Sir Walter Scott : {{date}} -> Sat Feb 18 2023.
Optional
doAllow whitespace between the opening/closing tags and the template content.
options.maxWhitespace
value is only relevent if options.doAllowWhitespace
is true.
Do not allow for better performance.
false
import MigascTemplate from 'migasc-template';
const mt = new MigascTemplate(
// MigascTemplate Options
{ doAllowWhitespace: true },
// MigascTemplate Dictionary
{
adjective: 'mysterious',
animal: 'Cats',
author: 'Sir Walter Scott',
}
);
const template = '{{ animal }} are a {{ adjective }} kind of folk - {{ author }}';
mt.compile(template);
// -> Cats are a mysterious kind of folk - Sir Walter Scott
Optional
maxSet the maximum number of valid characters.
64
import MigascTemplate from 'migasc-template';
const mt = new MigascTemplate(
// MigascTemplate Options
{ maxChars: 6 },
// MigascTemplate Dictionary
{
adjective: 'mysterious',
animal: 'Cats',
author: 'Sir Walter Scott',
}
);
const template = '{{animal}} are a {{adjective}} kind of folk - {{author}}';
mt.compile(template);
// -> Cats are a {{adjective}} kind of folk - Sir Walter Scott
Optional
maxSet the maximum number of valid whitespace characters between the opening/closing tags and the template content.
This is disregarded when doAllowWhiteSpace
is false
.
64
import MigascTemplate from 'migasc-template';
const mt = new MigascTemplate(
// MigascTemplate Options
{
doAllowWhitespace: true,
maxWhitespace: 1,
},
// MigascTemplate Dictionary
{
adjective: 'mysterious',
animal: 'Cats',
author: 'Sir Walter Scott',
}
);
const template = '{{ animal }} are a {{ adjective }} kind of folk - {{ author }}';
mt.compile(template);
// -> Cats are a mysterious kind of folk - {{ author }}
Optional
tagsDefine tags configuration.
Optional
close?: stringDefine characters to use as opening tags.
'}}'
Optional
open?: stringDefine characters to use as closing tags.
'{{'
Optional
validDefine valid characters and/or character ranges (e.g. 'a-z'
).
'a-zA-Z0-9_-'
import MigascTemplate from 'migasc-template';
const mt = new MigascTemplate(
// MigascTemplate Options
{ validChars: 'a-z' },
// MigascTemplate Dictionary
{
adjective: 'mysterious',
animal: 'Cats',
author: 'Sir Walter Scott',
}
);
const template = '{{animal}} are a {{ADJECTIVE}} kind of folk - {{author}}';
mt.compile(template);
// -> Cats are a {{ADJECTIVE}} kind of folk - Sir Walter Scott
The replacement value for template matches with no dictionary reference.
Default Value
''
Example