Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/minhducsun2002/leb128
A Node.js implementation of LEB128-formatted number parser
https://github.com/minhducsun2002/leb128
leb128 nodejs npm
Last synced: 29 days ago
JSON representation
A Node.js implementation of LEB128-formatted number parser
- Host: GitHub
- URL: https://github.com/minhducsun2002/leb128
- Owner: minhducsun2002
- License: mit
- Created: 2020-01-10T08:51:46.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-09-28T12:39:03.000Z (about 2 years ago)
- Last Synced: 2024-10-09T18:02:22.556Z (3 months ago)
- Topics: leb128, nodejs, npm
- Language: TypeScript
- Homepage: https://minhducsun2002.github.io/leb128
- Size: 202 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `leb128`
###### A parser for LEB128-formatted numbers.
![](https://img.shields.io/github/workflow/status/minhducsun2002/leb128/Jest%20tests?label=Jest%20tests)
![](https://img.shields.io/github/workflow/status/minhducsun2002/leb128/TypeScript%20compilation)
[![](https://img.shields.io/npm/v/@minhducsun2002/leb128)](https://www.npmjs.com/package/@minhducsun2002/leb128)### Usage
```js
// ES6 imports
import { LEB128 } from '@minhducsun2002/leb128';
// CommonJS thingy
const { LEB128 } = require('@minhducsun2002/leb128');// Unsigned integers
var a = LEB128.encode(462644);
// Uint8Array (3) [ 180, 158, 28 ]
var b = LEB128.decode(a);
// 462644
var c = LEB128.decode([0xA6, 0x87, 0x90, 0x04])
// 8651686// Signed (negative) integers
var d = LEB128.encode(-128383);
// Uint8Array(3) [ 129, 149, 120 ]
var e = LEB128.decode(d, 0, true); /* offset = 0, negative number */
// 8651686
var f = LEB128.decode([0x01, 0x81, 0x95, 0x78], 1, true)
// -128383
```### License
MIT License. See [here](./LICENSE)