{"id":20046027,"url":"https://github.com/johntalton/bitsmush","last_synced_at":"2025-08-03T08:06:50.560Z","repository":{"id":57121855,"uuid":"348157500","full_name":"johntalton/bitsmush","owner":"johntalton","description":"Pack and Unpack bits from a byte","archived":false,"fork":false,"pushed_at":"2024-05-05T13:41:33.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-26T23:12:12.445Z","etag":null,"topics":["bit","byte","pack","smush"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/johntalton.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"publiccode":null,"codemeta":null}},"created_at":"2021-03-16T00:00:24.000Z","updated_at":"2024-05-05T13:41:41.000Z","dependencies_parsed_at":"2024-11-13T11:20:32.406Z","dependency_job_id":"ebad98da-6da8-4104-9d24-61a7b6516644","html_url":"https://github.com/johntalton/bitsmush","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/johntalton/bitsmush","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johntalton%2Fbitsmush","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johntalton%2Fbitsmush/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johntalton%2Fbitsmush/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johntalton%2Fbitsmush/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johntalton","download_url":"https://codeload.github.com/johntalton/bitsmush/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johntalton%2Fbitsmush/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268334605,"owners_count":24233793,"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","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bit","byte","pack","smush"],"created_at":"2024-11-13T11:20:28.232Z","updated_at":"2025-08-03T08:06:50.537Z","avatar_url":"https://github.com/johntalton.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bit Smush 🤗\n\n[![npm Version](https://img.shields.io/npm/v/@johntalton/bitsmush.svg)](https://www.npmjs.com/package/@johntalton/bitsmush)\n![GitHub package.json version](https://img.shields.io/github/package-json/v/johntalton/bitsmush)\n![CI](https://github.com/johntalton/bitsmush/workflows/CI/badge.svg)\n![GitHub](https://img.shields.io/github/license/johntalton/bitsmush)\n[![Downloads Per Month](https://img.shields.io/npm/dm/@johntalton/bitsmush.svg)](https://www.npmjs.com/package/@johntalton/bitsmush)\n![GitHub last commit](https://img.shields.io/github/last-commit/johntalton/bitsmush)\n\n## :book: BitSmush\n\nA namespace for binary operations.  All otherwise reserved operators for bit manipulation should be contained within.  Providing a single lint exception class encapsulation.\n\n##### SmushMap\n\nThe methods `smushBits` and `unSmushBits` work given a template of the data offset and length.\nThis template (`SmushMap`) consists of an array of arrays that contain two numbers - the offset and length.\n\n- Offset is calculated from the right most bit, starting at zero\n- Length is number of bits to copy into destination.\n\nOffset index numbering\n| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |\n|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|\n\nThe following `SmushMap` `[[ 5, 2 ], [ 2, 2 ]]` with the source data `[3, 2]` will produce `0b00_11_0_10_0`\n| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |\n|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|\n| 0  | 0  | `1` | `1` | 0 | `1` | `0` | 0  |\n\nA bit-flags style `SmushMap` could be expressed as `[ [6, 1], [5, 1], [3, 1], [2, 1]]`.\nUsing the source data of `[ENABLED, ENABLED, DISABLED, ENABLED]` (aka `[1, ,1 ,0, 1]`)\n| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |\n|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|\n| 0  | `1`  | `1` | 0 | `0` | `1` | 0 | 0 |\n\nThe following methods `smushBits` and `unSmushBits` work using these templates definitions.\n\n### `smushBits` and `unSmushBits`\n\nPacks or Unpacks multiple number values of specified length (in bits) into or out of a single 8-bit number given a `SmushMap` template.\n\n```javascript\nconst template = [ [6, 1], [5, 3], [1, 2] ]\n```\n\n| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |\n|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|\n| 0  | `X`  | `Y` | `Y` | `Y` | 0 | `Z` | `Z` |\n\n```javascript\nconst source = [1, 3, 2]\nconst expected = 0b0_1_011_0_10 // 0x5A\nconst outRegister = BitSmush.packBits(template, source)\nexpect(outRegister).to.equal(expected)\n```\n\nAnd thus:\n\n```javascript\nconst inRegister = 0x5A\nconst [one, three, two] = BitSmush.unpackBits(template, inRegister)\nexpect(one).to.equal(1)\nexpect(two).to.equal(2)\nexpect(three).to.equal(3)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohntalton%2Fbitsmush","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohntalton%2Fbitsmush","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohntalton%2Fbitsmush/lists"}