Fuse
FunctionSelect
Fuse
selects a function that passes a condition.
Usage
const Fuse = require('@codefeathers/fuse');
-const { FuseIterable } = require('@codefeathers/fuse');
+Usage
Fuse
const Fuse = require('@codefeathers/fuse');
const a = 100;
@@ -58,7 +57,19 @@ const result = new Fuse(a)
.on(x => x===10,
a => `${a} is 10.`)
-console.log(result.resolve()); // -> "100 is greater than 10."
Docs
Docs exist in /docs
directory. Will be served soon.
+console.log(result.resolve()); // -> "100 is greater than 10."
FuseIterable
const { FuseIterable } = require('@codefeathers/fuse');
+
+const temperatures = [ 0, 20, 30 ];
+
+const result = new FuseIterable(temperatures)
+ .on(temp => temp<10,
+ () => `Too cold!`)
+ .on(temp => temp>=10 && temp <25,
+ () => `Just right.`)
+ .on(temp => temp>=25,
+ () => `Too warm!`)
+
+console.log(result.resolve()); // -> [ "Too cold!", "Just right.", "Too warm!" ]
Docs
Docs exist in /docs
directory. Will be served soon.
Development
@@ -87,7 +98,7 @@ console.log(result.resolve()); // -> "100 is greater than 10."<If you find any mistakes in code/documentation, or if you feel something could be done better, do PR :) I appreciate it.
diff --git a/docs/index.js.html b/docs/index.js.html index c47cbdd..77dbf64 100644 --- a/docs/index.js.html +++ b/docs/index.js.html @@ -183,6 +183,16 @@ class Fuse extends FuseItem { } /** + * Accepts a consequent function which automatically becomes resolve. + * Does not return a Fuse instance as .on after .else would be useless. + * @param {callback} consequent Consequent callback function + * @returns {Fuse} Returns new FuseItem instance + */ + else(consequent) { + return new FuseItem(this.value, consequent); + } + + /** * Accepts a value instead of a test function, and checks for strict * equality with this.value. * @param {any} value Any value to check against this.value @@ -224,7 +234,7 @@ module.exports.FuseIterable = FuseIterable;