# vlq

> Generate, and decode, base64 VLQ mappings for source maps and other uses

Latest version **2.0.4** (published 2021-10-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install vlq
pnpm add vlq
yarn add vlq
bun add vlq
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2021-10-18 |
| First published | 2014-09-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 221 |
| Author | Rich Harris |
| Maintainers | rich_harris |
| Keywords | sourcemap, sourcemaps, base64, vlq |

## Links

- npm: https://www.npmjs.com/package/vlq
- Repository: https://github.com/Rich-Harris/vlq
- Homepage: https://github.com/Rich-Harris/vlq#readme
- Issues: https://github.com/Rich-Harris/vlq/issues
- npm.io page: https://npm.io/package/vlq

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 2.0.4 (latest) — 2021-10-18
- 2.0.3 — 2021-10-18
- 2.0.2 — 2021-10-16
- 2.0.1 — 2021-10-16
- 2.0.0 — 2021-10-16
- 1.0.1 — 2019-07-03
- 1.0.0 — 2018-01-10
- 0.2.3 — 2017-10-03
- 0.2.2 — 2017-04-13
- 0.2.1 — 2015-02-28
- 0.2.0 — 2015-02-05
- 0.1.0 — 2014-09-28

## README

# 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](http://en.wikipedia.org/wiki/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     |


## Installation

```bash
npm install vlq
```


## Usage

### Encoding

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

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

### Decoding

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

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


## Limitations

Since JavaScript bitwise operators work on 32 bit integers, the maximum value this library can handle is 2^30 - 1, or 1073741823.


## Using vlq.js with sourcemaps

[See here for an example of using vlq.js with sourcemaps.](https://github.com/Rich-Harris/vlq/tree/master/sourcemaps)


## Credits

Adapted from [murzwin.com/base64vlq.html](http://murzwin.com/base64vlq.html) by Alexander Pavlov.


## License

[MIT](LICENSE).

---
_Source: https://npm.io/package/vlq · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
