nco
v1.0.1
Published
Applies a default value to a variable if it is null or undefined.
Downloads
155,515
Maintainers
Readme
nco
A function that acts as a Null-Coalescing Operator (nco) for npm and node. This is a terse way of setting default values.
You can read more about null-coalescing operators here: https://en.wikipedia.org/wiki/Null_coalescing_operator
Usage:
const nco = require('nco');
function myFunction(var1, var2) {
var1 = nco(var1, 'default1');
//if var1 was null or undefined, it will now be 'default1'
var2 = nco(var2, 'default2');
//etc.
}
The example usage written in C#, which uses ??
as a null-coalescing operator:
void MyFunction(string var1, string var2) {
var1 = var1 ?? "default1";
var2 = var2 ?? "default2";
//etc.
}