{"library":"prettier","title":"Prettier Code Formatter","description":"Prettier is an opinionated code formatter that enforces a consistent style across various programming languages by parsing code and re-printing it with its own rules, taking maximum line length into account. This approach minimizes bikeshedding over style in code reviews. The current stable version is 3.8.3, with releases occurring frequently for patch updates, and minor versions typically every 1-3 months, as observed from the changelog (e.g., 3.7.0 in Nov 2025, 3.8.0 in Jan 2026). Key differentiators include its strong opinionation, wide language support through a robust plugin ecosystem, and seamless integration with editors, pre-commit hooks, and CI/CD pipelines to maintain codebase consistency without manual intervention.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install prettier"],"cli":{"name":"prettier","version":null}},"imports":["import { format } from 'prettier';","import { resolveConfig } from 'prettier';","import { check } from 'prettier';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { format, resolveConfig } from 'prettier';\nimport * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\n\nasync function formatFile(filePath: string) {\n  const fileContent = await fs.readFile(filePath, 'utf8');\n  const config = await resolveConfig(filePath);\n\n  if (!config) {\n    console.warn(`No Prettier config found for ${filePath}. Using default options.`);\n  }\n\n  const formattedContent = await format(fileContent, {\n    ...config,\n    filepath: filePath, // Essential for Prettier to infer parser and apply file-specific overrides\n  });\n\n  console.log(`Original content of ${filePath}:\\n---\\n${fileContent}\\n---`);\n  console.log(`Formatted content of ${filePath}:\\n---\\n${formattedContent}\\n---`);\n\n  // To write back to file:\n  // await fs.writeFile(filePath, formattedContent, 'utf8');\n  // console.log(`Formatted ${filePath} and wrote changes.`);\n}\n\n// Create a dummy file for demonstration\nasync function setupAndRun() {\n  const dummyFilePath = path.join(process.cwd(), 'temp-example.ts');\n  const unformattedCode = `\nconst    myVariable  =  \"hello world\";\nfunction  sayHello(name: string)  { console.log('Hello, ' + name );}\n  sayHello (myVariable)\n`;\n  await fs.writeFile(dummyFilePath, unformattedCode, 'utf8');\n  console.log(`Created unformatted file: ${dummyFilePath}`);\n\n  await formatFile(dummyFilePath);\n\n  // Clean up\n  await fs.unlink(dummyFilePath);\n  console.log(`Cleaned up ${dummyFilePath}`);\n}\n\nsetupAndRun().catch(console.error);\n","lang":"typescript","description":"Demonstrates how to programmatically format a TypeScript file using Prettier's `format` and `resolveConfig` APIs, including critical `filepath` inference.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}