0.0.2 • Published 7 years ago

ifnotundefined v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

IfNotUndefined

A shorthand helper function for the pattern: const x = (typeof y !== 'undefined' ? y : 'default-value');

Usage

const ifNotUndefined = require('ifnotundefined');

function MyFunc (options = {}) {
	this.timeout = ifNotUndefined(options.timeout, null);  // the default value for timeout will be null.
	this.encoding = ifNotUndefined(options.encoding, 'utf8');  // the default value for encoding will be 'utf8'.
	...
}