mirror of
https://github.com/vatesfr/xen-orchestra.git
synced 2026-11-09 17:06:13 -06:00
63 lines
1.8 KiB
Markdown
63 lines
1.8 KiB
Markdown
<!-- DO NOT EDIT MANUALLY, THIS FILE HAS BEEN GENERATED -->
|
|
|
|
# @xen-orchestra/defined
|
|
|
|
[](https://npmjs.org/package/@xen-orchestra/defined)  [](https://bundlephobia.com/result?p=@xen-orchestra/defined) [](https://npmjs.org/package/@xen-orchestra/defined)
|
|
|
|
> Utilities to help handling (possibly) undefined values
|
|
|
|
## Install
|
|
|
|
Installation of the [npm package](https://npmjs.org/package/@xen-orchestra/defined):
|
|
|
|
```sh
|
|
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`.
|
|
|
|
```js
|
|
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](https://github.com/vatesfr/xen-orchestra/issues)
|
|
you've encountered;
|
|
- fork and create a pull request.
|
|
|
|
## License
|
|
|
|
[ISC](https://spdx.org/licenses/ISC) © [Vates SAS](https://vates.fr)
|