npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

kotlin-format

v0.0.12

Published

Kotlin formatter aligned with ktfmt, powered by WebAssembly with a Node.js CLI.

Readme

kotlin-format

A Kotlin formatter aligned with ktfmt, powered by WebAssembly with a Node.js CLI. It formats .kt and .kts files without a JVM, Gradle or Kotlin installation. The parser is included in the WASM build; installing kotlin-parser separately is unnecessary.

Installation

pnpm add -D kotlin-format

The package is ESM-only and includes TypeScript declarations. The CLI and native TypeScript configuration loading are tested with Node 26.12.1.

Command line

# Rewrite Kotlin files in a directory.
pnpm exec kotlin-format src --write

# Check formatting in CI without rewriting files.
pnpm exec kotlin-format . --check

# Select a style and line width.
pnpm exec kotlin-format "src/**/*.kt" --style KOTLINLANG --max-width 120 --write

# Print a formatted file to stdout.
pnpm exec kotlin-format src/Main.kt

pnpm exec kotlin-format --help

The CLI accepts files, directories and glob patterns. Directory scans respect nested .gitignore rules and skip symlinks, .git and node_modules. With --write or --check and no paths, it scans the current directory. Without either flag, provide one file or pipe source through stdin.

For stdin, --stdin-filepath determines the configuration search location and whether to parse a script. For example, in a shell supporting input redirection:

pnpm exec kotlin-format --stdin-filepath src/Main.kt < src/Main.kt

Exit codes: 0 for success, 1 for formatting differences with --check, 2 for invalid arguments, configuration, source syntax or I/O errors. --write and --check cannot be combined.

Configuration

Create kotlin-format.json:

{
  "style": "KOTLINLANG",
  "maxWidth": 100,
  "removeUnusedImports": true,
  "preserveLambdaBreaks": true
}

Or use kotlin-format.config.ts with editor type checking:

import type { FormatConfig } from 'kotlin-format/config';

export default {
  style: 'KOTLINLANG',
  maxWidth: 120,
  removeUnusedImports: false,
  preserveLambdaBreaks: true,
} satisfies FormatConfig;

kotlin-format.config.js and kotlin-format.config.mjs are also supported. Module configs are ESM-only and must default-export an object. JS/TS follow Node's module rules; use "type": "module" in the project or .mjs for an explicit ESM entry. TS uses native type stripping, with no transpiler, tsconfig path aliases or runtime type checking. CommonJS, .cjs and JSONC are not supported.

| Option | Default | Values | | --- | --- | --- | | style | KOTLINLANG | KOTLINLANG, GOOGLE, META | | maxWidth | 100 | Integer from 1 to 999 | | removeUnusedImports | true | Boolean | | preserveLambdaBreaks | true | Boolean |

Configuration is discovered per source file, searching upward to the nearest package.json or .git directory, or the filesystem root. The nearest config wins; parents are not merged. Multiple supported configs in one directory are an error. Use --config path to select a config explicitly. CLI flags override config values, then defaults apply. Boolean overrides include --no-remove-unused-imports and --no-preserve-lambda-breaks.

The Kotlin Syntax VS Code extension reads the same configuration. Project options override corresponding editor settings; executable configs require workspace trust. Config entry changes are picked up on the next format; restart the editor after changing imported helper modules.

JavaScript API

import { formatCode } from 'kotlin-format/wasm';

const result = formatCode('fun f(){println(42)}', 'KOTLINLANG', 100, false);
console.log(result);
// fun f() {
//     println(42)
// }

All four arguments are required: source, style, width and script mode (true for .kts). Importing this entry initializes WASM; formatting is synchronous afterward. Use await import('kotlin-format/wasm') for lazy loading.

For configuration-driven formatting:

import { loadConfig, resolveOptions } from 'kotlin-format/config';
import { formatWithOptions } from 'kotlin-format/wasm';

const options = resolveOptions(await loadConfig('/path/to/Main.kt'));
const result = formatWithOptions(
  'val answer=42',
  options.maxWidth, options.blockIndent, options.continuationIndent,
  options.trailingCommas, options.removeUnusedImports,
  options.preserveLambdaBreaks, false,
);
console.log(result);

The Node-specific kotlin-format/config entry does not load WASM. There is no root package export.

Formatting behavior

The current baseline is ktfmt 0.65 with the project's Kotlin 2.4.21 parser. Formatting operates on whole documents, preserves the source line-ending convention and rejects malformed syntax. Import removal is syntactic, not compiler-based; operator imports such as getValue and setValue are conservatively retained.

Each invocation performs one formatting pass. A small set of inputs changes again on a second pass in upstream ktfmt; this package preserves that behavior rather than repeatedly formatting until stable. See formatting details and upstream alignment.

Apache-2.0. See upstream attribution. Report issues in the project repository.