editorconfig-to-prettier
raw JSON → 1.0.0 verified Sat Apr 25 auth: no javascript
Converts an editorconfig-parsed object to a Prettier configuration object. This package bridges EditorConfig settings (like indentation, line endings, and max line length) into equivalent Prettier options. The current stable version is 1.0.0, with no recent releases. It is a small utility with zero dependencies, primarily used in build tools that combine EditorConfig with Prettier. Key differentiator: it automates the mapping between both standards, reducing manual configuration duplication. Suitable for Node.js environments, released as a CommonJS module.
Common errors
error Uncaught TypeError: editorconfigToPrettier is not a function ↓
cause Named import used instead of default import.
fix
Change to: import editorconfigToPrettier from 'editorconfig-to-prettier'
error Cannot find module 'editorconfig-to-prettier' ↓
cause Package not installed or missing from node_modules.
fix
Run: npm install editorconfig-to-prettier
error Unexpected token: export ↓
cause Using ESM import without enabling ESM in Node.js or using a bundler.
fix
Add 'type': 'module' to package.json or use require() instead.
Warnings
gotcha Function returns a Prettier configuration object only for known EditorConfig keys; unknown keys are ignored. ↓
fix Ensure your EditorConfig properties are supported (indent_style, indent_size, tab_width, end_of_line, max_line_length, insert_final_newline).
gotcha The conversion is one-way; you cannot convert Prettier config back to EditorConfig. ↓
fix Use separate tools for reverse conversion if needed.
gotcha Boolean EditorConfig values are not supported (e.g., trim_trailing_whitespace); only string qualifiers are read. ↓
fix Handle boolean values manually or use a more comprehensive converter.
gotcha No TypeScript type declarations included; users must add their own or rely on inference. ↓
fix Consider using @types/editorconfig-to-prettier if available, or declare module manually.
Install
npm install editorconfig-to-prettier yarn add editorconfig-to-prettier pnpm add editorconfig-to-prettier Imports
- default wrong
import { editorconfigToPrettier } from 'editorconfig-to-prettier'correctimport editorconfigToPrettier from 'editorconfig-to-prettier' - default (require)
const editorconfigToPrettier = require('editorconfig-to-prettier') - type
import type { EditorConfigToPrettier } from 'editorconfig-to-prettier'
Quickstart
import editorconfig from 'editorconfig';
import editorconfigToPrettier from 'editorconfig-to-prettier';
const filePath = '/path/to/your/file.js';
const config = await editorconfig.parse(filePath);
const prettierOptions = editorconfigToPrettier(config);
console.log(prettierOptions);
// => { tabWidth: 4, useTabs: false, printWidth: 80, endOfLine: 'lf', semi: true, singleQuote: false, trailingComma: 'none', bracketSpacing: true }