{"id":42287,"library":"wastyle","title":"WAstyle","description":"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.","status":"active","version":"0.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/Menci/wastyle","tags":["javascript"],"install":[{"cmd":"npm install wastyle","lang":"bash","label":"npm"},{"cmd":"yarn add wastyle","lang":"bash","label":"yarn"},{"cmd":"pnpm add wastyle","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM import is preferred. In Node.js, init expects a Buffer from reading the wasm file, while in browsers it expects a URL string.","wrong":"const init = require('wastyle').init","symbol":"init","correct":"import { init } from 'wastyle'"},{"note":"format is a named export, not default. It is synchronous but must be called after init completes.","wrong":"import format from 'wastyle'","symbol":"format","correct":"import { format } from 'wastyle'"}],"quickstart":{"code":"// Node.js quickstart\nimport { init, format } from 'wastyle';\nimport { readFile } from 'fs/promises';\nimport { fileURLToPath } from 'url';\nimport { dirname, join } from 'path';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\nconst wasmPath = join(__dirname, 'node_modules/wastyle/dist/astyle.wasm');\n\nconst wasmBuffer = await readFile(wasmPath);\nawait init(wasmBuffer);\n\nconst code = \"int main(){return 0;}\";\nconst [success, result] = format(code, \"style=google\");\nconsole.log(result);\n// Output:\n// int main() {\n//     return 0;\n// }","lang":"typescript","description":"Shows the required two-step process: initialize with WASM binary path, then call format with code and AStyle options."},"warnings":[{"fix":"Always await init(...) before calling format. Use try/catch or .catch on the promise.","message":"init must be called before format, and format will throw if not initialized","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Add { test: /\\.wasm$/, loader: 'file-loader', type: 'javascript/auto' } to webpack module.rules.","message":"Webpack may try to load .wasm files incorrectly if not configured","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Use fs.readFile for Node.js; use fetch or file-loader URL for browsers.","message":"In Node.js, init expects a Buffer, not a URL string. In browsers, it expects a URL string.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"This is by design; follow the manual init pattern described in the README.","message":"The package uses a custom init step rather than automatic WASM loading","severity":"deprecated","affected_versions":">=0.0.1"},{"fix":"Always destructure the array: const [success, result] = format(...);","message":"format returns an array [success, result]; success is boolean, result is string or error message","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"search_vec":"'0.0.5':27 'astyl':9,35 'binari':52,69 'bind':36 'browser':21 'c':13,14 'code':10 'configur':83 'cross':42 'cross-platform':41 'current':23 'due':53 'enabl':12 'file':75 'format':17,60 'formatt':11 'initi':48,62,79 'java':16 'javascript':90 'licens':32 'limit':56 'manual':47 'mit':31 'nativ':34 'new':88 'node.js':19 'offer':64 'optim':66 'perform':70 'platform':43 'port':6 'portabl':44 'releas':28 'requir':46 'size':76 'smaller':67 'stabl':24 'step':80 'suitabl':72 'support':58 'synchron':59 'tricki':86 'typic':74 'unlik':33 'use':38 'user':89 'version':25 'wasm':39,51,68 'wastyl':1,2,37 'webassembl':5 'webpack':55,82","created_at":"2026-06-04T18:56:31.509111+00:00","updated_at":"2026-06-04T18:56:31.509111+00:00","problems":[{"fix":"Ensure you await init() before calling format(). Store a promise and check it.","cause":"Calling format before init has completed","error":"Error: WAstyle is not initialized"},{"fix":"Read the .wasm file with fs.readFile and pass the Buffer.","cause":"Passed a URL string to init in Node.js","error":"Failed to load wasm: Expected a buffer-like argument"},{"fix":"Disable the default loader as shown in the README: add rule with type: 'javascript/auto' and file-loader.","cause":"Webpack's built-in WASM loader tries to parse the .wasm file","error":"Webpack: Module parse failed: Unexpected character"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/Menci/wastyle","github":"https://github.com/Menci/wastyle","docs":null,"changelog":null,"pypi":null,"npm":"wastyle","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}