https://github.com/wizardpisces/huffman-ts
Huffman Algorithm in Typescript
https://github.com/wizardpisces/huffman-ts
Last synced: about 2 months ago
JSON representation
Huffman Algorithm in Typescript
- Host: GitHub
- URL: https://github.com/wizardpisces/huffman-ts
- Owner: wizardpisces
- License: mit
- Created: 2021-03-10T03:57:51.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-09-04T12:59:19.000Z (over 3 years ago)
- Last Synced: 2024-08-04T16:06:44.986Z (9 months ago)
- Language: TypeScript
- Size: 299 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Huffman ts
Huffman ts is an implementation of Huffman Algorithm in Typescript. It provides
full compatibility with Huffman algorithm reference.Typescript version of [huffman_js](https://github1s.com/wilkerlucio/huffman_js)
[Demo](https://wizardpisces.github.io/playground/huffman)
## Basic Usage
```
npm install --save huffman-ts
``````ts
import {Huffman} from 'huffman-ts'let text = 'BCAADDDCCACACAC'
let huffman = Huffman.treeFromText(text); // first we need to create the tree to make encoding/decoding
let encoded = huffman.encode(text); // will return the compressed version of text
console.log(encoded, encoded.length)let decoded = huffman.decode(encoded); // will decode text to original version
// decoded: 'BCAADDDCCACACAC'```
```ts
import {Huffman} from 'huffman-ts'let text = 'BCAADDDCCACACAC'
let huffman = Huffman.treeFromText(text); // generate the tree
let treeEncoded = huffman.encodeTree(); // will return an javascript array with tree representation
let treeJSON = JSON.stringify(treeEncoded); // get a JSON string for easy transportation
// treeJSON: `["C",[["B","D"],"A"]]`let treeAgain = Huffman.decodeTree(treeEncoded); // restore
```
## Test```
npm run test
```## Other
[more Readme](https://github1s.com/wilkerlucio/huffman_js)