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

json-bits

v1.0.2

Published

A package for compressing and decompressing JSON data

Readme

Compression Efficiency

Json-Compressor significantly reduces the size of JSON data, which is particularly useful when working with large datasets. For example:

  • A 1 GB JSON file could be compressed down to just a few KB (typically around 1-5% of the original size), depending on the structure and content of the data.

Installation

npm install json-bits

Importing the Library

For CommonJS (Node.js):

const JsonCompressor = require('json-compressor');

For ES Modules:

import JsonCompressor from 'json-compressor';

Basic Usage

1. Compress and Decompress JSON Data

Compress JSON Data

const data = { name: 'Alice', age: 30, active: true };

async function runCompression() {
  const compressed = await JsonCompressor.compressJson(data);
  console.log('Compressed Data:', compressed);
}

runCompression();

Decompress JSON Data

const compressedData = '<your-compressed-data-here>';

async function runDecompression() {
  const decompressed = await JsonCompressor.decompressJson(compressedData);
  console.log('Decompressed Data:', decompressed);
}

runDecompression();

Why Use json-bits?

🚀 Efficient Compression

  • Compresses JSON data into compact binary formats using gzip compression.
  • Reduces the size of large JSON payloads significantly, saving bandwidth and storage.

💡 Flexible Format

  • Supports conversion to and from Base64 for easy transport in text-based systems like HTTP headers or URLs.

⚡ High Performance

  • Built on pako, a fast and efficient gzip implementation for JavaScript.
  • Designed for speed and low overhead, suitable for real-time applications.

🔐 Secure

  • Ensures the integrity of data during compression and decompression with robust error handling.
  • Mitigates risks of data corruption during the compression lifecycle.

🌐 Cross-Platform Compatibility

  • Works seamlessly in Node.js and browser environments.
  • Compatible with modern frameworks like React, Angular, and Vue.

📦 Compact Storage

  • Compresses data into compact representations that can be easily stored or transmitted.
  • Ideal for applications requiring low storage overhead, such as IoT devices, offline apps, or lightweight databases.

🛠️ Ease of Use

  • Intuitive API for compressing, decompressing, and handling data.
  • Simple integration with promises and async/await for modern JavaScript workflows.

🔄 Bidirectional Compression

  • Supports both compression and decompression workflows:
  • JSON → Compressed Binary → JSON
  • JSON → Base64 → JSON

🎯 Utility Functions

  • Includes utilities for advanced developers:
  • Convert between ArrayBuffer and Base64 seamlessly.
  • Pack/unpack bits for fine-grained control over data representation.