v7-formatter
v1.0.4
Published
A lightning-fast, zero-dependency, secure code formatter for JavaScript, TypeScript, HTML, CSS, JSON, and Markdown. Format entire directories or individual files with a single command. Safe formatting that never breaks your code.
Downloads
451
Maintainers
Keywords
Readme
🌟 Why V7 Formatter?
| Feature | V7 Formatter | Others | |---------|:---:|:---:| | Zero Dependencies | ✅ | ❌ | | Never Breaks Your Code | ✅ | ❌ | | No Network Requests | ✅ | ❌ | | No Code Execution | ✅ | ❌ | | Instant Install | ✅ | ❌ | | Totally Free & Open Source | ✅ | ✅ |
✨ Features
- ⚡ Lightning Fast — Zero dependencies, pure Node.js, formats 1000+ files in seconds
- 🔒 Top-Notch Security — No dependencies, no network, no eval, no code execution
- 🛡️ Never Breaks Your Code — Safe formatting with graceful error handling
- 📁 Directory Formatting — Recursively format entire project directories
- 🔧 Multi-Language — JavaScript, TypeScript, HTML, CSS, JSON, Markdown
- 🎯 CI/CD Ready — Check mode exits 1 for unformatted files
- ⚙️ Configurable —
.v7formatrcfor project-specific settings - 🚫 Ignore Support —
.v7ignorefile for excluding paths - 🖥️ CLI & API — Use from command line or programmatically
- 📦 Tiny Footprint — ~15 kB package size, instant install
- 🎨 Beautiful Output — Colored terminal output with IDE-clickable file paths and
git diffintegration - 🆓 100% Free — MIT License, open source forever
🚀 Quick Start
Install Globally
npm install -g v7-formatterInstall as Dev Dependency
npm install --save-dev v7-formatterUse Without Installing (npx)
npx v7-formatter .Format Your Project
# Format current directory
v7-formatter .
# Format specific directory
v7-formatter src/
# Format a single file
v7-formatter app.js
# Check if files are formatted (CI-friendly)
v7-formatter --check .📖 CLI Usage
v7-formatter [options] <files/directories...>Options
| Flag | Short | Description |
|------|-------|-------------|
| --help | -h | Show help message |
| --version | -v | Show version number |
| --check | -c | Check mode — don't write files, exit 1 if unformatted |
| --write | -w | Write mode (default) — format and save files |
| --init | | Create a .v7formatrc config file |
| --config <path> | | Path to custom config file |
| --indent-size <n> | | Indentation size (default: 2) |
| --use-tabs | | Use tabs instead of spaces |
| --single-quote | | Use single quotes (default) |
| --double-quote | | Use double quotes |
| --semicolons | | Add semicolons (default) |
| --no-semicolons | | Remove semicolons |
| --ext <exts> | | File extensions to process (comma-separated) |
Examples
# Format with tabs
v7-formatter --use-tabs .
# Format with double quotes, no semicolons
v7-formatter --double-quote --no-semicolons src/
# Format only JavaScript files
v7-formatter --ext js,jsx,ts,tsx .
# Check in CI pipeline (exits 1 if unformatted)
v7-formatter --check . || echo "Code needs formatting!"
# Initialize config
v7-formatter --init🔌 Programmatic API
const { format, formatFile, formatDirectory, check } = require('v7-formatter');
// Format a string
const formatted = format('function foo( ){return "hello" }', {
parser: 'javascript',
singleQuote: true,
semicolons: true,
});
// Output:
// function foo() {
// return 'hello';
// }
// Format a single file in-place
const result = formatFile('./src/app.js');
console.log(result.changed); // true or false
// Format an entire directory
const dirResult = formatDirectory('./src');
console.log(`Changed: ${dirResult.changed}, Unchanged: ${dirResult.unchanged}`);
// Check if files are formatted (no modifications)
const checkResult = check('./src');
if (!checkResult.isFormatted) {
console.log('Unformatted files:', checkResult.unformatted);
}API Reference
| Function | Parameters | Returns | Description |
|----------|-----------|---------|-------------|
| format(source, options) | source: string, options: { parser, ...config } | string | Format a source code string |
| formatFile(path, options?) | path: string, options?: object | { changed, filePath } | Format a file in-place |
| formatDirectory(path, options?) | path: string, options?: object | { total, changed, unchanged, errors } | Format all files in directory |
| check(path, options?) | path: string, options?: object | { isFormatted, unformatted[] } | Check formatting without changes |
| getSupportedExtensions() | none | string[] | List supported file extensions |
Supported Parsers: javascript, typescript, html, css, json, markdown
⚙️ Configuration
Create a .v7formatrc file in your project root:
v7-formatter --initOr manually:
{
"indentSize": 2,
"useTabs": false,
"singleQuote": true,
"semicolons": true,
"trailingNewline": true,
"maxConsecutiveBlankLines": 1,
"ignore": [
"node_modules",
"dist",
"build",
"coverage"
]
}All Configuration Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| indentSize | number | 2 | Spaces per indent level |
| useTabs | boolean | false | Use tabs instead of spaces |
| singleQuote | boolean | true | Single quotes in JS/TS |
| semicolons | boolean | true | Trailing semicolons in JS/TS |
| trailingNewline | boolean | true | Ensure file ends with newline |
| maxConsecutiveBlankLines | number | 1 | Max consecutive blank lines |
| sortKeys | boolean | false | Sort JSON object keys |
| listMarker | string | "-" | Markdown list marker |
| extensions | string[] | ["js","jsx","ts",...] | File extensions to process |
| ignore | string[] | ["node_modules",...] | Paths/patterns to ignore |
🚫 Ignore Files
Create a .v7ignore file:
# Dependencies
node_modules/
# Build output
dist/
build/
# Generated files
*.min.js
*.bundle.jsDefault ignored paths: node_modules • .git • dist • build • coverage • .next • .nuxt • .cache • vendor • package-lock.json • yarn.lock
📋 Supported Languages
| Language | Extensions | What V7 Formats |
|----------|-----------|-----------------|
| JavaScript | .js, .jsx, .mjs, .cjs | Indentation, quotes, semicolons, spacing, braces |
| TypeScript | .ts, .tsx | Same as JavaScript |
| HTML | .html, .htm | Tag indentation, attribute spacing, self-closing tags |
| CSS | .css, .scss, .less | Property indentation, selector formatting, spacing |
| JSON | .json | Pretty-print, key sorting, validation |
| Markdown | .md, .markdown | Heading spacing, list markers, blank lines |
🔒 Security
V7 Formatter is built with a security-first mindset:
- 🔐 Zero Dependencies — No supply chain attack surface. Every line is auditable.
- 🛡️ No Code Execution — V7 never uses
eval(),Function(), orchild_process - 🌐 No Network Access — Never makes HTTP requests or phones home
- 📁 Sandboxed File Access — Only touches files you explicitly specify
- 💾 Safe Writes — Files written only after successful formatting
- ⚠️ Graceful Errors — Invalid/malformed files are skipped, never corrupted
Your code is NEVER executed, evaluated, or transmitted. V7 Formatter treats your code purely as text.
See SECURITY.md for the full security policy and vulnerability reporting.
🔄 CI/CD Integration
GitHub Actions
name: Format Check
on: [push, pull_request]
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- run: npm install -g v7-formatter
- run: v7-formatter --check .npm Scripts
{
"scripts": {
"format": "v7-formatter .",
"format:check": "v7-formatter --check ."
}
}Pre-commit Hook
# .husky/pre-commit
v7-formatter --check .🤝 Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
📄 License
MIT — Totally free and open source forever.
👨💻 Author
TheVaibhaw
- 🌐 Website: vaibhawkumarparashar.in
- 🐙 GitHub: @TheVaibhaw
