Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

ifnotundefined

0.0.2 • Public • Published

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'.
    ...
}

Install

npm i ifnotundefined

DownloadsWeekly Downloads

0

Version

0.0.2

License

MIT

Last publish

Collaborators

  • avatar