Skip to main content

Utility for working with bits

Works with
This package works with Bun
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Browsers
JSR Score
100%
Published
2 weeks ago

Bits manipulation utility

JSR CI

Usage

Bits

import {Bits} from '@maks11060/bits'

enum Flags {
  flag1 = 0,
  flag2 = 1,
  flag3 = 2,
}
const b = new Bits<Flags>()

b.set(Flags.flag1)
b.clear(Flags.flag2)
b.toggle(Flags.flag3)
b.value   // 5
b.toBin() // 101

BitsN (using bigint)

import {BitsN} from '@maks11060/bits'

const Flags = {
  flag1: 0n,
  flag2: 1n,
  flag3: 2n,
} as const
const b = BitsN.from<typeof Flags>(0)

b.set(Flags.flag1)
b.clear(Flags.flag2)
b.toggle(Flags.flag3)
b.value   // 5n
b.toBin() // 101n
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @maks11060/bits

Import symbol

import * as mod from "@maks11060/bits";

Add Package

npx jsr add @maks11060/bits

Import symbol

import * as mod from "@maks11060/bits";

Add Package

yarn dlx jsr add @maks11060/bits

Import symbol

import * as mod from "@maks11060/bits";

Add Package

pnpm dlx jsr add @maks11060/bits

Import symbol

import * as mod from "@maks11060/bits";

Add Package

bunx jsr add @maks11060/bits

Import symbol

import * as mod from "@maks11060/bits";