@xen-orchestra/defined

0.0.2 • Public • Published

@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

Readme

Keywords

none

Package Sidebar

Install

npm i @xen-orchestra/defined

Weekly Downloads

7

Version

0.0.2

License

ISC

Unpacked Size

3.78 kB

Total Files

3

Last publish

Collaborators

  • mlssfrncjrg
  • mathieura
  • stephane-m-dev
  • florent.beauchamp
  • julien-f
  • marsaud
  • pdonias
  • olivierlambert
  • benjireis
  • tgoettelmann
  • b-nollet
  • joris-k
  • sebastianczech
  • olivier.f