Getting Started
Installation
Global Installation
Install CWF globally to use it from anywhere:
bash
npm install -g @codewaveinnovation/formatterProject Installation
Install as a dev dependency in your project:
bash
npm install --save-dev @codewaveinnovation/formatterBasic Usage
Format a Single File
bash
cwf format myfile.txtFormat Multiple Files
Using glob patterns:
bash
cwf format "src/**/*.ts"
cwf format "*.js" "*.ts"Interactive Mode
Configure rules interactively:
bash
cwf format myfile.txt --interactiveCheck Formatting
Check if files are formatted without modifying them:
bash
cwf check myfile.txtConfiguration
Auto-Discovery
CWF automatically searches for configuration files in the current directory:
.cwfrc.json.cwfrcpackage.json(under"formatter"key)
Create Default Config
Generate a default configuration file:
bash
cwf initThis creates a .cwfrc.json file with default settings:
json
{
"rules": [
{
"name": "indentation",
"enabled": true,
"options": { "style": "space", "size": 2 }
},
{
"name": "line-ending",
"enabled": true,
"options": { "style": "lf" }
},
{
"name": "trailing-whitespace",
"enabled": true
},
{
"name": "final-newline",
"enabled": true,
"options": { "insert": true }
}
]
}Programmatic Usage
Use CWF in your Node.js applications:
typescript
import { createFormatter, getDefaultConfig } from '@codewaveinnovation/formatter';
const formatter = createFormatter();
const config = getDefaultConfig();
const result = await formatter.format(' hello world ', config);
console.log(result.content); // 'hello world\n'
console.log(result.changed); // true
console.log(result.appliedRules); // ['trailing-whitespace', 'final-newline']Next Steps
- Learn about Configuration options
- Explore available Rules
- Check the API documentation