UNPKG

evaluator.js

Version:
20 lines (19 loc) 647 B
/** * Takes a string and evaluates the result. * * @param {string} expression The string. * * @throws {Error} No input. * @throws {Error} No valid tokens. * @throws {Error} Misused operator: <token>. * @throws {Error} Mismatched parentheses. * @throws {Error} Invalid token: <token>. * @throws {Error} No operations. * @throws {Error} Insufficient arguments for method: <token>. * @throws {Error} Insufficient operands for operator: <token>. * @throws {Error} Division by zero. * @throws {Error} Insufficient operators. * * @returns {number} The result. */ export default function (expression: string): number;