UNPKG

eslint-plugin-de-morgan

Version:

ESLint plugin for transforming negated boolean expressions via De Morgan’s laws

31 lines (30 loc) 832 B
/** * Creates a predicate function that checks if an AST node has a specific * operator. * * @example * * ```ts * const isAnd = hasOperator('&&') * isAnd({ type: 'LogicalExpression', operator: '&&' }) // returns true * ``` * * @example * * ```ts * const isNot = hasOperator('!') * isNot({ type: 'UnaryExpression', operator: '!' }) // returns true * ``` * * @param operator - The operator to check for. For LogicalOperator: `&&`, `||`, * `??` For UnaryOperator: `-`, `+`, `!`, `~`, `typeof`, etc. * @returns A predicate function that: * * - Takes a LogicalExpression or UnaryExpression node * - Returns `true` if the node's operator matches the specified operator * - Returns `false` otherwise. */ function hasOperator(operator) { return node => node.operator === operator } export { hasOperator }