{"id":19065462,"url":"https://github.com/menci/wastyle","last_synced_at":"2025-04-28T11:28:12.881Z","repository":{"id":44211344,"uuid":"244850897","full_name":"Menci/wastyle","owner":"Menci","description":"AStyle code formatter compiled to WebAssembly, for Node.js and the browser.","archived":false,"fork":false,"pushed_at":"2023-07-18T21:09:12.000Z","size":586,"stargazers_count":19,"open_issues_count":8,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-18T15:17:31.831Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Menci.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-04T08:50:31.000Z","updated_at":"2025-02-06T09:22:31.000Z","dependencies_parsed_at":"2024-06-19T05:56:51.901Z","dependency_job_id":"a9151715-431d-4d04-aaa7-71f133b36e25","html_url":"https://github.com/Menci/wastyle","commit_stats":{"total_commits":18,"total_committers":2,"mean_commits":9.0,"dds":0.05555555555555558,"last_synced_commit":"832a4ecc75cb81d6b57494d7830617979579fff6"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Menci%2Fwastyle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Menci%2Fwastyle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Menci%2Fwastyle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Menci%2Fwastyle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Menci","download_url":"https://codeload.github.com/Menci/wastyle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251304081,"owners_count":21567805,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T00:50:04.281Z","updated_at":"2025-04-28T11:28:12.862Z","avatar_url":"https://github.com/Menci.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WAstyle\nAStyle code formatter compiled to WebAssembly, for Node.js and the browser.\n\n[![Build Status](https://img.shields.io/travis/Menci/wastyle?style=flat-square)](https://travis-ci.org/Menci/wastyle)\n[![Dependencies](https://img.shields.io/david/Menci/wastyle?style=flat-square)](https://david-dm.org/Menci/wastyle)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square)](http://commitizen.github.io/cz-cli/)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)\n[![License](https://img.shields.io/github/license/Menci/wastyle?style=flat-square)](LICENSE)\n\n# Install\nInstall via NPM:\n\n```bash\n$ yarn add wastyle\n```\n\n# Usage\nFirstly, you need to initialize AStyle WASM library with `init` function.\n\nUnfortunately this step couldn't be done automatically since you need make Webpack emit the AStyle WASM binary to your dist directory and tell us its URL. Since we support running in browser mainly, so I don't want to write code to detect Node.js to increase your Webpack bundle size. So in both Node.js and Webpack this step must be done.\n\nIn Node.js, call `init` with a `Buffer` from `fs.readFile` or `fs.readFileSync`:\n\n```javascript\nconst fs = require(\"fs\");\nconst util = require(\"util\");\nconst wastyle = require(\"wastyle\");\n\nutil.promisify(fs.readFile)(\"wastyle/dist/astyle.wasm\")\n.then(data =\u003e wastyle.init(data))\n.then(() =\u003e console.log(\"WAstyle is ready!\"))\n.catch(err =\u003e console.error(err));\n```\n\nIn Webpack, I recommend you to use [`file-loader`](https://webpack.js.org/loaders/file-loader/) to emit the AStyle WASM binary to your dist directory and get its URL. See [NeekSandhu/onigasm#2](https://github.com/NeekSandhu/onigasm/issues/2).\n\nNote that Webpack has a very simple built-in WASM loader, which will load a WASM file (detected by its magic header) as a compiled and instantiated WASM instance. But it doesn't support passing imports to WASM module. So it WILL fail since the AStyle WASM binary needs [WASI](https://wasi.dev/) to run. To disable the build-in WASM loader and force `file-loader` to produce the file URL, use this rule: ([webpack/webpack#6725](https://github.com/webpack/webpack/issues/6725))\n\n```javascript\n{\n  test: /\\.wasm$/,\n  loader: \"file-loader\",\n  type: \"javascript/auto\"\n}\n```\n\nIn your code, initialize WAstyle with:\n\n```javascript\nimport { init, format } from \"wastyle\";\nimport astyleBinaryUrl from \"wastyle/dist/astyle.wasm\";\n\ninit(astyleBinaryUrl).then(() =\u003e console.log(\"WAstyle is ready!\"));\n```\n\nThe `init` function will compile and instantiate the Astyle WASM binary asynchronously. Will throw an error if failed.\n\nAfter initialization, call the synchronous function `format` to use Astyle:\n\n```javascript\nconst [success, result] = format(\"#include \u003ccstdio\u003e\\nint main(){int 🦄,a,*b=a,c=🦄*2,*d=nullptr;return -1;}\", \"pad-oper style=google\");\nconsole.log(result);\n// #include \u003ccstdio\u003e\n// int main() {\n//     int 🦄, a, *b = a, c = 🦄 * 2, *d = nullptr;\n//     return -1;\n// }\n```\n\nBesides, you can use `wastyle/dist/astyle-optimize-size.wasm` to reduce your Webpack dist's size.\n\n# Performance\nTested on Chrome 80.0.3987.122 on an i7-6600U laptop, formatting [this](https://paste.ubuntu.com/p/NtGx85z9BK/) C++ file takes 15ms with `wastyle/dist/astyle.wasm` and 40ms with `wastyle/dist/astyle-optimize-size.wasm` in average of 100 samples.\n\n# Development\nYou'll need `emcc` to build the Astyle WASM binary. Follow [this guide](https://emscripten.org/docs/getting_started/downloads.html) to install it.\n\n```bash\n$ yarn build      # Build TypeSrript\n$ yarn build:wasm # Build WASM\n```\n\n# License\nThis project is licensed under the MIT license.\n\nAstyle code formatter (Artistic Style) is also licensed under the MIT license. You can find its [license](astyle/LICENSE.md) in the [`astyle`](astyle) folder.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmenci%2Fwastyle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmenci%2Fwastyle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmenci%2Fwastyle/lists"}