
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

A lightweight library for easy bit flag management in JavaScript and TypeScript. BitFlagsJs is a simple implementation of a BitArray, providing an efficient way to handle bit flags with a minimal API.
npm install bitflagsjs
# or
yarn add bitflagsjs
BitFlagsJs simplifies bit flag operations in JavaScript and TypeScript:
// ES Modules
import BitFlags from 'bitflagsjs';
// CommonJS
// const BitFlags = require('bitflagsjs').default;
import BitFlags from 'bitflagsjs';
// Type-safe bit flags
const flags = new BitFlags();
flags.set(10);
const isSet: boolean = flags.is(10);
const flagArray: number[] = flags.get();
// Initialize with default value [0]
const bitFlags = new BitFlags();
// Initialize with custom values
const initializedFlags = new BitFlags([5, 10]); // [0x00000101, 0x00000a00]
Returns the current bit mask array.
const bitFlags = new BitFlags();
bitFlags.set(2);
bitFlags.set(35);
console.log(bitFlags.get()); // [4, 8] // [0x00000100, 0x00000008]
Checks if the bit at the specified index is set.
const bitFlags = new BitFlags([3]); // [0x00000011]
const isMaskedFirstBit = bitFlags.is(0); // true
const isMaskedSecondBit = bitFlags.is(1); // true
const isMaskedThirdBit = bitFlags.is(2); // false
Sets the bit at the specified index.
const bitFlags = new BitFlags(); // [0x00000000]
bitFlags.set(0); // [0x00000001]
bitFlags.set(1); // [0x00000011]
bitFlags.set(4); // [0x00001011]
Unsets the bit at the specified index.
const bitFlags = new BitFlags([3]); // [0x00000011]
bitFlags.unset(0); // [0x00000010]
bitFlags.unset(1); // [0x00000000]
Clears all bit flags, resetting the array to its initial state.
const bitFlags = new BitFlags([15, 7]); // [0x0000000f, 0x00000007]
bitFlags.clear(); // [0x00000000]
console.log(bitFlags.get()); // [0]
Returns the number of bits set in the bit flag array.
const bitFlags = new BitFlags([3]); // [0x00000011] (2 bits set)
console.log(bitFlags.count()); // 2
bitFlags.set(4); // [0x00010011] (3 bits set)
console.log(bitFlags.count()); // 3
BitFlagsJs supports bitwise operations between two BitFlags instances:
Returns a new BitFlags instance with the bit flags that are set in both this and the other BitFlags instance.
const flags1 = new BitFlags([5]); // [0x00000101]
const flags2 = new BitFlags([3]); // [0x00000011]
const result = flags1.and(flags2); // [0x00000001]
console.log(result.get()); // [1]
Returns a new BitFlags instance with the bit flags that are set in either this or the other BitFlags instance.
const flags1 = new BitFlags([5]); // [0x00000101]
const flags2 = new BitFlags([3]); // [0x00000011]
const result = flags1.or(flags2); // [0x00000111]
console.log(result.get()); // [7]
Returns a new BitFlags instance with the bit flags that are set in either this or the other BitFlags instance, but not in both.
const flags1 = new BitFlags([5]); // [0x00000101]
const flags2 = new BitFlags([3]); // [0x00000011]
const result = flags1.xor(flags2); // [0x00000110]
console.log(result.get()); // [6]
Returns a new BitFlags instance with all bits flipped.
const flags = new BitFlags([5]); // [0x00000101]
const result = flags.not(); // [0xfffffffa]
console.log(result.is(0)); // false
console.log(result.is(1)); // true
console.log(result.is(2)); // true
// Define permissions
const PERMISSIONS = {
READ: 0,
WRITE: 1,
DELETE: 2,
ADMIN: 3
};
// Set user permissions
const userPermissions = new BitFlags();
userPermissions.set(PERMISSIONS.READ);
userPermissions.set(PERMISSIONS.WRITE);
// Check permissions
if (userPermissions.is(PERMISSIONS.READ)) {
console.log('User has read permission');
}
if (!userPermissions.is(PERMISSIONS.ADMIN)) {
console.log('User does not have admin permission');
}
// Remove permissions
userPermissions.unset(PERMISSIONS.WRITE);
BitFlagsJs manages bit flags using arrays of 32-bit integers. When using indices beyond 32, new array elements are automatically allocated.
Want to contribute to this project? You're welcome!
git checkout -b feature/amazing-feature)git commit -m 'feat: add amazing feature')git push origin feature/amazing-feature)feat: Add a new featurefix: Fix a bugdocs: Update documentationstyle: Format code, missing semicolons, etc. (no code change)refactor: Refactor codetest: Add or update testschore: Update build process or auxiliary toolsThis project is licensed under the MIT License - see the LICENSE file for details.
Note: A Korean version of this document is available at README-KR.md
FAQs
managing bit flags by javascript and typescript.
We found that bitflagsjs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.