const $isset = (flag: number, flags = 0) => (flags & flag) === flag const $set = (flag: number, flags = 0) => flags | flag const $unset = (flag: number, flags = 0) => flags ^ flag const $toggle = (flag: number, flags = 0) => $isset(flag, flags) ? $unset(flag, flags) : $set(flag, flags) const combine = (...options: number[]) => options.reduce((flags, flag) => $set(flag, flags), 0) const createMultiFlagHandler = (fn: (flag: number, flags: number) => T) => (...options: number[]) => (flags = 0): T => 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 }