mightyplow 6a51785ade add some fields | vor 5 Jahren | |
---|---|---|
src | vor 5 Jahren | |
tests | vor 5 Jahren | |
.gitignore | vor 5 Jahren | |
README.md | vor 5 Jahren | |
package-lock.json | vor 5 Jahren | |
package.json | vor 5 Jahren |
Utilites to manipulate single bits in a sequence of bits. This can be used to store specific boolean flags in a memory saving manor.
npm i @mightyplow/flags
Sets one or multiple flags on a sequence of bits.
Unsets one or multiple flags on a sequence of bits.
Checks one or multiple flags on a sequence of bits. Returns true, when all requested bits are set to 1.
Inverts one or multiple flags on a sequence of bits.
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"
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