JSPM

  • Created
  • Published
  • Downloads 516
  • Score
    100M100P100Q111063F
  • License MIT

A wasm based clang-format

Package Exports

  • @wasm-fmt/clang-format
  • @wasm-fmt/clang-format/package.json
  • @wasm-fmt/clang-format/vite

Readme

Test

Install

npm

npm install @wasm-fmt/clang-format

jsr.io

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.

Build from source

  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. Clone this repository.
  5. Run scrips/build.sh.