{"id":21594580,"url":"https://github.com/kelreel/huffman-javascript","last_synced_at":"2025-04-10T23:41:46.996Z","repository":{"id":38408795,"uuid":"181177036","full_name":"kelreel/huffman-javascript","owner":"kelreel","description":"Huffman encode/decode text","archived":false,"fork":false,"pushed_at":"2024-02-25T18:11:27.000Z","size":2088,"stargazers_count":31,"open_issues_count":2,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T20:37:52.548Z","etag":null,"topics":["huffman-algorithm","huffman-coding","huffman-compression-algorithm","huffman-tree"],"latest_commit_sha":null,"homepage":"https://kelreel.github.io/huffman-javascript/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kelreel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-04-13T13:42:25.000Z","updated_at":"2025-01-31T02:21:46.000Z","dependencies_parsed_at":"2024-02-25T19:27:46.715Z","dependency_job_id":"a9fb6d7e-dc39-4256-803f-a057ff65497f","html_url":"https://github.com/kelreel/huffman-javascript","commit_stats":{"total_commits":14,"total_committers":4,"mean_commits":3.5,"dds":0.2142857142857143,"last_synced_commit":"80069f06ddcb05e078cdac2e7f4e8cf59c695782"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelreel%2Fhuffman-javascript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelreel%2Fhuffman-javascript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelreel%2Fhuffman-javascript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelreel%2Fhuffman-javascript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kelreel","download_url":"https://codeload.github.com/kelreel/huffman-javascript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247500460,"owners_count":20948879,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["huffman-algorithm","huffman-coding","huffman-compression-algorithm","huffman-tree"],"created_at":"2024-11-24T17:18:53.498Z","updated_at":"2025-04-10T23:41:46.977Z","avatar_url":"https://github.com/kelreel.png","language":"TypeScript","readme":"\u003ch1 align=\"center\"\u003e\u003cimg height=\"150\" src=\"assets/logo.png\" /\u003e\u003cbr\u003eHuffman coding JS (TypeScript)\u003c/h1\u003e\n\n[//]: # (\u003ch2 align=\"center\"\u003e)\n\n[//]: # (  \u003ca href=\"https://kelreel.github.io/huffman-javascript/\"\u003eDEMO\u003c/a\u003e)\n\n[//]: # (\u003c/h2\u003e)\n\nHuffman 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.\n  \n## Installation\n\nClone this repository and install modules:\n\n```bash\ngit clone https://github.com/kanitelk/huffman-javascript.git\ncd huffman-javascript\nnpm install\nnpm run dev(or build)\n```\n\n![](assets/split.png)\n\n## Usage\n\n\u003cb\u003eThe algorithm implementation is in the file /src/index.ts\u003c/b\u003e\n\nLet's encode and decode plain text!\n\n```typescript\nimport { getCodesFromText, encode, decode } from './huffman';\n\n/** ENCODING */\nlet text: string = 'abracadabra'; \nlet encodedText: string = '';\n\nlet codes: Map\u003cstring, string\u003e = getCodesFromText(text); // Symbols codes\nlet encodedArray: Array\u003cany\u003e = encode(text, codes); // Get array of encoded symbols\n\nencodedText = encodedArray.join(''); // Encoded array to string. Equals 0101100...\n\n/** DECODING */\ntext = decode(encodedArray, codes); // Equals 'abracadabra'\n\n```\n\n![](assets/split.png)\n\n## APIs\n\n#### Encode text\n```typescript\nencode(text: string, codes: Map\u003cstring, string\u003e): Array\u003cstring\u003e\n```\n\n#### Decode text\n```typescript\ndecode(text: Array\u003cstring\u003e, codes: Map\u003cstring, string\u003e):string\n```\n\n#### Get symbols codes from text\n```typescript\ngetCodesFromText(text: string): Map\u003cstring, string\u003e\n```\n\n#### Get symbols frequency\n```typescript\ngetFrequency(text: string): Array\u003cany\u003e\n```\n\n#### Get Huffman Tree from frequency array\n```typescript\ngetTree(arr: Array\u003cany\u003e)\n```\n\n#### Get relative frequency array\n```typescript\ngetRelativeFrequency(arr: Array\u003cany\u003e): Array\u003cany\u003e\n```\n\n#### Get text entropy\n```typescript\ngetEntropyOfText(text: string): number\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkelreel%2Fhuffman-javascript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkelreel%2Fhuffman-javascript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkelreel%2Fhuffman-javascript/lists"}