a set of helper functions that simplify the (is a undefined ? b : c) syntax
npm install ifnotundefAuthor: Loïc Formont
License: MIT Licensed
Example
``javascript
var undef = require("ifnotundef");
`
* ifnotundef
[.if(a, b, [c])](#module_ifnotundef.if) ⇒ \
* .is(a, b) ⇒ boolean
* .isnot(a, b) ⇒ boolean
* .check(a, b) ⇒ boolean
[.try(a, [b])](#module_ifnotundef.try) ⇒ \
[.child(a, b, c, [d])](#module_ifnotundef.child) ⇒ \
Kind: static method of ifnotundef
Returns: \* - a, b or c depending on their undefined status
| Param | Type | Description |
| --- | --- | --- |
| a | \* | the first parameter |
| b | \* | the second parameter |
| [c] | \* | the third parameter |
Example
Two ways to use if. Either with two parameters (a||b):
`javascript
var myHost = undef.if(options.host, options.hostname);
`
or with three parameters (a?b:c):
`javascript
var myHost = undef.if(options.host, options.hostname, 'localhost');
`
Kind: static method of ifnotundef
Returns: boolean - a or a[b]'s undefined status
| Param | Type | Description |
| --- | --- | --- |
| a | \* | the variable to check |
| b | \* | the child path |
Example
`javascript
if(undef.is(options.host)) console.log('Deal with it');
`
Kind: static method of ifnotundef
Returns: boolean - a or a[b]'s undefined status
| Param | Type | Description |
| --- | --- | --- |
| a | \* | the variable to check |
| b | \* | the child path |
Example
`javascript
if(undef.isnot(options.host)) console.log('Great');
`
Kind: static method of ifnotundef
Returns: boolean - a or a[b]'s undefined status
| Param | Type | Description |
| --- | --- | --- |
| a | \* | the variable to check |
| b | \* | the child path |
Example
`javascript
if(!undef.check(options.host)) console.log('Deal with it');
`
Kind: static method of ifnotundef
Returns: \* - a or exception depending on a's undefined status
| Param | Type | Description |
| --- | --- | --- |
| a | \* | the parameter to try |
| [b] | \* | the error message |
Example
Two ways to use if. Either with one parameter:
`javascript
var myHost = undef.try(options.host);
`
or with two parameters:
`javascript
var myUndefined = undef.try(undefined, 'undefined is not defined ... ;-)');
// Exeption raised above
`
Kind: static method of ifnotundef
Returns: \* - a[b] or c or d depending on their undefined status
| Param | Type | Description |
| --- | --- | --- |
| a | \* | the object |
| b | \* | the child path |
| c | \* | the first value |
| [d] | \* | the second value |
Example
Two ways to use child. Either with three parameters (a[b]||c):
`javascript
var myHost = undef.child(options, ['params', 'host'], 'localhost');
`
or with four parameters (a[b]?c:d):
`javascript
var myHost = undef.child(options, ['params'], options.params.host, 'localhost');
``