You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Huffman code is a particular type of optimal prefix code that is commonly used for lossless data compression. This is the implementation of the algorithm on TypeScript.
Installation
Clone this repository and install modules:
git clone https://github.com/kanitelk/huffman-javascript.gitcd huffman-javascriptnpm installnpm run dev(or build)
Usage
The algorithm implementation is in the file /src/index.ts
Let's encode and decode plain text!
import{getCodesFromText,encode,decode}from'./huffman';/** ENCODING */lettext:string='abracadabra';letencodedText:string='';letcodes:Map<string,string>=getCodesFromText(text);// Symbols codesletencodedArray:Array<any>=encode(text,codes);// Get array of encoded symbolsencodedText=encodedArray.join('');// Encoded array to string. Equals 0101100.../** DECODING */text=decode(encodedArray,codes);// Equals 'abracadabra'