New:Microsoft Teams Notifications Are Now Available in Socket.Learn more
Get Started

stringcompression

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

stringcompression

String compression is the process of reducing the size of text data to optimize storage space or transmission.

unpublished
latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

String compression is the process of reducing the size of text data to optimize storage space or transmission.

Install

npm install stringcompression

Functions

The following functions are available:

  • encodeKeys(input): Encodes the keys in the input text using a predefined dictionary. Words in the input that match a key in the dictionary are replaced with a caret symbol (^) followed by the corresponding key.

  • decodeKeys(input): Decodes the keys in the input text using a predefined dictionary. Words in the input that start with a caret symbol (^) followed by a key are replaced with the corresponding value from the dictionary.

  • compressIt(input): Performs a series of encoding operations on the input text. It applies the Burrows-Wheeler Transform (BWT), Move-to-Front (MTF) encoding, Elias Gamma Coding (EGC), and Bijective Ternary Transformation (BTT) using the provided keys and dictionary.

  • decompressIt(input): Performs a series of decoding operations on the input code. It reverses the encoding operations applied by the encodeIt function using the provided keys and dictionary.

Usage

To use these functions in your JavaScript code, you can require the module and call the desired functions:

const { encodeKeys, decodeKeys, compressIt, decompressIt } = require('stringcompression');

// perform dynamic compress - Stable

const encodedText = compressIt('Hello, world!');
console.log(encodedText); // Outputs: encoded text

const decodedText = decompressIt(encodedText);
console.log(decodedText); // Outputs: 'Hello, world!'

// perform dictionary compress - Experimental

const encoded = encodeKeys('Hello, world!');
console.log(encoded); // Outputs: 'Hello, ^WRUJ^RBT^'

const decoded = decodeKeys('Hello, ^WRUJ^RBT^');
console.log(decoded); // Outputs: 'Hello, world!'

// learn how to combine both

const text = `Through fields resplendent, we gallivant,
Embracing nature's whispered chant.
In twilight's embrace, we find solace,
Our bond, unbreakable and flawless.

Through tempests fierce and trials dire,
You ignite within me a ceaseless fire.
With valor true, you stand by my side,
A guardian, my soul's eternal guide.

So, let us revel in this sacred dance,
For in your presence, I find enhanced,
A love profound, beyond all measure,
Woven with words, woven with treasure.`;

// compressoons and decompressions
const { encodeKeys, decodeKeys } = require('./index.js');

const { compressIt, decompressIt } = require('./index.js');

const keys = encodeKeys(text);

console.log('\n\n', keys.length, keys);

const code = compressIt(keys);

console.log('\n\n', code.length, code);

console.log(`        `);

const decode = decompressIt(code);

console.log('\n\n', decode.length, decode);

const decodx = decodeKeys(decode);

console.log('\n\n', decodx.length, decodx);

Results

stringcompression

Keywords

string

FAQs

Package last updated on 07 Nov 2023

Related posts