A utility for manipulating bit masks

npm install bit-mask
20 downloads in the last day
97 downloads in the last week
262 downloads in the last month


An NPM for manipulating bit masks

Just a convenient abstraction for computing bitmasks, such as file permissions.

var BitMask = require('bit-mask');

Bit Masks

Declare a new BitMask with an initial value

var mask = new BitMask(value, [base]);

Set a particular bit with a boolean

mask.setBit(position, value)

get the boolean value of a particular bit


get the bits as a string of binary digits


Ownership Mask

Declare a new Ownership Mask with an initial value

var mask = new BitMask.OwnershipMask(value);

Then you have all the functions from the BitMask plus you can get the permissions in a more readable way with:

mask.hasPermission(context, permission)

where context is 'user', 'group' or 'world' and permission is 'read', 'write', 'execute' and a corresponding set:

mask.setPermission(context, permission, value)

as well as a modify function which allows you to pass chmod style modifier strings as well as integer values.



Run the tests at the project root with:



-Abbey Hawk Sparrow

npm loves you