Node.js/TypeScript API Guide

Complete guide to using MathHook from Node.js and TypeScript via NAPI bindings. Provides comprehensive documentation for the JavaScript/TypeScript API including installation, quick start, API reference, integration patterns with Express/Next.js, and performance best practices.

Code Examples

Basic Parsing and Simplification

Parse mathematical expressions from strings and simplify them

use mathhook::{expr, symbol, simplify, expand};

let x = symbol!(x);
let expr = expr!(x + x);
let result = simplify(expr);  // 2*x

let expr2 = expr!((x + 1)^2);
let expanded = expand(expr2);  // x^2 + 2*x + 1

TypeScript Type Safety

Use TypeScript for type-safe mathematical operations

Derivatives in TypeScript

Compute symbolic derivatives with TypeScript type safety

use mathhook::{expr, symbol, derivative};

let x = symbol!(x);
let expr = expr!(x^3);

// First derivative
let df = derivative(&expr, &x, 1);
// Result: 3*x^2

// Second derivative
let d2f = derivative(&expr, &x, 2);
// Result: 6*x

Express.js API Integration

Build a REST API for mathematical operations using Express.js

Next.js Server Actions

Use MathHook in Next.js server actions for server-side computation

WebSocket Server

Build a WebSocket server for real-time mathematical computation

Evaluation with Context

Advanced evaluation with custom contexts and variable substitutions

🔗 Related Topics