set-default-value
v0.0.8
Published
If value is null or undefined, it sets a default value instead.
Downloads
691
Readme
setDefaultValue
Sets a Default-Value, if null or undefined is given
Usage
easily set default values for any variable
import defaults from "set-default-value";
console.log(defaults(null).to(5)); // 5
console.log(defaults(10).to(5)); // 10
Replaces undefined
import defaults from "set-default-value";
console.log(defaults(undefined).to(5)); // 5
console.log(defaults("hi").to("default")); // "hi"
API
typedef Options = {
checkNull: Bool,
checkUndefined: Bool
};
defaults(<Any>, <Options?>).to(<Any>)
It checks for null and undefined by default.