GithubHelp home page GithubHelp logo

kelreel / huffman-javascript Goto Github PK

View Code? Open in Web Editor NEW
32.0 2.0 3.0 2.04 MB

Huffman encode/decode text

Home Page: https://kelreel.github.io/huffman-javascript/

JavaScript 22.14% TypeScript 72.85% HTML 4.00% Shell 1.00%
huffman-coding huffman-algorithm huffman-tree huffman-compression-algorithm

huffman-javascript's Introduction


Huffman coding JS (TypeScript)

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.git
cd huffman-javascript
npm install
npm 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 */
let text: string = 'abracadabra'; 
let encodedText: string = '';

let codes: Map<string, string> = getCodesFromText(text); // Symbols codes
let encodedArray: Array<any> = encode(text, codes); // Get array of encoded symbols

encodedText = encodedArray.join(''); // Encoded array to string. Equals 0101100...

/** DECODING */
text = decode(encodedArray, codes); // Equals 'abracadabra'

APIs

Encode text

encode(text: string, codes: Map<string, string>): Array<string>

Decode text

decode(text: Array<string>, codes: Map<string, string>):string

Get symbols codes from text

getCodesFromText(text: string): Map<string, string>

Get symbols frequency

getFrequency(text: string): Array<any>

Get Huffman Tree from frequency array

getTree(arr: Array<any>)

Get relative frequency array

getRelativeFrequency(arr: Array<any>): Array<any>

Get text entropy

getEntropyOfText(text: string): number

huffman-javascript's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

huffman-javascript's Issues

tests?

Hey, great work on this.

Is there any chance that tests could be written for this, we would be willing to contribute a couple hundred bucks to make sure it's done.

Best,
Nick

make jquery an optional dependancy

Looks like your including jquery into the package dependancies.

This for most dev's makes this unusable when not using special tree shaking builds.

Any chance jqeury could be moved to a dev or optional dependancy?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.