--- title: "@cmtx/autocorrect-wasm" lang: en skip_doc_render: true --- # @cmtx/autocorrect-wasm [![npm version](https://img.shields.io/npm/v/@cmtx/autocorrect-wasm.svg)](https://www.npmjs.com/package/@cmtx/autocorrect-wasm) [![License](https://img.shields.io/npm/l/@cmtx/autocorrect-wasm.svg)](https://github.com/cc01cc/cmtx-project/blob/main/LICENSE) AutoCorrect WASM bindings for CMTX — WebAssembly text auto-correction module compiled from the Rust `autocorrect` crate. > Full API documentation: `pnpm run docs` (generated in `docs/api/`) ## 1. Installation ```bash pnpm add @cmtx/autocorrect-wasm ``` ## 2. Usage ```typescript import { loadWASM, format } from "@cmtx/autocorrect-wasm"; await loadWASM(); const result = format("学习如何用Rust构建Application"); console.log(result); // "学习如何用 Rust 构建 Application" ``` ## 3. API | Function | Description | |----------|-------------| | `loadWASM(options?)` | Load the WASM module (async, idempotent) | | `isWasmLoaded()` | Check if WASM has been loaded | | `format(text)` | Auto-correct text format | | `formatFor(text, filetype)` | Format according to the specified file type | | `lintFor(text, filetype)` | Check format issues according to the specified file type | | `loadConfig()` | Load autocorrect configuration | | `Ignorer` | `.gitignore`-style path matching class | ## 4. File Type Formatting ```typescript import { loadWASM, formatFor, lintFor } from "@cmtx/autocorrect-wasm"; await loadWASM(); // Format according to Markdown rules const md = formatFor("##标题", "markdown"); // Check format issues const issues = lintFor("hello,world", "text"); ``` ## 5. Build ```bash pnpm build # Build WASM package pnpm test # Run tests pnpm run docs # Generate API documentation ```