falseorvalue

Returns the value of supplied argument, or false.

Usage no npm install needed!

<script type="module">
  import falseorvalue from 'https://cdn.skypack.dev/falseorvalue';
</script>

README

False Or Value

This module exports a function which can be used to return a passed value or return false. Useful for setting defaults.

var falseOrV = require('falseorvalue')

var options = {
    aString: falseOrV(undefined) || 'Some default',
    aNumber: falseOrV(NaN) || 10,
    anObject: falseOrV({}) || {a: 1},
    anArray: falseOrV([]) || [1,2,3]
}

Notes:

  • Returns 0, -0 and -n as passed.
  • Does not handle empty multi-dimensional arrays.
  • Does not handle objects with prototype methods or properties, but without enumerable properties.