
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
A simple bitfield, compliant with the BitTorrent spec.
npm install bitfield
import Bitfield from "bitfield";
const field = new Bitfield(256); // Create a bitfield with 256 bits.
field.set(128); // Set the 128th bit.
field.set(128, true); // Same as above.
field.get(128); // `true`
field.get(200); // `false` (all values are initialised to `false`)
field.get(1e3); // `false` (out-of-bounds is also false)
field.set(128, false); // Set the 128th bit to 0 again.
field.buffer; // The buffer used by the bitfield.
+ new BitField(data?: number | Uint8Array, opts?: BitFieldOptions): BitField
| Name | Type | Default value | Description |
|---|---|---|---|
data | number | Uint8Array | 0 | Either a number representing the maximum number of supported bytes, or a Uint8Array. |
opts? | { grow: number } | { grow: 0 } | grow: If you If you want the Bitfield to grow indefinitely, pass |
Returns: BitField
• buffer: Uint8Array
The internal storage of the bitfield.
â–¸ forEach(fn: (bit: boolean, index: number) => void, start?: number, end?: number): void
Loop through the bits in the bitfield.
| Name | Type | Default value | Description |
|---|---|---|---|
fn | (bit: boolean, index: number) => void | - | Function to be called with the bit value and index. |
start | number | 0 | Index of the first bit to look at. |
end | number | this.buffer.length * 8 | Index of the first bit that should no longer be considered. |
Returns: void
â–¸ get(i: number): boolean
Get a particular bit.
| Name | Type | Description |
|---|---|---|
i | number | Bit index to retrieve. |
Returns: boolean
A boolean indicating whether the ith bit is set.
â–¸ set(i: number, value?: boolean): void
Set a particular bit.
Will grow the underlying array if the bit is out of bounds and the grow option is set.
| Name | Type | Default value | Description |
|---|---|---|---|
i | number | - | Bit index to set. |
value | boolean | true | Value to set the bit to. Defaults to true. |
Returns: void
â–¸ setAll(array: ArrayLike<boolean>, offset?: number): void
Set the bits in the bitfield to the values in the given array.
| Name | Type | Default value | Description |
|---|---|---|---|
array | ArrayLike<boolean> | - | Array of booleans to set the bits to. |
offset | number | 0 | Index of the first bit to set. |
Returns: void
MIT
FAQs
a simple bitfield, compliant with the BitTorrent spec
The npm package bitfield receives a total of 14,126 weekly downloads. As such, bitfield popularity was classified as popular.
We found that bitfield demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.