Skip to content

Latest commit

 

History

History
141 lines (91 loc) · 3.39 KB

01-clang-format-node.md

File metadata and controls

141 lines (91 loc) · 3.39 KB

clang-format-node

NPM Version Node Current

Repository | npm

Node wrapper for clang-format native binary inspired by angular/clang-format. (The CORE package.)

Installation

If you want to use clang-format without git-clang-format, simply follow the installation guide below. If you need git-clang-format, refer to the clang-format-git or clang-format-git-python.

global

npm install -g clang-format-node
yarn global add clang-format-node
pnpm add -g clang-format-node
bun add -g clang-format-node

local(devDependencies)

npm install --save-dev clang-format-node
yarn add --dev clang-format-node
pnpm add -D clang-format-node
bun add -d clang-format-node

Usage

You can use the commands below to run clang-format.

clang-format-node is an alias for clang-format and works in exactly the same way.

npx clang-format
npx clang-format-node

Node.js APIs

These APIs depends on the Node.js fs and path module and the file system, so you cannot use it in browsers.

  • CommonJS

    const {
      clangFormatPath,
      clangFormatNodePath,
      getClangFormatPath,
      getClangFormatNodePath
    } = require('clang-format-node');
  • ES Modules

    import {
      clangFormatPath,
      clangFormatNodePath,
      getClangFormatPath,
      getClangFormatNodePath
    } from 'clang-format-node';

clangFormatPath

The ABSOLUTE path to the clang-format executable binary based on the OS platform and architecture.

Alias and Version

clangFormatNodePath

Alias for clangFormatPath.

Alias and Version

  • Alias: clangFormatPath. See clangFormatPath.
  • Version: v1.2.0 Initial release.

getClangFormatPath

Returns the ABSOLUTE path to the clang-format executable binary based on the OS platform and architecture.

The possible combinations are darwin-arm64, darwin-x64, linux-arm, linux-arm64, linux-ppc64, linux-s390x, linux-x64, win32-x64.

Throws an error if the executable is not found.

Parameters

  • osPlatform (string): The current operating system platform. (e.g., darwin, linux, win32)
  • architecture (string): The current system architecture. (e.g., arm, arm64, ppc64, s390x, x64)

Returns

  • string: The absolute path to the clang-format executable binary.

Throws

  • Error: Throws an error if the executable binary is not found for the specified OS platform and architecture.

Alias and Version

getClangFormatNodePath

Alias for getClangFormatPath.

Alias and Version