Simple bitwise toggler with enum options packed as AngularJS service and filter. This module provide convenient way to manage array of boolean flags, while using enum to turn on/off the options or get the state.
NPM and YARN are coming soon
- Include the js files (in this order)
- bitwiseEnum.module.js
- bitwiseEnum.service.js
- bitwiseEnum.filter.js
- Require module
'ng-bitwise-enum'
in your angular app - inject
'BitwiseEnum'
service into your angular component/ctrl - Init the bitwise-enum with desired options
var options = [
'EDIT_MODE',
'VALID',
'OTHER_OPTION'
];
// Init the state
var state = new BitwiseEnum(options);
// Set option on
state.setOn(state.options.EDIT_MODE); // set EDIT_MODE to true
state.is(state.options.EDIT_MODE); // return true
state.is(state.options.VALID); // return false as we didn't enable this flag yet
// Set option off
state.setOff(state.options.EDIT_MODE); // set EDIT_MODE to false
state.is(state.options.EDIT_MODE); // return false
// Toggle option on/off
state.toggle(state.options.VALID); // set VALID from false to true
state.is(state.options.EDIT_MODE); // return true
state.toggle(state.options.VALID); // set VALID from true to false
state.is(state.options.EDIT_MODE); // return false
// Get raw bitwise integer
state.setOn(state.options.VALID);
state.setOn(state.options.OTHER_OPTION);
state.getRaw(); // return 110 as
<div ng-if="vm.state | is : vm.state.options.EDIT_MODE"></div>