{"id":19177737,"url":"https://github.com/jessety/wiegand-encoder","last_synced_at":"2025-07-15T22:10:52.030Z","repository":{"id":57397755,"uuid":"237865038","full_name":"jessety/wiegand-encoder","owner":"jessety","description":"Encode and decode 26-bit, 34-bit, or 38-bit Wiegand protocol credentials for communicating with access control systems in TypeScript or JavaScript","archived":false,"fork":false,"pushed_at":"2024-09-03T21:07:29.000Z","size":49,"stargazers_count":12,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-09T22:07:52.891Z","etag":null,"topics":["access-control","bit-parity","encoder","nodejs","typescript","wiegand","wiegand-encoder","wiegand-protocol","wiegand-reader","wiegand-rfid"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/wiegand-encoder","language":"TypeScript","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/jessety.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":"2020-02-03T01:39:45.000Z","updated_at":"2025-02-11T13:29:06.000Z","dependencies_parsed_at":"2024-11-09T10:35:24.637Z","dependency_job_id":"81a4d9db-957a-4806-af5e-95b0460efcf3","html_url":"https://github.com/jessety/wiegand-encoder","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/jessety/wiegand-encoder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessety%2Fwiegand-encoder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessety%2Fwiegand-encoder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessety%2Fwiegand-encoder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessety%2Fwiegand-encoder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jessety","download_url":"https://codeload.github.com/jessety/wiegand-encoder/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessety%2Fwiegand-encoder/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265464256,"owners_count":23770316,"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":["access-control","bit-parity","encoder","nodejs","typescript","wiegand","wiegand-encoder","wiegand-protocol","wiegand-reader","wiegand-rfid"],"created_at":"2024-11-09T10:34:55.646Z","updated_at":"2025-07-15T22:10:52.009Z","avatar_url":"https://github.com/jessety.png","language":"TypeScript","readme":"# wiegand-encoder\n\nLightweight module that encodes and decodes 26, 34, or 38 bit Wiegand protocol credentials for communication with access control systems.\n\n[![ci](https://github.com/jessety/wiegand-encoder/workflows/ci/badge.svg)](https://github.com/jessety/wiegand-encoder/actions?query=workflow%3Aci)\n[![coverage](https://codecov.io/gh/jessety/wiegand-encoder/branch/main/graph/badge.svg?token=D7FYN28WBE)](https://codecov.io/gh/jessety/wiegand-encoder)\n[![npm](https://img.shields.io/npm/v/wiegand-encoder.svg)](https://www.npmjs.com/package/wiegand-encoder)\n[![license](https://img.shields.io/github/license/jessety/wiegand-encoder.svg)](https://github.com/jessety/wiegand-encoder/blob/main/LICENSE)\n\n## Installation\n\n```bash\nnpm install wiegand-encoder\n```\n\n## Usage\n\n```javascript\n// Modules\nimport wiegand from 'wiegand-encoder';\n\n// CommonJS\nconst wiegand = require('wiegand-encoder');\n```\n\n### Encoding\n\nThe `encode()` function converts a card number and facility code into binary, counts the bit parity of each half of the message, and wraps it in parity bits.\n\n```javascript\nconst encoded = wiegand.encode(cardNumber, facilityCode);\n\nwiegand.encode(wiegand.encode(324, 90));\n// 00101101000000001010001000\n```\n\nIf the specified card number or facility code are too high for the standard bit length, it will throw an exception. The largest possible card number in 26-bit protocol is `65535`, and the largest possible facility code is `255`.\n\n### Decoding\n\nThe `decode()` function validates the parity bits on either side of the message, then parses the message content from binary back into integers.\n\n```javascript\nconst { cardNumber, facilityCode } = wiegand.decode('00101101000000001010001000');\n// { cardNumber: 324, facilityCode: 90 }\n```\n\nIf the parity bits are invalid, `decode()` will throw an exception.\n\nTo check parity on a message without decoding it, use `parity.validate()`.\n\n```javascript\ntry {\n  wiegand.parity.validate('00101101000000001010001000');\n} catch (error) {\n  console.error(error);\n}\n```\n\n### Alternate bit length\n\nBy default, `encode()` encodes all messages as 26-bit.\n\nTo encode a larger message (e.g. 34-bit, 38-bit, etc.) send the bit length for the card number and facility code to the `encode()` function.\n\n26-bit credentials use a card number length of `16` and a facility code length of `8`. To encode a 34-bit message, use a card number length of `22` and a facility code length fo `10`.\n\n```javascript\nwiegand.encode(cardNumber, facilityCode, cardNumberLength, facilityCodeLength);\n\nwiegand.encode(wiegand.encode(324, 90, 22, 10));\n// 0000101101000000000000001010001000\n```\n\nThe `decode()` function also supports optional `cardNumberLength` and `facilityCodeLength` parameters, but will attempt to infer them based on the content of the length of the message if omitted.\n\n```javascript\nconst { cardNumber, facilityCode } = wiegand.decode('0000101101000000000000001010001000');\n// { cardNumber: 324, facilityCode: 90 }\n```\n\n## License\n\nMIT © Jesse Youngblood\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjessety%2Fwiegand-encoder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjessety%2Fwiegand-encoder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjessety%2Fwiegand-encoder/lists"}