function readVLQ
readVLQ(
text: string,
position: number
): [number, number]

Reads one VLQ-encoded integer from text starting at position. Returns [decodedValue, positionAfterLastConsumedChar].

Each base64 character contributes 5 data bits (bits 0–4) and 1 continuation bit (bit 5). The least-significant bit of the fully-accumulated value is the sign bit.

import * as SourceMap from './source-map.ts';

SourceMap.readVLQ('C', 0); // [1, 1] — value 1, next position 1
SourceMap.readVLQ('D', 0); // [-1, 1] — the low bit is the sign
SourceMap.readVLQ('gB', 0); // [16, 2] — 'g' sets the continuation bit, 'B' finishes the value

Parameters

text: string
position: number

Return Type

[number, number]

Usage

import { readVLQ } from "lib/utils/source-map.ts";