0.0.2 • Published 8 years ago

bitwise-mask v0.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

Bitwise mask

Build Status Test Coverage

Installation

$ npm install --save bitwise-mask

Usage

import * as bitmask from 'bitwise-mask';

const Directions = {
  TOP: 1 << 0,
  RIGHT: 1 << 1,
  BOTTOM: 1 << 2,
  LEFT: 1 << 3
}

Directions.TOP_RIGHT = bitmask.combine(Directions.TOP, Directions.RIGHT);

let mask = bitmask.create();

mask = bitmask.add(Directions.TOP, Directions.RIGHT);

bitmask.contains(mask, Directions.TOP_RIGHT); // true

API

mask = create(...fields)

Create a mask with the given fields.

field = bitmask.combine(...fields)

Combine fields into one field.

mask = bitmask.add(mask, ...fields)

Add fields to mask.

mask = bitmask.remove(mask, ...fields)

Remove fields from mask.

bitmask.contains(mask, ...fields)

Check if the the mask contains the fields and returns a boolean.

License

MIT, see LICENSE.md for more details.

0.0.2

8 years ago

0.0.1

8 years ago