Registry / devops / wastyle

wastyle

JSON →
library0.0.5jsnpmunverified

WAstyle is a WebAssembly port of the AStyle code formatter, enabling C, C++, and Java formatting in Node.js and browsers. The current stable version is 0.0.5, released with an MIT license. Unlike native AStyle bindings, WAstyle uses WASM for cross-platform portability, but requires manual initialization with the WASM binary due to Webpack limitations. It supports synchronous formatting after initialization and offers an optimized smaller WASM binary. Performance is suitable for typical file sizes, but the initialization step and Webpack configuration can be tricky for new users.

npm install wastyle
INSTALL
IMPORT
SIG · WASTYLE
W
wastyle
devopsjavascriptv0.0.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

init
import { init } from 'wastyle'
const init = require('wastyle').init
ESM import is preferred. In Node.js, init expects a Buffer from reading the wasm file, while in browsers it expects a URL string.
format
import { format } from 'wastyle'
import format from 'wastyle'
format is a named export, not default. It is synchronous but must be called after init completes.

Shows the required two-step process: initialize with WASM binary path, then call format with code and AStyle options.

// Node.js quickstart import { init, format } from 'wastyle'; import { readFile } from 'fs/promises'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const wasmPath = join(__dirname, 'node_modules/wastyle/dist/astyle.wasm'); const wasmBuffer = await readFile(wasmPath); await init(wasmBuffer); const code = "int main(){return 0;}"; const [success, result] = format(code, "style=google"); console.log(result); // Output: // int main() { // return 0; // }
Debug
Known issues
gotchainit must be called before format, and format will throw if not initialized
fix
Always await init(...) before calling format. Use try/catch or .catch on the promise.
affects: >=0.0.1
gotchaWebpack may try to load .wasm files incorrectly if not configured
fix
Add { test: /\.wasm$/, loader: 'file-loader', type: 'javascript/auto' } to webpack module.rules.
affects: >=0.0.1
gotchaIn Node.js, init expects a Buffer, not a URL string. In browsers, it expects a URL string.
fix
Use fs.readFile for Node.js; use fetch or file-loader URL for browsers.
affects: >=0.0.1
deprecatedThe package uses a custom init step rather than automatic WASM loading
fix
This is by design; follow the manual init pattern described in the README.
affects: >=0.0.1
gotchaformat returns an array [success, result]; success is boolean, result is string or error message
fix
Always destructure the array: const [success, result] = format(...);
affects: >=0.0.1
Errors
Common errors & fixes
Error: WAstyle is not initialized
Calling format before init has completed
fix
Ensure you await init() before calling format(). Store a promise and check it.
Failed to load wasm: Expected a buffer-like argument
Passed a URL string to init in Node.js
fix
Read the .wasm file with fs.readFile and pass the Buffer.
Webpack: Module parse failed: Unexpected character
Webpack's built-in WASM loader tries to parse the .wasm file
fix
Disable the default loader as shown in the README: add rule with type: 'javascript/auto' and file-loader.
Upgrade
Version history
0.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
wastyle — npm install wastyle · libregistry