{"id":19742200,"url":"https://github.com/wasm-fmt/clang-format","last_synced_at":"2026-04-13T06:20:46.574Z","repository":{"id":189556422,"uuid":"677898287","full_name":"wasm-fmt/clang-format","owner":"wasm-fmt","description":"A WASM Based Clang Format | C / C++ / C# / Objective-C / Java / Protobuf","archived":false,"fork":false,"pushed_at":"2024-10-30T11:30:44.000Z","size":2284,"stargazers_count":11,"open_issues_count":3,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-06T17:09:37.776Z","etag":null,"topics":["clang-format","formatter","formatting","wasm","web","webassembly"],"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/wasm-fmt.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":"2023-08-13T02:42:01.000Z","updated_at":"2024-10-30T11:30:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"99b80e90-56ac-42f0-b00b-63560ead7534","html_url":"https://github.com/wasm-fmt/clang-format","commit_stats":null,"previous_names":["wasm-fmt/clang-format"],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasm-fmt%2Fclang-format","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasm-fmt%2Fclang-format/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasm-fmt%2Fclang-format/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasm-fmt%2Fclang-format/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wasm-fmt","download_url":"https://codeload.github.com/wasm-fmt/clang-format/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224201540,"owners_count":17272594,"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":["clang-format","formatter","formatting","wasm","web","webassembly"],"created_at":"2024-11-12T01:29:35.550Z","updated_at":"2026-04-13T06:20:46.563Z","avatar_url":"https://github.com/wasm-fmt.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Test](https://github.com/wasm-fmt/clang-format/actions/workflows/test.yml/badge.svg)](https://github.com/wasm-fmt/clang-format/actions/workflows/test.yml)\n\n# Install\n\n[![npm](https://img.shields.io/npm/v/@wasm-fmt/clang-format?color=f34b7d)](https://www.npmjs.com/package/@wasm-fmt/clang-format)\n\n```bash\nnpm install @wasm-fmt/clang-format\n```\n\n[![jsr.io](https://jsr.io/badges/@fmt/clang-format?color=f34b7d)](https://jsr.io/@fmt/clang-format)\n\n```bash\nnpx jsr add @fmt/clang-format\n```\n\n# Usage\n\n## CLI\n\nThis repository contains 3 executable files, namely `clang-format`, `git-clang-format` and `clang-format-diff`.\nFor more information, please refer to https://clang.llvm.org/docs/ClangFormat.html\n\n## Node.js / Deno / Bun / Bundler\n\n```javascript\nimport { format } from \"@wasm-fmt/clang-format\";\n\nconst source = `\n#include \u003ciostream\u003e\nusing namespace std;\nauto main() -\u003e int{\nstd::cout \u003c\u003c \"Hello World!\" \u003c\u003c std::endl;\nreturn 0;}\n`;\n\n// JSON representation of Clang-Format Style Options\nconst config = JSON.stringify({\n\tBasedOnStyle: \"Chromium\",\n\tIndentWidth: 4,\n\tColumnLimit: 80,\n});\n\n// or YAML representation of Clang-Format Style Options which is used in `.clang-format` file\nconst config2 = `---\nBasedOnStyle: Chromium\nIndentWidth: 4\nColumnLimit: 80\n\n...\n`;\n\n// or the preset name\nconst config3 = \"Chromium\";\n\nconst formatted = format(source, \"main.cc\", config);\n\nconsole.log(formatted);\n```\n\nThe third argument of `format` is a Clang-Format Style Options, which can be one of the following:\n\n1. A preset: LLVM, GNU, Google, Chromium, Microsoft, Mozilla, WebKit.\n2. A YAML/JSON string representing the style options.\n3. the string content of a `.clang-format` file.\n\nSee [Clang-Format Style Options](https://clang.llvm.org/docs/ClangFormatStyleOptions.html) for more information.\n\n## Web\n\nFor web environments, you need to initialize WASM module manually:\n\n```javascript\nimport init, { format } from \"@wasm-fmt/clang-format/web\";\n\nawait init();\n\nconst source = `\n#include \u003ciostream\u003e\nusing namespace std;\nauto main() -\u003e int{\nstd::cout \u003c\u003c \"Hello World!\" \u003c\u003c std::endl;\nreturn 0;}\n`;\n\nconst formatted = format(source, \"main.cc\", \"Chromium\");\nconsole.log(formatted);\n```\n\n### Vite\n\n```JavaScript\nimport init, { format } from \"@wasm-fmt/clang-format/vite\";\n\nawait init();\n// ...\n```\n\n## Entry Points\n\n- `.` - Auto-detects environment (Node.js uses node, Webpack uses bundler, default is ESM)\n- `./node` - Node.js environment (no init required)\n- `./esm` - ESM environments like Deno (no init required)\n- `./bundler` - Bundlers like Webpack (no init required)\n- `./web` - Web browsers (requires manual init)\n- `./vite` - Vite bundler (requires manual init)\n\n# How does it work?\n\n[Clang-Format] is a tool to format C/C++/Java/JavaScript/TypeScript/Objective-C/Protobuf/C# code.\n\nThis package is a WebAssembly build of Clang-Format, with a JavaScript wrapper.\n\n[Clang-Format]: https://clang.llvm.org/docs/ClangFormat.html\n\n# Build from source\n\n1. Install [LLVM](https://llvm.org/docs/GettingStarted.html) and [Clang](https://clang.llvm.org/get_started.html) (version 18 or later).\n2. Install [CMake](https://cmake.org/download/) (version 3.27 or later).\n3. Install [Ninja](https://ninja-build.org/) (version 1.11 or later).\n4. Install [Emscripten](https://emscripten.org/docs/getting_started/downloads.html) (version 4.0.9).\n5. Clone this repository.\n6. Run scripts/build.sh.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwasm-fmt%2Fclang-format","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwasm-fmt%2Fclang-format","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwasm-fmt%2Fclang-format/lists"}