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

json-string-pack

v1.0.7

Published

Compress JSON strings with a large number of repeating characters.

Readme

json-string-pack

npm version License: MIT

一个高效的 JSON 字符串压缩工具,特别适用于包含大量重复字符串的 JSON 数据。该库使用 MessagePack 和 GZIP 压缩算法,可以显著减小数据大小。

特性

  • 🚀 高效压缩:使用 MessagePack 和 GZIP 双重压缩
  • 🔄 字符串去重:自动检测和优化重复字符串
  • 💪 类型支持:完整的 TypeScript 类型定义
  • 🌐 跨平台:支持浏览器和 Node.js 环境
  • 📦 轻量级:最小化的依赖

安装

npm install json-string-pack

使用方法

ESM 方式导入

import { pack, unpack } from 'json-string-pack';

// 压缩数据
const data = {
  users: [
    { name: 'Alice', role: 'admin' },
    { name: 'Bob', role: 'admin' },
  ],
};

const compressed = await pack(data);
console.log(compressed); // 输出 base64 编码的压缩数据

// 解压数据
const decompressed = await unpack(compressed);
console.log(decompressed); // 输出原始对象

CommonJS 方式导入

const { pack, unpack } = require('json-string-pack');

// 压缩数据
const data = {
  users: [
    { name: 'Alice', role: 'admin' },
    { name: 'Bob', role: 'admin' },
  ],
};

// 使用 async/await
(async () => {
  const compressed = await pack(data);
  console.log(compressed); // 输出 base64 编码的压缩数据

  // 解压数据
  const decompressed = await unpack(compressed);
  console.log(decompressed); // 输出原始对象
})();

API 文档

pack(value: Object): Promise<string>

将 JavaScript 对象压缩为 base64 字符串。

参数:

  • value: 要压缩的数据, json 格式的对象或数组

返回:

  • Promise<string>: base64 编码的压缩数据

unpack(data: string): Promise<Object>

将压缩的 base64 字符串解压为原始数据。

参数:

  • data: base64 编码的压缩数据

返回:

  • Promise<Object>: 解压后的原始数据

性能优化建议

  1. 对于如果数据量较小或者字符串基本不重复,使用该库反而会导致体积增加;
  2. 如果数据量较大,建议在 Web Worker 中进行压缩/解压操作;
  3. 考虑使用流式处理来处理超大数据集;
  4. 解压后的对象的属性顺序不能保证。

贡献指南

欢迎提交 Issue 和 Pull Request!在提交 PR 之前,请确保:

  1. 添加/更新测试用例
  2. 通过所有测试
  3. 更新相关文档
  4. 遵循代码风格指南

许可证

MIT