value-when

Return a value when a condition passes, otherwise return undefined

Usage no npm install needed!

<script type="module">
  import valueWhen from 'https://cdn.skypack.dev/value-when';
</script>

README

value-when Build Status

Return a value when a condition passes, otherwise return undefined

Install

$ npm install --save value-when

Usage

var when = require('value-when')

when(true, 'value')
//=> 'value'

when(false, 'value')
//=> undefined

Or use the functional API:

var when = require('value-when/fn')

when(true, function () {
  return 'value'
})
//=> 'value'

when(false, function () {
  return 'value'
})
//=> undefined

API

when(condition, value) -> value / undefined

condition

Required
Type: any

A value to check for truthiness/falsiness.

value

Type: any

A value to return when the condition passes. When using the functional API, value should be a function to be called to return the output value.

License

MIT © Ben Drucker