deffy
Small and fast library to set default values.
Installation
$ npm i deffy
Example
var Deffy = require("deffy");
console.log(Deffy(undefined, "Hello World"));
console.log(Deffy("Hello World", 42));
console.log(Deffy("Hello", "World"));
console.log(Deffy("", "World", true));
console.log(Deffy("", "World"));
console.log(Deffy("foo", function (input) {
return input === "foo" ? "bar" : "foo";
}));
Documentation
Deffy(input, def, options)
Computes a final value by providing the input and default values.
Params
-
Anything input
: The input value.
-
Anything|Function def
: The default value or a function getting the input value as first argument.
-
Object|Boolean options
: The empty
value or an object containing the following fields:
-
empty
(Boolean): Handles the input value as empty field (input || default
). Default is false
.
Return
- Anything The computed value.
How to contribute
Have an idea? Found a bug? See how to contribute.
License
KINDLY © Ionică Bizău–The LICENSE file contains
a copy of the license.