1.0.0 • Published 10 months ago

als-compress-json v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

Compress JSON

A utility library for compressing JSON data by identifying and compacting repeated string patterns.

Installation

To install this package, run the following command:

npm install compress-json

Usage

Here's a basic usage of this library:

const CompressValues = require('compress-json');

const data = {
  // your data here...
};

const { dictionary, compressed } = CompressValues.compress(data);
const decompressed = CompressValues.decompress({ dictionary, compressed });

API

The library exports two static methods:

  • compress(data: object, length?: number, prefix?: string): CompressedData
    • Compresses the given JSON data. length and prefix are optional parameters to adjust the compression settings.
  • decompress(data: CompressedData, length?: number, prefix?: string): object
    • Decompresses data previously compressed by the compress method. length and prefix should match the values used when compressing.

The CompressedData type is an object with the following structure:

{
  dictionary: string[],
  dictionaryString: string,
  compressed: string, // stringified json
  savedBytes: number,
  workTime: number,
}