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 🙏

© 2026 – Pkg Stats / Ryan Hefner

nv-number-uleb

v1.0.3

Published

一个轻量级的 JavaScript 库,用于处理 ULEB128(Unsigned Little Endian Base 128)编码和解码。ULEB128 是一种用于表示任意大小非负整数的变长编码方式,常用于减少数据传输或存储时的字节数。

Readme

nv-number-uleb

一个轻量级的 JavaScript 库,用于处理 ULEB128(Unsigned Little Endian Base 128)编码和解码。ULEB128 是一种用于表示任意大小非负整数的变长编码方式,常用于减少数据传输或存储时的字节数。

安装

npm install nv-number-uleb

特性

  • 轻量级实现,无依赖
  • 支持编码/解码单个数字或批量操作
  • 提供缓冲区内原地编码功能,减少内存分配
  • 高效的解码能力,支持从特定偏移量开始解码

使用方法

基本编码和解码

const uleb128 = require('nv-number-uleb');

// 编码单个数字
const encoded = uleb128.encd(300);
console.log(encoded); // Uint8Array [ 172, 2 ]

// 解码
const decoded = uleb128.decd(encoded);
console.log(decoded); // [300]

原地编码(节省内存)

const uleb128 = require('nv-number-uleb');

// 准备缓冲区
const buffer = new Uint8Array(10);
let offset = 0;

// 编码多个数字到同一缓冲区
offset = uleb128.encd_into(42, buffer, offset);
offset = uleb128.encd_into(1337, buffer, offset);
offset = uleb128.encd_into(9000, buffer, offset);

console.log(buffer.slice(0, offset)); 
// 包含了三个编码后的数字

// 解码全部
const allNumbers = uleb128.decd(buffer.slice(0, offset));
console.log(allNumbers); // [42, 1337, 9000]

从特定偏移量解码

const uleb128 = require('nv-number-uleb');

const buffer = new Uint8Array([42, 0xE9, 0x0A, 0x98, 0x44]);
//                             ^    ^----------^
//                             |         |
//                            42      1337

let offset = 0;
let value;

[value, offset] = uleb128.decd_from(buffer, offset);
console.log(value); // 42
console.log(offset); // 1

[value, offset] = uleb128.decd_from(buffer, offset);
console.log(value); // 1337
console.log(offset); // 4

API 参考

encd(number)

将单个数字编码为 ULEB128 格式。

  • 参数: number - 要编码的非负整数
  • 返回值: Uint8Array - 包含编码结果的新数组

encd_into(number, buffer, offset = 0)

将数字编码到提供的缓冲区中。

  • 参数:
    • number - 要编码的非负整数
    • buffer - 目标 Uint8Array 缓冲区
    • offset - 开始写入的偏移量 (默认为 0)
  • 返回值: 编码后的新偏移量

decd_from(buffer, offset = 0)

从缓冲区的特定偏移量开始解码单个数字。

  • 参数:
    • buffer - 包含 ULEB128 编码数据的 Uint8Array
    • offset - 开始解码的偏移量 (默认为 0)
  • 返回值: 包含 [解码的数字, 新偏移量] 的数组,如果解码失败则为 [null, null]

decd(buffer)

解码缓冲区中的所有 ULEB128 编码的数字。

  • 参数: buffer - 包含 ULEB128 编码数据的 Uint8Array
  • 返回值: 解码后的数字数组

ULEB128 编码简介

ULEB128(Unsigned Little Endian Base 128)是一种变长编码方式,专为节省空间而设计。其工作原理是:

  1. 每个字节的低 7 位用于编码数值
  2. 最高位(第 8 位)用作延续标志:1 表示后面还有字节,0 表示当前字节是最后一个
  3. 较小的数字使用较少的字节,实现空间优化

常见使用场景:

  • 字节码格式(如 WebAssembly、DWARF 调试信息等)
  • 优化的二进制协议
  • 数据压缩算法

许可证

MIT