TypeDoc API
TagScript
classes
Stringtransformer

Class: StringTransformer

String transformer transforms a string based on the given parameters.

If no parameters are given, the string will be returned as is. If an integer parameter is given, the string will be splitted into an array of strings using payload or space as a separator. And will return the element at the given index (integer parameter).

Use a + before the index to reference every element up to and including the index value.

Use a + after the index to reference the index value and every element after it.

Remarks

You need to use StrictVarsParser parser to use this transformer.

Example

import { Interpreter, StringTransformer, StrictVarsParser } from 'tagscript';
 
const ts = new Interpreter(new StrictVarsParser());
 
await ts.run('{args}', { args: new StringTransformer('Hi, How are you?') });
// Hi, How are you?
 
await ts.run('{args(0)}', { args: new StringTransformer('Hi, How are you?') });
// Hi,
 
await ts.run('{args(1)}', { args: new StringTransformer('Hi, How are you?') });
// How
 
await ts.run('{args(2+)}', { args: new StringTransformer('Hi, How are you?') });
// How are you?
 
await ts.run('{args(+2)}', { args: new StringTransformer('Hi Vox, How are you?') });
// Hi Vox,

Implements

Constructors

constructor

new StringTransformer(str, escape?)

Parameters

NameTypeDefault valueDescription
strstringundefinedThe string to transform.
escapebooleanfalseIf true, the string will be escaped.

Properties

escape

Private Readonly escape: boolean


str

Private Readonly str: string

Methods

handleContext

Private handleContext(tag): string

Parameters

NameType
tagLexer

Returns

string


returnValue

Private returnValue(str): string

Parameters

NameType
strstring

Returns

string


transform

transform(tag): string

Transforms the given tag.

Parameters

NameTypeDescription
tagLexerThe tag that triggered the transformer.

Returns

string

Implementation of

ITransformer.transform