bitflag-js v1.0.0
·
7 commits
to main
since this release
This package provides a class for working with bitflag fields. These structures are very useful as a way to condense a list of boolean values into a single number. They are perfect matches for things like user flags, permissions, and more.
bitflag-js is written in TypeScript and uses bigints instead of numbers.
Usage
import { BitField } from "bitflags-js";
const UserBadges = {
VERIFIED: 1n << 0n,
CONTRIBUTOR: 1n << 1n,
SUPPORTER: 1n << 2n,
VIP: 1n << 3n,
};
const bitfield = new BitField();
bitfield.add(UserBadges.VERIFIED);
bitfield.add(UserBadges.CONTRIBUTOR);
if (bitfield.has(UserBadges.VERIFIED)) {
console.log("This user is verified!");
}
console.log(bitfield.value);