Skip to content
Generate, and decode, base64 VLQ mappings for sourcemaps and other uses
Branch: master
Clone or download
Latest commit b7093c2 Jan 10, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
sourcemaps annotations Sep 28, 2014
src Use let and const Jan 9, 2018
test initial commit Sep 28, 2014
.eslintrc.json -> v0.2.2 Apr 13, 2017
.gitignore Add dist to .gitignore Jan 9, 2018
CHANGELOG.md -> v1.0.0 Jan 10, 2018
LICENSE
README.md Update README.md Oct 3, 2017
package-lock.json
package.json
rollup.config.js Switch to TypeScript Jan 9, 2018
tsconfig.json

README.md

vlq.js

Convert integers to a Base64-encoded VLQ string, and vice versa. No dependencies, works in node.js or browsers, supports AMD.

Why would you want to do that?

Sourcemaps are the most likely use case. Mappings from original source to generated content are encoded as a sequence of VLQ strings.

What is a VLQ string?

A variable-length quantity is a compact way of encoding large integers in text (i.e. in situations where you can't transmit raw binary data). An integer represented as digits will always take up more space than the equivalent VLQ representation:

Integer VLQ
0 A
1 C
-1 D
123 2H
123456789 qxmvrH
123456789123456789 gxvh6sB

Installation

npm install vlq

...or...

bower install vlq

...or grab the vlq.js file and include it with a <script src='vlq.js'> tag.

Usage

Encoding

vlq.encode accepts an integer, or an array of integers, and returns a string:

vlq.encode( 123 ); // '2H';
vlq.encode([ 123, 456, 789 ]); // '2HwcqxB'

Decoding

vlq.decode accepts a string and always returns an array:

vlq.decode( '2H' ); // [ 123 ]
vlq.decode( '2HwcqxB' ); // [ 123, 456, 789 ]

Using vlq.js with sourcemaps

See here for an example of using vlq.js with sourcemaps.

Credits

Adapted from murzwin.com/base64vlq.html by Alexander Pavlov.

License

MIT.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.