Package Exports
- @wasm-fmt/clang-format
- @wasm-fmt/clang-format/package.json
- @wasm-fmt/clang-format/vite
Readme
Install
npm install @wasm-fmt/clang-format
npx jsr add @fmt/clang-format
Usage
import init, { format } from "@wasm-fmt/clang-format";
await init();
const source = `
#include <iostream>
using namespace std;
auto main() -> int{
std::cout << "Hello World!" << std::endl;
return 0;}
`;
// JSON/YAML representation of Clang-Format Style Options
const config = JSON.stringify({
BasedOnStyle: "Chromium",
IndentWidth: 4,
ColumnLimit: 80,
});
// or
const config2 = `---
BasedOnStyle: Chromium
IndentWidth: 4
ColumnLimit: 80
...
`;
const formatted = format(
source,
"main.cc",
config,
);
console.log(formatted);
The third argument of format
accepts either a JSON or YAML representation of Clang-Format Style Options.
See Clang-Format Style Options for more information.