https://github.com/tomashubelbauer/esm-dataview-getvarint
ESM (and non-ESM) JavaScript varint library
https://github.com/tomashubelbauer/esm-dataview-getvarint
javascript library protobuf sqlite varint
Last synced: 3 months ago
JSON representation
ESM (and non-ESM) JavaScript varint library
- Host: GitHub
- URL: https://github.com/tomashubelbauer/esm-dataview-getvarint
- Owner: TomasHubelbauer
- Created: 2021-03-27T15:50:55.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-04-17T00:18:09.000Z (about 4 years ago)
- Last Synced: 2025-10-29T08:38:14.436Z (8 months ago)
- Topics: javascript, library, protobuf, sqlite, varint
- Language: JavaScript
- Homepage: https://tomashubelbauer.github.io/esm-dataview-getvarint/index.js
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# ESM DataView `getVarint`
This JavaScript library extends the `DataView` prototype to add a `getVarint`
method.
The library is developed with Protobuf and SQLite varints in mind, but varints
are used in other applications as well, like Bitcoin, Minecraft and many others.
- [Protobuf varint](https://developers.google.com/protocol-buffers/docs/encoding#varints)
- [SQLite varint](https://sqlite.org/src4/doc/trunk/www/varint.wiki)
## Installation
### `script` tag
```js
```
From this point on, any `DataView` will have a `getVarint` method.
### ES Modules (browser and Node)
Use `--experimental-network-imports` with Node for HTTP(S) ESM URL support:
https://nodejs.org/api/esm.html#https-and-http-imports
```js
import 'https://tomashubelbauer.github.io/esm-dataview-getvarint/index.js';
// From this point on, any `DataView` will have a `getVarint` method.
```
## Usage & API
```js
/** @type {DataView} */
const dataView = …;
/** @typedef {{ value: number; byteLength: number; }} Varint */
// Get a varint at the beginning of the data view
/** @type {Varint} */
const varint = dataView.getVarint();
// Get a varint at a given byte offset in the data view
/** @type {Varint} */
const varint = dataView.getVarint(1);
```