{"id":40735,"library":"code-formatter","title":"code-formatter","description":"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.","status":"active","version":"0.0.2","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","code","formatter","typescript"],"install":[{"cmd":"npm install code-formatter","lang":"bash","label":"npm"},{"cmd":"yarn add code-formatter","lang":"bash","label":"yarn"},{"cmd":"pnpm add code-formatter","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export only; named import will fail.","wrong":"import { formatter } from 'code-formatter'","symbol":"formatter","correct":"import formatter from 'code-formatter'"},{"note":"CommonJS: use default require with no destructuring.","wrong":"const { formatter } = require('code-formatter')","symbol":"formatter","correct":"const formatter = require('code-formatter')"},{"note":"TypeScript: options type is exported as named export, but the main function is default.","wrong":"import { FormatterOptions } from 'code-formatter'","symbol":"formatter","correct":"import type { FormatterOptions } from 'code-formatter'"}],"quickstart":{"code":"import formatter from 'code-formatter';\n\nconst content = `{\"name\":\"ilex\",\"identifier\":\"ac1bf435\",\"_test\":{\"say\":\"hello\",\"run\":\"fast\"}}`;\n\nconst result = formatter(content, {\n  method: 'json',\n  step: '  ',\n  preserveComments: false,\n  tabsize: 2,\n  tabchar: ' '\n});\n\nconsole.log(result);","lang":"typescript","description":"Formats a JSON string with indentation options using the default export."},"warnings":[{"fix":"Avoid using preserveComments for non-CSS/XML methods.","message":"The option 'preserveComments' only applies to cssmin and xmlmin functions; may be removed in future versions.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Use `import formatter from 'code-formatter'` instead of `import { formatter } from 'code-formatter'`.","message":"Importing via named import 'formatter' will result in undefined; use default import.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure method is lowercase.","message":"The 'method' option is case-sensitive; use lowercase strings like 'json', 'html', 'css', 'xml', 'sql'.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"N/A","message":"Version 0.0.2 is the only version; no breaking changes documented.","severity":"breaking","affected_versions":"0.0.2"}],"env_vars":null,"search_vec":"'0.0.2':23 'api':35 'code':2,6,53 'code-formatt':1 'compar':44 'compress':19 'configur':43 'css':11 'current':20 'differenti':33 'eslint':48 'formatt':3,7,54 'html':10 'initi':30 'irregular':25 'javascript':9,52 'json':12 'key':32 'landscap':17 'languag':40 'lightweight':5 'limit':42 'major':27 'minim':34 'multipl':39 'prettier':46 'publish':31 'releas':24 'ship':49 'sinc':29 'sql':15 'stabl':21 'support':8,37 'type':51 'typescript':50,55 'updat':28 'version':22 'xml':13","created_at":"2026-06-04T18:49:00.444768+00:00","updated_at":"2026-06-04T18:49:00.444768+00:00","problems":[{"fix":"Replace `import { formatter } from 'code-formatter'` with `import formatter from 'code-formatter'`.","cause":"Named import used instead of default import.","error":"TypeError: formatter is not a function"},{"fix":"Install package: `npm install code-formatter`.","cause":"Package not installed or missing from node_modules.","error":"Cannot find module 'code-formatter'"},{"fix":"Ensure content is a string before passing to formatter.","cause":"Passed non-string content to formatter.","error":"UnhandledPromiseRejectionWarning: TypeError: content.replace is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"code-formatter","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}