Parsec Web is a generalized JavaScript library that connects to the equations-parser WebAssembly module (C++ code compiled to WASM) for high-performance, cross-platform equation evaluation.
- Generalization: Make the library reusable across different JavaScript environments
- Cross-Platform: Support frontend projects, Flutter web, Node.js applications
- Performance: Leverage WebAssembly for fast, client-side equation processing
- Offline-First: No server dependency, completely self-contained
JavaScript Applications
↓
Parsec Web Library (js/equations_parser_wrapper.js)
↓
WebAssembly Module (wasm/equations_parser.js/.wasm)
↓
C++ equations-parser Library
- Frontend Projects: React, Vue, Angular, vanilla JavaScript
- Flutter Web: Via dart:js_interop integration
- Node.js Applications: As importable npm package
- Cross-Platform Solutions: Any JavaScript environment
The project uses Vitest as the primary testing framework for comprehensive equation evaluation testing.
Test Categories:
-
Unit Tests (8 modules):
tests/unit/arithmetic.test.js- Basic math operations, order of operationstrigonometry.test.js- sin, cos, tan, inverse functions, hyperboliclogarithms.test.js- ln, log, exp functionsstrings.test.js- concat, length, toupper, tolower, substring functionsdates.test.js- current_date, daysdiff, hoursdiff functionscomplex.test.js- real, imag, conj, arg, norm functionsarrays.test.js- sizeof, eye, ones, zeros functions
-
Integration Tests (2 modules):
tests/integration/complex-expressions.test.js- Multi-function combinationsmixed-types.test.js- Different return types (number, string, boolean)
-
Error Handling (3 modules):
tests/errors/syntax-errors.test.js- Invalid equation syntaxruntime-errors.test.js- Division by zero, invalid argumentstype-errors.test.js- Type mismatches, invalid operations
-
Performance Benchmarks (3 modules):
tests/performance/simple-ops.bench.js- Basic arithmetic benchmarkingfunction-calls.bench.js- Function call performancecomplex-expr.bench.js- Complex expression performance
Testing Commands:
npm test # Run all tests
npm run test:watch # Watch mode for development
npm run test:coverage # Generate coverage report
npm run test:unit # Unit tests only
npm run test:integration # Integration tests only
npm run test:performance # Performance benchmarkspackage.json- Complete npm configuration with proper scripts and metadata- Multi-format exports supporting ES6, CommonJS, and UMD patterns
- TypeScript definitions included for full type safety
- Professional package structure ready for npm publishing
// Parsec class with enhanced functionality
const parsec = new Parsec()
await parsec.initialize()
// Batch evaluation
const results = parsec.evaluateBatch(['2+2', 'sqrt(16)', 'sin(pi/2)'])
// Timeout protection
const result = await parsec.evaluateWithTimeout('expression', 5000)
// Library metadata
const info = parsec.getInfo()
console.log(info.supportedPlatforms) // Multiple platform support info// ES6 Modules
import { Parsec } from 'parsec-web'
// CommonJS (Node.js)
const { Parsec } = require('parsec-web')
// TypeScript
import { Parsec, EquationResult } from 'parsec-web'- Prettier: Automatic code formatting with consistent style rules
- ESLint: Code quality checking with modern JavaScript best practices
- npm scripts:
style:fix,lint:fix,format,testcommands - Vitest configuration: Modern testing framework setup
Development Workflow:
npm run style:fix # Auto-fix formatting and linting
npm test # Run comprehensive test suite
npm run dev # Start development server
npm run build # Build WebAssembly module- Goal:
dart:js_interopintegration - Planned: Dart bindings for JavaScript library
- Status: Future enhancement
Modern Automated Testing Approach:
- Vitest: Modern testing framework
- Automated: Runs via npm scripts
- Comprehensive: All equations-parser functionality covered
- CI/CD Ready: JSON reports, coverage metrics
- Cross-Platform: Works in any Node.js environment
npm install # Install all dependencies
chmod +x build.sh # Make build script executable
./build.sh # Compile C++ to WebAssemblyThe project requires Emscripten to compile the C++ equations-parser library to WebAssembly:
- System Installation: Install via package manager (
apt-get install emscripten) - Official Download: From https://emscripten.org/docs/getting_started/downloads.html
- Manual emsdk Setup: Clone and configure emsdk repository manually
Manual emsdk Setup (if needed):
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest # Install latest Emscripten
./emsdk activate latest # Activate for use
source ./emsdk_env.sh # Set environment variables
cd ..
./build.sh # Build WebAssembly modulenpm test # Run complete test suite
npm run test:watch # Development mode with auto-rerun
npm run test:coverage # Generate coverage report
npm run test:unit # Unit tests only
npm run test:integration # Integration tests only
npm run test:performance # Performance benchmarks onlynpm run lint # 🔍 Run ESLint checks
npm run lint:fix # 🤖 Auto-fix linting issues
npm run format:check # 🔍 Check formatting without changes
npm run format # 🤖 Format code with Prettier
npm run style:fix # 🤖 🦾 Fix both linting and formattingnpm run dev # Start development server (port 8000)
npm run serve # Alternative server command
# Access: http://localhost:8000# Test CommonJS import in Node.js
node -e "const E = require('./index.js'); console.log('✅ CommonJS works')"
# Test ES6 import (requires Node.js with ES modules support)
node --input-type=module -e "import('./index.mjs').then(()=>console.log('✅ ES6 works'))"The repository is configured as a production-ready npm package with dual CommonJS/ES module support:
# 1. Ensure everything is built and tested
npm run build # Builds WebAssembly module
npm test # Runs comprehensive test suite
npm run lint # Checks code quality
# 2. Test package creation
npm pack --dry-run # Preview what will be published
# 3. Login to npm (if not already)
npm login
# 4. Publish to npm registry
npm publish
# 5. Or publish as scoped package
npm publish --access publicPackage Structure:
- CommonJS entry:
index.cjsfor Node.jsrequire() - ES Module entry:
index.mjsfor modernimport - TypeScript definitions:
types.d.tswith complete type safety - Automated scripts:
prepublishOnlyandprepackensure quality
Installation for users:
npm install parsec-webUsage examples:
// CommonJS (Node.js)
const { Parsec } = require('parsec-web')
// ES Modules (modern)
import { Parsec } from 'parsec-web'
// Usage
const parsec = new Parsec()
await parsec.initialize()
const result = parsec.eval('2 + 3 * 4') // Returns: 14parsec-web/
├── cpp/ # C++ source files
│ └── equations-parser/ # Git submodule
├── js/ # JavaScript library
│ └── equations_parser_wrapper.js # Core WebAssembly wrapper (Parsec class)
├── wasm/ # Generated WebAssembly files
│ └── equations_parser.js # Main WebAssembly module
├── tests/ # Vitest test suites
│ ├── setup.js # Global test configuration
│ ├── unit/ # Function category tests
│ ├── integration/ # Complex expression tests
│ ├── errors/ # Error handling tests
│ └── performance/ # Benchmark tests
├── index.js # CommonJS entry point
├── index.mjs # ES6 module entry point
├── types.d.ts # TypeScript definitions
├── package.json # npm package configuration
├── vitest.config.js # Vitest configuration
├── .eslintrc.js # ESLint configuration
├── .prettierrc # Prettier configuration
├── .prettierignore # Prettier ignore patterns
├── build.sh # WebAssembly build script
├── README.md # Public documentation
└── CLAUDE.md # This development guide
// Import the library
import Parsec from './js/equations_parser_wrapper.js'
// Initialize WebAssembly module
const parsec = new Parsec()
await parsec.initialize()
// Evaluate equations
const result = parsec.eval('2 + 3 * 4') // Returns: 14
const trig = parsec.eval('sin(pi/2)') // Returns: 1
const complex = parsec.eval('real(3+4i)') // Returns: 3
const string = parsec.eval('concat("a","b")') // Returns: "ab"// All tests follow this pattern
class SomeTests {
constructor(testRunner) {
this.testRunner = testRunner
}
async runTests() {
const result = await this.testRunner.evaluate('some_equation')
this.testRunner.assertEqual(result, expected, 'Test description')
}
}- Make Changes: Edit C++, JavaScript, or test files
- Rebuild WASM:
./build.sh(if C++ changed) - Run Tests:
npm test(verify functionality) - Fix Issues: Address any failing tests
- Lint Code:
npm run lint(maintain code quality) - Update Docs: Keep README.md and CLAUDE.md current
- Module Loading: Ensure proper ES6 module paths
- WebAssembly Path: Check WASM file path resolution
- Import Errors: Verify proper import/export statements
- Test Failures: Use
npm run test:watchfor iterative debugging
# Detailed test output
npm test -- --reporter verbose
# Run single test file
npm test -- arithmetic.test.js
# Debug mode with console output
npm test -- --reporter verbose --silent falseThis guide serves as the definitive reference for Parsec Web development, focusing on the modern testing approach and cross-platform generalization goals.
When prompted with "draft a pull request":
-
Analyze changes
- Compare everything done on the current branch against
main. - Summarize all relevant commits, file modifications, and key impacts.
- Compare everything done on the current branch against
-
Create a Markdown draft
- Produce content that can be pasted directly into the PR title and description fields.
- Structure the description with the template imported below: @status-survey2/.github/pull_request_template.md
- Enhance clarity with markdown code fences with language tags, colors, tables, blockquotes for callouts, admonitions (GitHub alerts), mermaid diagrams, images, collapsible details and etc.
-
Write the Test Guidance section
- Assume the tester has minimal backend or API knowledge.
- Describe step-by-step checks performed purely through the frontend—mouse clicks, typing, and other UI interactions.
-
Generate a Markdown file
- Generate a
pull_request.mdfile containing the Pull Request title and description
- Generate a