A wasm based clang-format
npm install @wasm-fmt/clang-format

``bash`
npm install @wasm-fmt/clang-format

`bash`
npx jsr add @fmt/clang-format
This repository contains two executable files, namely clang-format and git-clang-format.
For more information, please refer to https://clang.llvm.org/docs/ClangFormat.html
`JavaScript
import init, { format } from "@wasm-fmt/clang-format";
await init();
const source =
#include
using namespace std;
auto main() -> int{
std::cout << "Hello World!" << std::endl;
return 0;};
// JSON representation of Clang-Format Style Options
const config = JSON.stringify({
BasedOnStyle: "Chromium",
IndentWidth: 4,
ColumnLimit: 80,
});
// or YAML representation of Clang-Format Style Options which is used in .clang-format file---
const config2 =
BasedOnStyle: Chromium
IndentWidth: 4
ColumnLimit: 80
...;
// or the preset name
const config3 = "Chromium";
const formatted = format(
source,
"main.cc",
config,
);
console.log(formatted);
`
The third argument of format is a Clang-Format Style Options, which can be one of the following:
1. A preset: LLVM, GNU, Google, Chromium, Microsoft, Mozilla, WebKit.
2. A YAML/JSON string representing the style options.
3. the string content of a .clang-format` file.
See Clang-Format Style Options for more information.
1. Install LLVM and Clang (version 18 or later).
2. Install CMake (version 3.27 or later).
3. Install Ninja (version 1.11 or later).
4. Install Emscripten (version 4.0.9).
5. Clone this repository.
6. Run scripts/build.sh.