eslint-plugin-de-morgan
Version:
ESLint plugin for transforming negated boolean expressions via De Morgan’s laws
36 lines (35 loc) • 971 B
TypeScript
import {
LogicalExpression,
LogicalOperator,
UnaryExpression,
UnaryOperator,
} from 'estree'
/**
* 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.
*/
export declare function hasOperator(
operator: LogicalOperator | UnaryOperator,
): (node: LogicalExpression | UnaryExpression) => boolean