omnibelt/default-to-strict.js

  1. const curry = require('ramda/src/curry');
  2. const when = require('ramda/src/when');
  3. const either = require('ramda/src/either');
  4. const isNil = require('ramda/src/isNil');
  5. const complement = require('ramda/src/complement');
  6. const always = require('ramda/src/always');
  7. const isPopulatedString = require('./is-populated-string');
  8. /**
  9. * TODO: TESTS
  10. * TODO: DOCS
  11. *
  12. * @signature * a -> * b -> a|b
  13. */
  14. const defaultToStrict = curry((def, val) =>
  15. when(
  16. either(isNil, complement(isPopulatedString)),
  17. always(def)
  18. )(val)
  19. );
  20. module.exports = defaultToStrict;