prettierx

raw JSON →
0.19.0 verified Sat Apr 25 auth: no javascript maintenance

prettierx (v0.19.0) is a less opinionated fork of Prettier, offering additional formatting options that align with Standard JS and semistandard. It provides CLI usage and can be used as a standalone formatter or via a plugin. Unlike Prettier, prettierx includes options like `alignObjectProperties`, `offsetTernaryExpressions`, `spaceBeforeFunctionParen`, and `breakBeforeElse`. It requires Node >=12.17.0 and is currently in active maintenance with irregular release cadence. The package is ESM-only for programmatic use but provides a CommonJS-compatible CLI.

error Cannot find module 'prettierx'
cause Trying to require('prettierx') in a CommonJS project.
fix
Use import('prettierx') or switch to ES modules.
error Error: Invalid option: 'alignObjectProperties'
cause Using an option that does not exist in Prettier or older prettierx version.
fix
Ensure you are using prettierx, not Prettier, and update to a version that supports the option (>=0.14.0).
error TypeError: prettierx.format is not a function
cause Importing wrong export (default vs named).
fix
Use import { format } from 'prettierx' instead of default import.
error Error: Cannot use 'import.meta' outside a module
cause Trying to use prettierx programmatically without 'type': 'module' in package.json or without .mjs extension.
fix
Add 'type': 'module' to your package.json or use .mjs extension for your script.
breaking prettierx 0.14.0 dropped support for Node <12 and switched to using Babel for TypeScript parsing by default.
fix Upgrade to Node >=12.17.0 and update any TypeScript parser configuration.
deprecated Option `--no-align-ternary-lines` was replaced with `--offset-ternary-expressions` in v0.17.0.
fix Use `--offset-ternary-expressions` or `offsetTernaryExpressions: true` instead.
deprecated Options `--no-bracket-spacing` and `--paren-spacing` were replaced with finer-grained options in v0.17.0.
fix Use specific spacing options like `--array-bracket-spacing`, `--computed-property-spacing`, etc.
gotcha Some options like `arrayBracketSpacing`, `cssParenSpacing`, `computedPropertySpacing`, `spaceInParens`, `spaceUnaryOps`, `templateCurlySpacing`, `typeAngleBracketSpacing`, `typeBracketSpacing` are experimental with limited testing and may produce unexpected formatting.
fix Test thoroughly before enabling experimental options in production.
gotcha The `--import-formatting oneline` option may conflict with VSCode's Organize Imports feature.
fix Use `importFormatting: 'auto'` or disable VSCode Organize Imports if using `oneline`.
gotcha prettierx is ESM-only for programmatic use; `require('prettierx')` will throw an error.
fix Use `import` statements or `dynamic import()`.
npm install prettierx
yarn add prettierx
pnpm add prettierx

Demonstrates using prettierx programmatically with additional options like alignObjectProperties and spaceBeforeFunctionParen.

import { format } from 'prettierx';

const code = `const foo = {a:1,b:2}`;
const options = {
  alignObjectProperties: true,
  spaceBeforeFunctionParen: true
};
const formatted = format(code, { parser: 'babel', ...options });
console.log(formatted);
// Output:
// const foo = {
//   a: 1,
//   b: 2
// };