0.0.2 • Published 9 months ago

@xen-orchestra/defined v0.0.2

Weekly downloads
1
License
ISC
Repository
github
Last release
9 months ago

@xen-orchestra/defined

Package Version License PackagePhobia Node compatibility

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.

License

ISC © Vates SAS