Tagscript

IntegerTransformer

Integer transformer transforms an integer based on the given parameters.

If no parameters are given, the integer will be returned as is. If ++ parameter is given, the integer will be incremented. If -- parameter is given, the integer will be decremented.

Usage

import { Interpreter, IntegerTransformer, StrictVarsParser } from 'tagscript';
const ts = new Interpreter(new StrictVarsParser());
const { Interpreter, IntegerTransformer, StrictVarsParser } = require('tagscript');
const ts = new Interpreter(new StrictVarsParser());

API

Check IntegerTransformer for the API documentation.

For End Users

Syntax

{variable}
{variable(++)}
{variable(--)}

Examples

# Basic usage - returns the integer as string
{count}
# 5
# Increment the integer
{count(++)}
# 6 (if count was initially 5)
# Decrement the integer
{count(--)}
# 4 (if count was initially 5)
# Practical example with counter
Current count: {counter}
Incremented: {counter(++)}
Decremented: {counter(--)}
# Current count: 10
# Incremented: 11
# Decremented: 10

Notes

  • The transformer modifies the internal integer value when using ++ or --
  • Multiple calls to {variable(++)} will continue incrementing the value
  • The integer value persists for the lifetime of the transformer instance
  • Input must be a valid integer string or number
You need to use StrictVarsParser parser to use this transformer.

Last updated on