roll-parser - v3.4.0
    Preparing search index...

    Type Alias Token

    A token produced by lex: what it is, the text it came from, and where in the input that text sits.

    position/end are a half-open range, so input.slice(position, end) recovers the original source text — useful for syntax highlighting, where value alone is lossy.

    import { lex, TokenType } from 'roll-parser';

    const input = '4D6KH3';
    const tokens = lex(input);
    tokens[1]; // { type: TokenType.DICE, value: 'd', position: 1, end: 2 }
    tokens[3].type === TokenType.KEEP_HIGH; // true
    input.slice(tokens[3].position, tokens[3].end); // 'KH' — original casing
    tokens[3].value; // 'kh' — normalized
    type Token = {
        end: number;
        position: number;
        type: TokenType;
        value: string;
    }
    Index
    end: number

    Zero-based end offset (exclusive). Not always position + value.length — braced variables (@{name} stores only name) and case-normalized identifiers consume more input than their value retains.

    position: number

    Zero-based start offset in the input string (UTF-16 code units)

    type: TokenType

    The type of this token

    value: string

    The raw string value from input (lowercased for identifiers)