Registry / testing / code-formatter

code-formatter

JSON →
library0.0.2jsnpmunverified

A lightweight code formatter supporting JavaScript, HTML, CSS, JSON, XML, and SQL with landscaping and compression. Current stable version: 0.0.2. Released irregularly; no major updates since initial publish. Key differentiator: minimal API and support for multiple languages, but limited configurability compared to Prettier or ESLint. Ships TypeScript types.

npm install code-formatter
INSTALL
IMPORT
SIG · CODE-FORMATTER
C
code-formatter
testingjavascriptv0.0.2
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.

formatter
✓ import formatter from 'code-formatter'
✗ import { formatter } from 'code-formatter'
Default export only; named import will fail.
formatter
✓ const formatter = require('code-formatter')
✗ const { formatter } = require('code-formatter')
CommonJS: use default require with no destructuring.
formatter
✓ import type { FormatterOptions } from 'code-formatter'
✗ import { FormatterOptions } from 'code-formatter'
TypeScript: options type is exported as named export, but the main function is default.

Formats a JSON string with indentation options using the default export.

import formatter from 'code-formatter'; const content = `{"name":"ilex","identifier":"ac1bf435","_test":{"say":"hello","run":"fast"}}`; const result = formatter(content, { method: 'json', step: ' ', preserveComments: false, tabsize: 2, tabchar: ' ' }); console.log(result);
Debug
Known issues
deprecatedThe option 'preserveComments' only applies to cssmin and xmlmin functions; may be removed in future versions.
fix
Avoid using preserveComments for non-CSS/XML methods.
affects: >=0.0.0
gotchaImporting via named import 'formatter' will result in undefined; use default import.
fix
Use `import formatter from 'code-formatter'` instead of `import { formatter } from 'code-formatter'`.
affects: >=0.0.0
gotchaThe 'method' option is case-sensitive; use lowercase strings like 'json', 'html', 'css', 'xml', 'sql'.
fix
Ensure method is lowercase.
affects: >=0.0.0
breakingVersion 0.0.2 is the only version; no breaking changes documented.
fix
N/A
affects: 0.0.2
Errors
Common errors & fixes
TypeError: formatter is not a function
Named import used instead of default import.
fix
Replace `import { formatter } from 'code-formatter'` with `import formatter from 'code-formatter'`.
Cannot find module 'code-formatter'
Package not installed or missing from node_modules.
fix
Install package: `npm install code-formatter`.
UnhandledPromiseRejectionWarning: TypeError: content.replace is not a function
Passed non-string content to formatter.
fix
Ensure content is a string before passing to formatter.
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
code-formatter — npm install code-formatter · libregistry