{"name":"bitfield","description":"a simple bitfield, compliant with the BitTorrent spec","version":"4.2.0","author":{"name":"Felix Boehm","email":"me@feedic.com"},"funding":{"url":"https://github.com/sponsors/fb55"},"sideEffects":false,"main":"lib/index.js","types":"lib/index.d.ts","module":"lib/esm/index.js","exports":{"require":"./lib/index.js","import":"./lib/esm/index.js"},"directories":{"lib":"lib/"},"bugs":{"url":"https://github.com/fb55/bitfield/issues"},"devDependencies":{"@types/jest":"^29.5.11","@types/node":"^20.10.6","@typescript-eslint/eslint-plugin":"^6.17.0","@typescript-eslint/parser":"^6.17.0","eslint":"^8.56.0","eslint-config-prettier":"^9.1.0","eslint-plugin-n":"^16.6.1","jest":"^29.7.0","prettier":"^3.1.1","ts-jest":"^29.1.1","typescript":"^5.3.3"},"engines":{"node":">=8"},"keywords":["bitfield","buffer","bittorrent"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/fb55/bitfield.git"},"scripts":{"test":"npm run test:jest && npm run lint","test:jest":"jest","lint":"npm run lint:es && npm run lint:prettier","lint:es":"eslint .","lint:prettier":"npm run format:prettier:raw -- --check","format":"npm run format:es && npm run format:prettier","format:es":"npm run lint:es -- --fix","format:prettier":"npm run format:prettier:raw -- --write","format:prettier:raw":"prettier '**/*.{{m,c,}js,ts,md,json,yml}'","build":"npm run build:cjs && npm run build:esm","build:cjs":"tsc --sourceRoot https://raw.githubusercontent.com/fb55/bitfield/$(git rev-parse HEAD)/src/","build:esm":"npm run build:cjs -- --module esnext --target es2019 --outDir lib/esm && echo '{\"type\":\"module\"}' > lib/esm/package.json","prepare":"npm run build"},"jest":{"preset":"ts-jest","testEnvironment":"node","moduleNameMapper":{"^(.*)\\.js$":"$1"}},"prettier":{"tabWidth":4},"_id":"bitfield@4.2.0","gitHead":"070c4a2deb66da3282283665c8765ed247d80ae5","homepage":"https://github.com/fb55/bitfield#readme","_nodeVersion":"21.5.0","_npmVersion":"10.2.4","dist":{"integrity":"sha512-kUTatQb/mBd8uhvdLrUkouGDBUQiJaIOvPlptUwOWp6MFqih4d1MiVf0m3ATxfZSzu+LjW/awFeABltYa62uIA==","shasum":"fecb620bbe38e16526fbb62048f6c4af712ace91","tarball":"http://registry-npm.ywwl.com/bitfield/download/bitfield-4.2.0.tgz","fileCount":12,"unpackedSize":31552,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCHx86fDZkJS/nlOwPdVKqggIUXe6ylbGfObTpPwZ+1jACIQDjTO+1/MRMQgCIsjsVCGeftXA4zT94J55Nh3gFx3iDnQ=="}],"size":6175,"noattachment":false,"key":"/bitfield/-/bitfield-4.2.0.tgz"},"_npmUser":{"name":"feedic","email":"me@feedic.com"},"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"},{"name":"feross","email":"feross@feross.org"},{"name":"feedic","email":"me@feedic.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bitfield_4.2.0_1704451691035_0.05623634947983347"},"_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":1704451691170,"_cnpm_publish_time":1704451691170,"dist-tags":{"latest":"5.0.1"}}