{"id":16777045,"url":"https://github.com/fb55/bitfield","last_synced_at":"2025-05-15T20:05:22.044Z","repository":{"id":5379362,"uuid":"6566850","full_name":"fb55/bitfield","owner":"fb55","description":"A bitfield implementation using buffers, compliant with the BitTorrent spec.","archived":false,"fork":false,"pushed_at":"2025-05-15T00:02:13.000Z","size":4007,"stargazers_count":86,"open_issues_count":2,"forks_count":17,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-15T00:39:08.730Z","etag":null,"topics":["bitfield","buffer","javascript"],"latest_commit_sha":null,"homepage":"","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/fb55.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,"zenodo":null}},"created_at":"2012-11-06T18:16:09.000Z","updated_at":"2025-05-15T00:01:22.000Z","dependencies_parsed_at":"2024-02-15T09:24:20.039Z","dependency_job_id":"549fa4df-aa49-4097-af12-5bb366b2ca1c","html_url":"https://github.com/fb55/bitfield","commit_stats":{"total_commits":975,"total_committers":12,"mean_commits":81.25,"dds":"0.11076923076923073","last_synced_commit":"234e25f8445cee33fde533f05e9ec2fa6398a530"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fb55%2Fbitfield","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fb55%2Fbitfield/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fb55%2Fbitfield/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fb55%2Fbitfield/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fb55","download_url":"https://codeload.github.com/fb55/bitfield/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254257381,"owners_count":22040439,"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":["bitfield","buffer","javascript"],"created_at":"2024-10-13T07:11:48.047Z","updated_at":"2025-05-15T20:05:13.372Z","avatar_url":"https://github.com/fb55.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bitfield\n\nA simple bitfield, compliant with the BitTorrent spec.\n\n    npm install bitfield\n\n#### Example\n\n```js\nimport Bitfield from \"bitfield\";\n\nconst field = new Bitfield(256); // Create a bitfield with 256 bits.\n\nfield.set(128); // Set the 128th bit.\nfield.set(128, true); // Same as above.\n\nfield.get(128); // `true`\nfield.get(200); // `false` (all values are initialised to `false`)\nfield.get(1e3); // `false` (out-of-bounds is also false)\n\nfield.set(128, false); // Set the 128th bit to 0 again.\n\nfield.buffer; // The buffer used by the bitfield.\n```\n\n## Class: BitField\n\n### Constructors\n\n- [constructor](#constructor)\n\n### Properties\n\n- [buffer](#buffer)\n\n### Methods\n\n- [forEach](#foreach)\n- [get](#get)\n- [set](#set)\n\n## Constructors\n\n### constructor\n\n\\+ **new BitField**(`data?`: number \\| Uint8Array, `opts?`: BitFieldOptions): `BitField`\n\n#### Parameters:\n\n| Name    | Type                 | Default value | Description                                                                                                                                                                                                                                                       |\n| ------- | -------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `data`  | number \\| Uint8Array | 0             | Either a number representing the maximum number of supported bytes, or a Uint8Array.                                                                                                                                                                              |\n| `opts?` | { grow: number }     | { grow: 0 }   | \u003cp\u003e**grow:**\u003cp\u003eIf you `set` an index that is out-of-bounds, the bitfield will automatically grow so that the bitfield is big enough to contain the given index, up to the given size (in bit). \u003cp\u003eIf you want the Bitfield to grow indefinitely, pass `Infinity`. |\n\n**Returns:** `BitField`\n\n## Properties\n\n### buffer\n\n• **buffer**: Uint8Array\n\nThe internal storage of the bitfield.\n\n## Methods\n\n### forEach\n\n▸ **forEach**(`fn`: (bit: boolean, index: number) =\u003e void, `start?`: number, `end?`: number): void\n\nLoop through the bits in the bitfield.\n\n#### Parameters:\n\n| Name    | Type                                  | Default value           | Description                                                 |\n| ------- | ------------------------------------- | ----------------------- | ----------------------------------------------------------- |\n| `fn`    | (bit: boolean, index: number) =\u003e void | -                       | Function to be called with the bit value and index.         |\n| `start` | number                                | 0                       | Index of the first bit to look at.                          |\n| `end`   | number                                | this.buffer.length \\* 8 | Index of the first bit that should no longer be considered. |\n\n**Returns:** void\n\n---\n\n### get\n\n▸ **get**(`i`: number): boolean\n\nGet a particular bit.\n\n#### Parameters:\n\n| Name | Type   | Description            |\n| ---- | ------ | ---------------------- |\n| `i`  | number | Bit index to retrieve. |\n\n**Returns:** boolean\n\nA boolean indicating whether the `i`th bit is set.\n\n---\n\n### set\n\n▸ **set**(`i`: number, `value?`: boolean): void\n\nSet a particular bit.\n\nWill grow the underlying array if the bit is out of bounds and the `grow` option is set.\n\n#### Parameters:\n\n| Name    | Type    | Default value | Description                                  |\n| ------- | ------- | ------------- | -------------------------------------------- |\n| `i`     | number  | -             | Bit index to set.                            |\n| `value` | boolean | true          | Value to set the bit to. Defaults to `true`. |\n\n**Returns:** void\n\n---\n\n### setAll\n\n▸ **setAll**(`array`: `ArrayLike\u003cboolean\u003e`, `offset?`: number): void\n\nSet the bits in the bitfield to the values in the given array.\n\n#### Parameters:\n\n| Name     | Type                 | Default value | Description                           |\n| -------- | -------------------- | ------------- | ------------------------------------- |\n| `array`  | `ArrayLike\u003cboolean\u003e` | -             | Array of booleans to set the bits to. |\n| `offset` | number               | 0             | Index of the first bit to set.        |\n\n**Returns:** void\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffb55%2Fbitfield","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffb55%2Fbitfield","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffb55%2Fbitfield/lists"}