Interface MigascTemplateOptions

Hierarchy

  • MigascTemplateOptions

Properties

dict404?: string

The replacement value for template matches with no dictionary reference.

Default Value

''

Example

import MigascTemplate from 'migasc-template';

const mt = new MigascTemplate(
// MigascTemplate Options
{ dict404: '__NOT_FOUND__' },
// MigascTemplate Dictionary
{
adjective: 'mysterious',
animal: 'Cats',
}
);

const template = '{{animal}} are a {{adjective}} kind of folk - {{author}}';

mt.compile(template);
// -> Cats are a mysterious kind of folk - __NOT_FOUND__
doAllowEscapeChar?: boolean

Allow 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.

Default Value

false

Example

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.
doAllowWhitespace?: boolean

Allow 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.

Default Value

false

Example

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
maxChars?: number

Set the maximum number of valid characters.

Default Value

64

Example

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
maxWhitespace?: number

Set the maximum number of valid whitespace characters between the opening/closing tags and the template content. This is disregarded when doAllowWhiteSpace is false.

Default Value

64

Example

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 }}
tags?: {
    close?: string;
    open?: string;
}

Define tags configuration.

Type declaration

  • Optional close?: string

    Define characters to use as opening tags.

    Default Value

    '}}'

  • Optional open?: string

    Define characters to use as closing tags.

    Default Value

    '{{'

validChars?: string

Define valid characters and/or character ranges (e.g. 'a-z').

Default Value

'a-zA-Z0-9_-'

Example

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