{"name":"bitfield","description":"a simple bitfield, compliant with the BitTorrent spec","version":"4.1.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":"^27.4.1","@types/node":"^17.0.25","@typescript-eslint/eslint-plugin":"^5.20.0","@typescript-eslint/parser":"^5.20.0","eslint":"^8.13.0","eslint-config-prettier":"^8.5.0","eslint-plugin-node":"^11.1.0","jest":"^27.5.1","prettier":"^2.6.2","ts-jest":"^27.1.4","typescript":"^4.6.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"},"prettier":{"tabWidth":4},"gitHead":"597dd2c25d6aa18eb4d844a9ec42c4a2e9e51bbc","homepage":"https://github.com/fb55/bitfield#readme","_id":"bitfield@4.1.0","_nodeVersion":"17.9.0","_npmVersion":"8.5.5","dist":{"integrity":"sha512-6cEDG3K+PK9f+B7WyhWYjp09bqSa+uaAaecVA7Y5giFixyVe1s6HKGnvOqYNR4Mi4fBMjfDPLBpHkKvzzgP7kg==","shasum":"77f3ef4e915e58adaf758b23cbff156959e0fd8e","tarball":"http://registry-npm.ywwl.com/bitfield/download/bitfield-4.1.0.tgz","fileCount":12,"unpackedSize":22121,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDEv/F1BSNElcZOiTdMTEoxu81nYq+cekFNpnHDOyvVRwIhAK0DzNJQEdrJxEBO5MB7qtdIKfnFo3S3mhAugBZdbDpt"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiYme5ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq8Sg//QpXNSwY2D/SpTRCTbnsdO4CeS6Ev+UTvIGqCJFqq/vT4/0zA\r\nW6aWpJ7nsT13nlh9sRvBk2nZrrKcqy/k5OFwjOxpOGb8syuEy+ZwYJ6bbtiE\r\n02F4prykUPiOLvSTmjxijC3BRqG+k1jySJhwzIjlnKKTI5n87pV89ZUbHjzY\r\n379/jGjbByLY/OiboQHdCZW39Y9eZmV1RXxDgbYbJ33Wcps9MEU4Y5hEKo1y\r\n709kXpO/GB8bV8soc5Z9B9ItCe0vKqA4UoU0E4GraJjOVPQlZrXBaMcxZD7d\r\n9eZFXW/7+RpnVCZNdwPZpTonEbL7qZf39H7ezo2dFQlTgJVF9OKYwrmQK2dJ\r\nSGeklWbUVzBhm0MQCPNsgBuh2rjqyPfFpa7DLKpgF8pt+y1iAOYEldK8AoTu\r\ng38dDBQ82Zbmb6768y4v+JiO1/gAAKKWyOizOEwLZbb6G+H8rRAk/hPA3ly+\r\nAVIIXkTLZPFlCzIz+kpry77vE0PKPFH2YqH5VgNqx78DDcbOgXBcbUvLHGOJ\r\noF0DYK0fx9sguLWvwLbwWmjjHfw7snOmSXRrARBUNB1RAb7hXEhJ0UdFyMYE\r\n4K3ABTkuIOyXmSwgIlELTeFuhodY5/K5wlMFelL45KDkmAZD8+Li3HON4Viy\r\nqlVJCLEB5vI3KrYqgWc3eidi9W2AocKqp8w=\r\n=sZIr\r\n-----END PGP SIGNATURE-----\r\n","size":5067,"noattachment":false,"key":"/bitfield/-/bitfield-4.1.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.1.0_1650616248825_0.2694330432515446"},"_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":1650616249074,"_cnpm_publish_time":1650616249074,"dist-tags":{"latest":"5.0.1"}}