{"type":"module","name":"bitfield","description":"a simple bitfield, compliant with the BitTorrent spec","version":"5.0.1","author":{"name":"Felix Boehm","email":"me@feedic.com"},"funding":{"type":"github","url":"https://github.com/sponsors/fb55"},"sideEffects":false,"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"bugs":{"url":"https://github.com/fb55/bitfield/issues"},"devDependencies":{"@biomejs/biome":"^2.4.7","@eslint/compat":"^2.0.3","@feedic/eslint-config":"^0.3.1","@types/node":"^25.5.0","eslint":"^10.0.3","eslint-config-biome":"^2.1.3","globals":"^17.4.0","typescript":"^5.9.3","typescript-eslint":"^8.57.1","vitest":"^4.0.18"},"engines":{"node":">=20.19.0"},"keywords":["bitfield","buffer","bittorrent"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/fb55/bitfield.git"},"scripts":{"build":"tsc","format":"npm run format:es && npm run format:biome","format:biome":"biome check --write .","format:es":"npm run lint:es -- --fix","lint":"npm run lint:es && npm run lint:biome","lint:biome":"biome check .","lint:es":"eslint .","prepare":"npm run build","test":"npm run test:vi && npm run lint","test:vi":"vitest run"},"gitHead":"844e52f4edefdbe13e2aef6bafe807cd252d791e","_id":"bitfield@5.0.1","homepage":"https://github.com/fb55/bitfield#readme","_nodeVersion":"24.14.0","_npmVersion":"11.9.0","dist":{"integrity":"sha512-81mvFHCa0L1HsDdKVCTkPKZZ6KFdyXgfQNoneFT7Qk5/PZeBWdPkTFa4KttbR8uHszfjiqOJbeahLOPfCqw4cw==","shasum":"b3fdbf92291d78a8fcec7d027542d7591d69a109","tarball":"http://registry-npm.ywwl.com/bitfield/download/bitfield-5.0.1.tgz","fileCount":8,"unpackedSize":24749,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/bitfield@5.0.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDludEQmVT1bTM5YXMsBy22BhZQje42TKq+KaomOCmZ0gIgB5DjBfuh9nf+LwqqUTXMlY8CniqAMLuN1xXXLHCWdAI="}],"size":5518,"noattachment":false,"key":"/bitfield/-/bitfield-5.0.1.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:4ee2a5ab-0b17-4058-906d-cb19bb01a752"}},"directories":{},"maintainers":[{"name":"fb55","email":"me@feedic.com"},{"name":"mafintosh","email":"mathiasbuus@gmail.com"},{"name":"feross","email":"feross@feross.org"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/bitfield_5.0.1_1773789153831_0.46981066018127793"},"_hasShrinkwrap":false,"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 }   | <p>**grow:**<p>If 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). <p>If 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) => 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) => 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<boolean>`, `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<boolean>` | -             | 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","publish_time":1773789153972,"_cnpm_publish_time":1773789153972,"dist-tags":{"latest":"5.0.1"}}