npm package: @raphaellcs/code-formatter
Description: A simple code formatter for JSON, CSS, and HTML
Author: Dream Heart
Latest version: 1.0.0

# @raphaellcs/code-formatter

A simple and easy-to-use code formatter for JSON, CSS, HTML, JavaScript, and TypeScript.

## Features

- 🎨 **Format** multiple file types (JSON, CSS, HTML, JS, TS)
- 📁 **Batch** format files in directories
- 🔍 **Check** if files are properly formatted
- ⚙️ **Customizable** formatting options (indentation, width, quotes)
- 🚀 **Fast** and lightweight

## Installation

```bash
# Use with npx (no installation needed)
npx @raphaellcs/code-formatter --help

# Or install globally
npm install -g @raphaellcs/code-formatter
```

## Usage

### Format a Single File

```bash
# Format a JSON file
npx @raphaellcs/code-formatter format --file data.json

# Format and save to a new file
npx @raphaellcs/code-formatter format --file input.json --output output.json

# Format with custom indentation (4 spaces)
npx @raphaellcs/code-formatter format --file code.js --spaces 4

# Format with tabs
npx @raphaellcs/code-formatter format --file code.css --tab
```

### Batch Format Files in Directory

```bash
# Format all JSON and CSS files in current directory
npx @raphaellcs/code-formatter batch --directory .

# Format recursively (including subdirectories)
npx @raphaellcs/code-formatter batch --directory . --recursive

# Format specific file types
npx @raphaellcs/code-formatter batch --directory . --extensions json,css,html

# Format with custom options
npx @raphaellcs/code-formatter batch --directory src --recursive --tab --width 100
```

### Check if Files are Formatted

```bash
# Check a single file
npx @raphaellcs/code-formatter check --file data.json

# Check all files in directory
npx @raphaellcs/code-formatter check --directory . --recursive

# The command exits with code 1 if files need formatting
```

## Options

### Format Command

- `-f, --file <path>` - File path to format
- `-o, --output <path>` - Output file path (default: overwrite original)
- `-w, --width <number>` - Line width (default: 80)
- `-s, --spaces <number>` - Number of spaces for indentation (default: 2)
- `--tab` - Use tabs instead of spaces
- `--no-semi` - No semicolons (JavaScript only)
- `--single-quote` - Use single quotes instead of double
- `--check` - Check if file is formatted without modifying

### Batch Command

- `-d, --directory <path>` - Directory path (default: current directory)
- `-e, --extensions <extensions>` - File extensions (comma-separated, default: json,css,html,htm,js,ts)
- `-r, --recursive` - Format files recursively in subdirectories
- `-w, --width <number>` - Line width (default: 80)
- `-s, --spaces <number>` - Number of spaces for indentation (default: 2)
- `--tab` - Use tabs instead of spaces
- `--check` - Check if files are formatted without modifying

## Examples

### Example 1: Format a Messy JSON File

**Input file (data.json):**
```json
{"name":"John","age":30,"city":"New York"}
```

**Command:**
```bash
npx @raphaellcs/code-formatter format --file data.json
```

**Output file (data.json):**
```json
{
  "name": "John",
  "age": 30,
  "city": "New York"
}
```

### Example 2: Format CSS with Tabs

**Input file (style.css):**
```css
body{background-color:#fff;color:#333;margin:0;padding:0}
```

**Command:**
```bash
npx @raphaellcs/code-formatter format --file style.css --tab
```

**Output file (style.css):**
```css
body {
	background-color: #fff;
	color: #333;
	margin: 0;
	padding: 0;
}
```

### Example 3: Batch Format All JS Files

```bash
$ npx @raphaellcs/code-formatter batch --directory src --extensions js --recursive
✔ Found 12 file(s) to format...

✔ Formatting app.js... Done
✔ Formatting utils.js... Done
✔ Formatting index.js... Done
...

✔ Formatted 12 file(s) successfully!
```

### Example 4: Check Files Before Commit

```bash
# Check if files need formatting (for CI/CD)
npx @raphaellcs/code-formatter check --directory . --recursive
✔ Checked 24 file(s). All files are formatted!

# Or if files need formatting:
✖ Checked 24 file(s). 3 need formatting.
```

## Supported File Types

- ✅ JSON (`.json`)
- ✅ CSS (`.css`)
- ✅ HTML (`.html`, `.htm`)
- ✅ JavaScript (`.js`, `.jsx`)
- ✅ TypeScript (`.ts`, `.tsx`)

## Use Cases

- 📦 Preparing JSON configuration files
- 🎨 Cleaning up messy CSS
- 📄 Formatting HTML documents
- 🔧 JavaScript/TypeScript code formatting
- 🔄 CI/CD pre-commit hooks
- 📊 Project-wide code style enforcement

## Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

## License

MIT

## Author

Dream Heart 🌙

## Links

- [npm](https://www.npmjs.com/package/@raphaellcs/code-formatter)
- [GitHub](https://github.com/RaphaelLcs-financial/code-formatter)