SliceParser
The slice tag takes a string and returns a substring of it based on the provided start and end indices. This parser is useful for extracting portions of text or limiting string length.
Usage
import { Interpreter, SliceParser } from 'tagscript';
const ts = new Interpreter(new SliceParser());
const { Interpreter, SliceParser } = require('tagscript');
const ts = new Interpreter(new SliceParser());
API
Check SliceParser for the API documentation.
For End Users
Syntax
{slice(start):text}
{slice(start-end):text}
{slice(start,end):text}
Examples
{slice(3):Hello World}
# lo World
{slice(0-5):Hello World}
# Hello
{slice(6,11):Hello World}
# World
{slice(0-3):Welcome to our server!}
# Wel
{slice(-5):Hello World}
# World
Aliases
substr
, substring
Notes
- Start index is inclusive, end index is exclusive
- Negative indices count from the end of the string
- If only start index is provided, slices from that position to the end
- Uses JavaScript's
String.slice()
method internally
Last updated on