npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hookun/vlq

v1.0.1

Published

A tool to encode/decode arbitrary unsigned integers using predefined-length chunk of bits.

Downloads

5

Readme

@hookun/vlq

codecov .github/workflows/push.yml .github/workflows/publish.yml

A tool to encode/decode arbitrary unsigned integers using predefined-length chunk of bits.

Usage

import {encodeToArrayBuffer, decodeToArray} from '@hookhookun/vlq';
const data = [1, 2, 3, 4];
const encoded1 = encodeToArrayBuffer(data, 1);
console.info(Buffer.from(encoded1).toString('hex'));
// 073788
console.info(Buffer.from(encoded1).toString('base64url'));
// BzeI
console.info(decodeToArray(encoded1));
// [ 1, 2, 3, 4 ]
const encoded2 = encodeToArrayBuffer(data, 2);
console.info(Buffer.from(encoded1).toString('hex'));
// 129d10
console.info(Buffer.from(encoded1).toString('base64url'));
// Ep0Q
console.info(decodeToArray(encoded1));
// [ 1, 2, 3, 4 ]

Install

npm install @hookun/vlq

API document

docs/modules.md

Format of encoded binary

Encoded     = ChunkSize -> Data -> EndOfChunks
ChunkSize   = Value(3,C-1)
Data        = *Value(C,x)
EndOfChunks = SB(C,0)
Value(n,x)  = *SB(n,x1) -> LSB(n,x0)
SB(n,x)     = 1xxxxxxxxxxx
               | <- n -> |
LSB(n,y)    = 0yyyyyyyyyyy

The binary representation of ChunkSize is 1 less than the actual value.

Example: Value(1+n) and EndOfChunks (EOC)

Assume that ChunkSize is 1.

| x| Value(1,x)| |----:|----------------:| | 0| 00| | 1| 01| | 2| 11 00| | 3| 11 01| | 4| 11 10 00| | 5| 11 10 01| | 8| 11 10 10 00| | 16| 11 10 10 10 00| | EOC| 10|

Assume that ChunkSize is 2.

| x| Value(2,x)| |----:|----------------:| | 0| 000| | 1| 001| | 2| 010| | 3| 011| | 4| 101 000| | 5| 101 001| | 8| 110 000| | 16| 101 100 000| | 32| 110 100 000| | 64|101 100 100 000| | EOC| 100|

Assume that ChunkSize is 3.

| x| Value(3,x)| |----:|---------------:| | 0| 0000| | 1| 0001| | 2| 0010| | 3| 0011| | 4| 0100| | 8| 1001 0000| | 16| 1010 0000| | 32| 1100 0000| | 64|1001 1000 0000| | EOC| 1000|

Example: Encoded

Assume that Data is [1, 2, 3, 4] ChunkSize is 1.

EndOfChunks = 10
Data        = 01 11 00 11 01 11 10 00
ChunkSize   = 0000
Encoded     = 0000 01 11 00 11 01 11 10 00 10
            = ChunkSize -> Data -> EndOfChunks
            = 0000011100110111100010
            = 0000 0111 0011 0111 1000 10(00)
            =    0    7    3    7    8     8
            = 0x073788

Assume that Data is [1, 2, 3, 4] ChunkSize is 2.

EndOfChunks = 100
Data        = 001 010 011 101 000
ChunkSize   = 0001
Encoded     = 0001 001 010 011 101 000 100
            = ChunkSize -> Data -> EndOfChunks
            = 0001001010011101000100
            = 0001 0010 1001 1101 0001 00(00)
            =    1    2    9    d    1     0
            = 0x129d10

Example: decoding 0x51450f2880

Encoded =    5   1   4   5   0   f   2   8   8   0
        = 0101000101000101000011110010100010000000
          ^^^^|          <-   Data   ->          |

Since ChunkSize is 5, divide Data into (5+offset+flag bit)=(5+1+1)=7 bits each.

Data = 0001010 0010100 0011110 0101000 1000000 0
     =      10      20      30      40     EOC
     = [10, 20, 30, 40]

License

Apache License, Version 2.0