Socket
Book a DemoInstallSign in
Socket

@mightyplow/flags

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mightyplow/flags

A utility to handle bitwise flags.

1.1.2
latest
npmnpm
Version published
Maintainers
1
Created
Source

flags

Utilites to manipulate single bits in a sequence of bits. This can be used to store specific boolean flags in a memory saving manor.

Installation

npm i @mightyplow/flags

API

set (flag: number | number[], sequence = 0): number

Sets one or multiple flags on a sequence of bits.

unset (flag: number | number[], sequence = 0): number

Unsets one or multiple flags on a sequence of bits.

isset (flag: number | number[], sequence = 0): boolean

Checks one or multiple flags on a sequence of bits. Returns true, when all requested bits are set to 1.

toggle (flag: number | number[], sequence = 0): number

Inverts one or multiple flags on a sequence of bits.

Examples

Store option flags

import { set } from '@mightyplow/flags'

const Option = {
    foo: 2 ** 0,
    bar: 2 ** 1,
    baz: 2 ** 2
}

const base = 0b000;
console.log(set([Option.foo, Option.baz], base).toSting(2)) // "101"

Create a function to check flags

import { isset } from '@mightyplow/flags'

const Option = {
    foo: 2 ** 0,
    bar: 2 ** 1,
    baz: 2 ** 2
}

const hasFooAndBaz = (flags) => isset([Option.foo, Option.baz], flags)
console.log(hasFooAndBaz(0b101)) // true
console.log(hasFooAndBaz(0b001)) // false

Keywords

flags

FAQs

Package last updated on 23 Oct 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.