1234567891011 |
- const $isset = (flag, flags = 0) => (flags & flag) === flag;
- const $set = (flag, flags = 0) => flags | flag;
- const $unset = (flag, flags = 0) => flags ^ flag;
- const $toggle = (flag, flags = 0) => $isset(flag, flags) ? $unset(flag, flags) : $set(flag, flags);
- const combine = (...options) => options.reduce((flags, flag) => $set(flag, flags), 0);
- const createMultiFlagHandler = (fn) => (...options) => (flags = 0) => fn(combine(...options), flags);
- const set = createMultiFlagHandler($set);
- const unset = createMultiFlagHandler($unset);
- const toggle = createMultiFlagHandler($toggle);
- const isset = createMultiFlagHandler($isset);
- export { combine, set, unset, toggle, isset };
|