Web calculator with persistent history, virtual keypad, and keyboard shortcuts. Expression evaluation via a custom parser (no eval).
npm installRequirements: Node ^20.19.0 or >=22.12.0.
npm run dev # development server
npm run build # production build
npm run test:unit # unit tests- Expression field — Type or use the virtual keypad. Accepts spaces; known characters are normalized (e.g.
*→×). - Operators: addition (
+), subtraction (−), multiplication (×), division (÷), square (²), percent (%), and parentheses. Decimal numbers with a dot. - Precedence: multiplication and division before addition and subtraction; parentheses override the order.
- = / Enter — Evaluates, shows the result in the field, and adds it to history.
- Virtual keypad — Buttons for digits, operators, parentheses,
C(clear),.,%,², etc. Double×inserts². - Physical keyboard — Outside the field: mapped digits and operators, Enter/= to evaluate, Backspace to remove the last character. Inside the field: normal typing and paste; Enter evaluates.
- Calculation list — Each row shows expression and result. Click a row to reuse that expression.
- Delete item — Hover over a row to show the delete button; click to remove it from history.
- Clear All — Top button clears the entire history.
- Persistence — History is stored in the browser (localStorage) across sessions.
- Error messages (invalid expression, division by zero, unbalanced parentheses, etc.) appear above the field. Any new edit or action clears the error.
- Frontend: Vue 3 (Composition API), TypeScript.
- State: Pinia with history persistence (pinia-plugin-persistedstate).
- Styling: Tailwind CSS v4.
- Build: Vite 7.
- Tests: Vitest and Vue Test Utils (store, expression evaluator, clicks, keyboard, and history).
- Expression evaluation: Custom parser (tokenization + precedence), no
eval. Supports+,−,×,÷,²,%, and parentheses.
✅ Persistent history in the browser
✅ Input via virtual and physical keyboard
✅ Safe expression parser (no eval)
✅ Operator precedence and parentheses
✅ Unit tests (store, eval, UI, and keyboard)