@xen-orchestra/defined
v0.0.2
Published
Utilities to help handling (possibly) undefined values
Downloads
76
Maintainers
Keywords
Readme
@xen-orchestra/defined
Utilities to help handling (possibly) undefined values
Install
Installation of the npm package:
npm install --save @xen-orchestra/defined
Usage
defined()
Returns the first non-undefined
value from a list of arguments, evaluating functions if needed.
There is two ways to use this function:
- either with a single array argument: it should return the first non-undefined item
- or with multiple arguments: it should return the first non-undefined argument
If only undefined
values, return undefined
.
import defined from '@xen-orchestra/defined/index.js'
defined(undefined, 'foo', 42)
// Returns 'foo'
defined([undefined, null, 10])
// Returns null
defined([undefined, undefined], [undefined, undefined, 10])
// Returns [undefined, undefined]
defined(() => 'bar', 42)
// Returns 'bar'
defined(undefined, undefined)
// Returns undefined
Contributions
Contributions are very welcomed, either on the documentation or on the code.
You may:
- report any issue you've encountered;
- fork and create a pull request.