condition.js 454 B

1234567891011121314151617181920
  1. /**
  2. * Check if a "thing" is truthy according to a "condition"
  3. *
  4. * Note: matches.condition(node, matcher) can be indirectly used through
  5. * matches(node, { condition: matcher })
  6. *
  7. * Example:
  8. * ```js
  9. * matches.condition(node, (arg) => arg === null)
  10. * ```
  11. *
  12. * @param {any} argument
  13. * @param {Function|Null|undefined} condition
  14. * @returns {Boolean}
  15. */
  16. function condition(arg, condition) {
  17. return !!condition(arg);
  18. }
  19. export default condition;