Chalkboard - v3.0.1
    Preparing search index...

    Function parse

    • Parses, simplifies, and optionally evaluates a boolean expression. When called with values, it evaluates the expression with the provided variable values, and otherwise, it simplifies the expression to its minimal form. Supports variables (a-z, A-Z, 0-9, _), operators (!, &, |), and parentheses.

      Parameters

      • expr: string

        The boolean expression to parse

      • config: {
            returnAST?: boolean;
            returnJSON?: boolean;
            returnLaTeX?: boolean;
            values?: Record<string, boolean | 0 | 1>;
        } = ...
        • OptionalreturnAST?: boolean

          If true, returns an abstract syntax tree (AST) instead of a string

        • OptionalreturnJSON?: boolean

          If true, returns an AST in JSON instead of a string

        • OptionalreturnLaTeX?: boolean

          If true, returns LaTeX code instead of a string

        • Optionalvalues?: Record<string, boolean | 0 | 1>

          Optional object mapping variable names to values

      Returns string | boolean | 0 | 1 | { type: string; [key: string]: any }

      // Simplify expression
      const p = Chalkboard.bool.parse("x & !x | y & x | y & !x"); // Returns "y"
      const q = Chalkboard.bool.parse("(x & y) | (x & z)"); // Returns "x & (y | z)"

      // Evaluate expression with values
      const r = Chalkboard.bool.parse("x & y | z", { values: { x: true, y: false, z: true } }); // Returns true
      const s = Chalkboard.bool.parse("a & !b", { values: { a: 1, b: 0 } }); // Returns true

      // Get AST representation
      const t = Chalkboard.bool.parse("x & y", { returnAST: true }); // Returns AST object