Janiczek / elm-vlq / VLQ

VLQ (variable-length quantity) is a way to encode integers via text.

This base64-encoded variant is notably used in sourcemaps.

Conversion

encode : List Basics.Int -> String

Encode a list of integers to the VLQ representation.

VLQ.encode [ 1, 2, 3 ]
--> "CEG"

VLQ.encode [ 8, 0, 4, 16 ]
--> "QAIgB"

VLQ.encode [ 123456789 ]
--> "qxmvrH"

encodeSingle : Basics.Int -> String

Encode a single integer to the VLQ representation.

This will always behave the same as if you wrapped the integer in a list and encoded it with encode

VLQ.encodeSingle 1
--> "C"

VLQ.encodeSingle 123456789
--> "qxmvrH"

decode : String -> Maybe (List Basics.Int)

Decode a VLQ-encoded string back into a list of integers.

VLQ.decode "C"
--> Just [ 1 ]

VLQ.decode "AAAA"
--> Just [ 0, 0, 0, 0 ]

VLQ.decode "2HwcqxB"
--> Just [ 123, 456, 789 ]

VLQ.decode "Not a VLQ string"
--> Nothing

Constants

The minimum and maximum VLQ integer values representable by JavaScript bitwise operators are -2147483648 (-2^31) and 2147483647 (2^31 - 1) respectively.

minInt : Basics.Int

Minimum integer usable with this library: -2147483648 (-2^31)

maxInt : Basics.Int

Maximum integer usable with this library: 2147483647 (2^31 - 1)