Ramda Adjunct 3.0.0

isThenable.js

  1. import { pathSatisfies } from 'ramda';
  2. import isFunction from './isFunction';
  3. /**
  4. * Checks if input value is a `thenable`.
  5. * `thenable` is an object or function that defines a `then` method.
  6. *
  7. * @func isThenable
  8. * @memberOf RA
  9. * @since {@link https://char0n.github.io/ramda-adjunct/2.1.0|v2.1.0}
  10. * @category Type
  11. * @sig * -> Boolean
  12. * @param {*} val The value to test
  13. * @return {boolean}
  14. * @see {@link RA.isPromise|isPromise}
  15. * @example
  16. *
  17. * RA.isThenable(null); // => false
  18. * RA.isThenable(undefined); // => false
  19. * RA.isThenable([]); // => false
  20. * RA.isThenable(Promise.resolve()); // => true
  21. * RA.isThenable(Promise.reject()); // => true
  22. * RA.isThenable({ then: () => 1 }); // => true
  23. */
  24. const isThenable = pathSatisfies(isFunction, ['then']);
  25. export default isThenable;