|
@@ -0,0 +1,50 @@
|
|
|
|
+"use strict";
|
|
|
|
+exports.__esModule = true;
|
|
|
|
+var applyFlagHandler = function (fn) { return function (flags) { return function (initial) {
|
|
|
|
+ if (initial === void 0) { initial = 0; }
|
|
|
|
+ return fn(flags)(initial);
|
|
|
|
+}; }; };
|
|
|
|
+var $isset = function (flag) { return function (flags) {
|
|
|
|
+ if (flags === void 0) { flags = 0; }
|
|
|
|
+ return (flags & flag) === flag;
|
|
|
|
+}; };
|
|
|
|
+var $set = function (flag) { return function (flags) {
|
|
|
|
+ if (flags === void 0) { flags = 0; }
|
|
|
|
+ return flags | flag;
|
|
|
|
+}; };
|
|
|
|
+var $unset = function (flag) { return function (flags) {
|
|
|
|
+ if (flags === void 0) { flags = 0; }
|
|
|
|
+ return flags ^ flag;
|
|
|
|
+}; };
|
|
|
|
+var $toggle = function (flag) { return function (flags) {
|
|
|
|
+ if (flags === void 0) { flags = 0; }
|
|
|
|
+ return $isset(flag)(flags) ? $unset(flag)(flags) : $set(flag)(flags);
|
|
|
|
+}; };
|
|
|
|
+var combine = function () {
|
|
|
|
+ var options = [];
|
|
|
|
+ for (var _i = 0; _i < arguments.length; _i++) {
|
|
|
|
+ options[_i] = arguments[_i];
|
|
|
|
+ }
|
|
|
|
+ return options.reduce(function (flags, flag) { return $set(flag)(flags); }, 0);
|
|
|
|
+};
|
|
|
|
+exports.combine = combine;
|
|
|
|
+var createMultiFlagHandler = function (fn) { return function () {
|
|
|
|
+ var options = [];
|
|
|
|
+ for (var _i = 0; _i < arguments.length; _i++) {
|
|
|
|
+ options[_i] = arguments[_i];
|
|
|
|
+ }
|
|
|
|
+ return function (flags) {
|
|
|
|
+ if (flags === void 0) { flags = 0; }
|
|
|
|
+ return applyFlagHandler(fn)(combine.apply(void 0, options))(flags);
|
|
|
|
+ };
|
|
|
|
+}; };
|
|
|
|
+var set = createMultiFlagHandler($set);
|
|
|
|
+exports.set = set;
|
|
|
|
+var unset = createMultiFlagHandler($unset);
|
|
|
|
+exports.unset = unset;
|
|
|
|
+var toggle = createMultiFlagHandler($toggle);
|
|
|
|
+exports.toggle = toggle;
|
|
|
|
+var isset = createMultiFlagHandler($isset);
|
|
|
|
+exports.isset = isset;
|
|
|
|
+var settings = set(1, 4, 8)();
|
|
|
|
+console.log(isset(4)(settings));
|