Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wasm-fmt/clang-format
A WASM Based Clang Format | C / C++ / C# / Objective-C / Java / Protobuf
https://github.com/wasm-fmt/clang-format
clang-format formatter formatting wasm web webassembly
Last synced: 3 months ago
JSON representation
A WASM Based Clang Format | C / C++ / C# / Objective-C / Java / Protobuf
- Host: GitHub
- URL: https://github.com/wasm-fmt/clang-format
- Owner: wasm-fmt
- License: mit
- Created: 2023-08-13T02:42:01.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-30T11:30:44.000Z (4 months ago)
- Last Synced: 2024-11-06T17:09:37.776Z (4 months ago)
- Topics: clang-format, formatter, formatting, wasm, web, webassembly
- Language: C++
- Homepage:
- Size: 2.18 MB
- Stars: 11
- Watchers: 1
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/wasm-fmt/clang-format/actions/workflows/test.yml)
# Install
[](https://www.npmjs.com/package/@wasm-fmt/clang-format)
```bash
npm install @wasm-fmt/clang-format
```[](https://jsr.io/@fmt/clang-format)
```bash
npx jsr add @fmt/clang-format
```# Usage
## CLI
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## API
```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](https://clang.llvm.org/docs/ClangFormatStyleOptions.html) for more information.
# Build from source
1. Install [LLVM](https://llvm.org/docs/GettingStarted.html) and [Clang](https://clang.llvm.org/get_started.html) (version 18 or later).
2. Install [CMake](https://cmake.org/download/) (version 3.27 or later).
3. Install [Ninja](https://ninja-build.org/) (version 1.11 or later).
4. Clone this repository.
5. Run scripts/build.sh.