npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@codewaveinnovation/formatter

v1.4.3

Published

Language-agnostic code formatter with configurable rules and plugin support

Readme

npm version npm downloads Tests License: MIT Node.js Version

Language-agnostic code formatter with configurable rules and plugin support

📚 Documentation🚀 Getting Started🔌 Plugins📖 API Reference


🚀 Features

  • Language-agnostic: Works with any kind of text file
  • SOLID architecture: Modular and extensible design
  • Plugin system: Extend functionality without changing the core code
  • Interactive CLI: Command-line interface with interactive mode
  • Configurable rules: Customize formatting to fit your needs
  • High test coverage: Over 80% code coverage

📦 Installation

npm install @codewaveinnovation/formatter

For global CLI usage:

npm install -g @codewaveinnovation/formatter

🎯 Usage

CLI

Format files

Format a single file:

cwf format file.txt

Format multiple files with glob patterns:

cwf format "src/**/*.ts"        # All TypeScript files in src/
cwf format "*.js" "*.ts"        # All JS and TS files in current dir
cwf format src/ test/           # All files in src/ and test/ directories

Interactive mode

cwf format file.txt --interactive

Use a configuration file

cwf format file.txt --config .cwfrc.json

Auto-discovery of configuration

The CLI automatically searches for configuration files in the current directory:

cwf format file.txt
# Looks for .cwfrc.json, .cwfrc, or package.json (formatter key)

Supported config locations (in order of priority):

  • .cwfrc.json
  • .cwfrc
  • package.json under "formatter" key

Check formatting without modifying

cwf check file.txt

Create a default configuration file

cwf init

Programmatic API

import { createFormatter, getDefaultConfig } from '@codewaveinnovation/formatter';

// Create a formatter with default rules
const formatter = createFormatter();
const config = getDefaultConfig();

// Format content
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']

Custom configuration

import { createFormatter, FormatterConfig } from '@codewaveinnovation/formatter';

const formatter = createFormatter();

const customConfig: FormatterConfig = {
  rules: [
    { 
      name: 'indentation', 
      enabled: true, 
      options: { style: 'space', size: 4 } 
    },
    { 
      name: 'line-ending', 
      enabled: true, 
      options: { style: 'lf' } 
    },
    { 
      name: 'trailing-whitespace', 
      enabled: true 
    },
    { 
      name: 'final-newline', 
      enabled: true, 
      options: { insert: true } 
    },
  ],
};

const result = await formatter.format(code, customConfig);

📋 Available Rules

indentation

Normalizes indentation to spaces or tabs.

Options:

  • style: 'space' | 'tab' (default: 'space')
  • size: number of spaces per level (default: 2)

line-ending

Normalizes line endings.

Options:

  • style: 'lf' | 'crlf' | 'cr' (default: 'lf')

trailing-whitespace

Removes trailing whitespace at the end of lines.

final-newline

Ensures the file ends with a newline.

Options:

  • insert: boolean (default: true)

max-line-length

Controls the maximum length of lines.

Options:

  • length: number of characters (default: 80)
  • action: 'warn' | 'wrap' (default: 'warn')

🔌 Plugin System

Create your own plugin to extend functionality:

import { BasePlugin, IFormattingRule } from '@codewaveinnovation/formatter';
import { MyCustomRule } from './my-custom-rule';

export class MyPlugin extends BasePlugin {
  readonly name = 'my-plugin';
  readonly version = '1.0.0';

  getRules(): IFormattingRule[] {
    return [new MyCustomRule()];
  }
}

Load the plugin:

import { RuleRegistry, PluginManager, CodeFormatter } from '@codewaveinnovation/formatter';
import { MyPlugin } from './my-plugin';

const registry = new RuleRegistry();
const pluginManager = new PluginManager(registry);
const myPlugin = new MyPlugin();

pluginManager.loadPlugin(myPlugin);

const formatter = new CodeFormatter(registry);

🏗️ SOLID Architecture

The project follows the SOLID principles:

  • Single Responsibility: Each class has a single responsibility
  • Open/Closed: Open for extension (plugins), closed for modification
  • Liskov Substitution: Implementations can be substituted by their interfaces
  • Interface Segregation: Specific interfaces instead of general ones
  • Dependency Inversion: Depend on abstractions, not concretions

🧪 Tests

Run tests:

npm test

View coverage:

npm run test:coverage

🛠️ Development

# Install dependencies
npm install

# Build
npm run build

# Run linter
npm run lint

# Run tests
npm test

📄 License

MIT © CodeWave Innovation

🤝 Contributing

Contributions are welcome. Please open an issue or pull request for suggestions or improvements.

📚 Additional documentation

Configuration file (.cwfrc.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
      }
    }
  ]
}