Registry / devops / tsfmt
library0.2.5jsnpmunverified

tsfmt is an opinionated TypeScript and JavaScript code formatter using AST-based transformations to enforce structural consistency. Version 0.2.5 (stable) is actively maintained with irregular releases. It goes beyond Prettier by automatically sorting class members, organizing imports, ordering file declarations, and formatting package.json/tsconfig.json. Core opinions include double quotes, semicolons, 4-space indentation, 120-char line width, and trailing commas. Built on the TypeScript compiler API, it resolves dependencies to prevent breaking changes during reordering.

npm install tsfmt
INSTALL
IMPORT
SIG · TSFMT
T
tsfmt
devopsjavascriptv0.2.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

formatCode
import { formatCode } from 'tsfmt'
const formatCode = require('tsfmt').formatCode; // CJS still works
Default export also available as `formatCode`; this is the main entry point for formatting source code.
formatConfig
import { formatConfig } from 'tsfmt'
Used to format JSON configuration files like tsconfig.json or package.json.
FormatterOptions
import type { FormatterOptions } from 'tsfmt'
TypeScript type for formatting options. Only available when using TypeScript.

Demonstrates basic usage of formatCode to fix spacing and formatting in a TypeScript snippet.

import { formatCode } from 'tsfmt'; const code = `const x:number=1;`; const formatted = formatCode(code, { indentSize: 4, useTabs: false }); console.log(formatted); // Output: "const x: number = 1;"
Debug
Known issues
breakingNode.js >=22.0.0 required starting in v0.2.0
fix
Upgrade Node.js to version 22 or later.
affects: >=0.2.0
deprecatedDefault export removed in v0.2.0; use named import `formatCode` instead
fix
Replace `import tsfmt from 'tsfmt'` with `import { formatCode } from 'tsfmt'`.
affects: >=0.2.0
gotchaFormatter reorders code structurally; class member sorting can break module exports if order is assumed
fix
Review output for unintended reordering; disable sortClassMembers if needed.
affects: >=0.1.0
gotchaImport grouping with `importGroupOrder` may cause import statement splitting across multiple lines for long paths
fix
Adjust line width or disable import organization if splitting is undesirable.
affects: all
Errors
Common errors & fixes
Error: require() of ES Module /path/to/node_modules/tsfmt/dist/index.js not supported
tsfmt uses ESM but project is using CommonJS require()
fix
Use dynamic import: `import('tsfmt')` or convert to ESM.
TypeError: formatter(...).formatCode is not a function
Using wrong import pattern; default import is no longer a function
fix
Use named import: `import { formatCode } from 'tsfmt'`.
Cannot find module 'typescript'
tsfmt requires TypeScript as a peer dependency but it's not installed
fix
Run `npm install typescript`.
Upgrade
Version history
0.2.5latest on npm
Audit
Dependencies
typescriptrequiredRequires TypeScript compiler API for AST parsing and transformations
Agent activity
6 hits · last 30 days
node
6
Resources
packagetsfmt
tsfmt — npm install tsfmt · libregistry