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

@formatr/cli

v1.0.0

Published

CLI tools for the formatr template library

Readme

@formatr/cli

Command Line Interface for the formatr template library.

Installation

npm install -g @formatr/cli
# or
npm install --save-dev @formatr/cli

Quick Start

# Render a template
echo "Hello {name}!" | formatr render --data '{"name":"World"}'

# Validate templates
formatr validate ./templates --recursive

# Start the playground
formatr playground

Commands

formatr render

Render templates with provided data.

# Render from file with JSON data
formatr render template.fmt --data data.json --output result.txt

# Render from stdin
echo "Hello {name}!" | formatr render --data '{"name":"World"}'

# Render with YAML data
formatr render template.fmt --data config.yaml

# Render multiple templates
formatr render ./templates --data data.json --output-dir ./dist --recursive

# Watch mode
formatr render template.fmt --data data.json --watch

formatr validate

Validate template syntax and structure.

# Validate single template
formatr validate template.fmt

# Validate directory
formatr validate ./templates --recursive

# Validate with context (check placeholders exist)
formatr validate template.fmt --context data.json

# Strict mode (treat warnings as errors)
formatr validate template.fmt --strict

# Output as JSON for CI
formatr validate template.fmt --json

formatr analyze

Analyze template complexity and characteristics.

# Analyze single template
formatr analyze template.fmt

# Analyze with detailed metrics
formatr analyze template.fmt --detailed

# Compare multiple templates
formatr analyze template-v1.fmt template-v2.fmt --compare

# Output as JSON with threshold for CI
formatr analyze template.fmt --json --threshold complexity=10

formatr benchmark

Benchmark template rendering performance.

# Basic benchmark
formatr benchmark template.fmt --data data.json

# Multiple iterations
formatr benchmark template.fmt --data data.json --iterations 10000

# Compare implementations
formatr benchmark template-v1.fmt template-v2.fmt --data data.json

# Memory profiling
formatr benchmark template.fmt --data data.json --memory

# Generate HTML report
formatr benchmark template.fmt --data data.json --report benchmark.html

formatr report

Generate reports from templates and data.

# Generate HTML report
formatr report --template report.fmt --data results.json --format html

# Generate markdown report
formatr report --template report.fmt --data results.json --format markdown

# Batch report generation
formatr report --template report.fmt --data-dir ./data --output-dir ./reports

# Custom styles
formatr report --template report.fmt --data data.json --format html --style custom.css

formatr watch

Watch templates and data files for changes.

# Watch single template
formatr watch template.fmt --data data.json --output result.txt

# Watch directory
formatr watch ./templates --data-dir ./data --output-dir ./dist

# Watch with live reload server
formatr watch template.fmt --data data.json --serve --port 3000

# Watch with custom debounce
formatr watch template.fmt --data data.json --debounce 500

formatr init

Initialize a new formatr project.

# Interactive initialization
formatr init

# Initialize with template
formatr init my-project --template basic

# Initialize TypeScript project
formatr init my-project --template typescript

# Create config file only
formatr init --config-only

Available templates:

  • basic - Basic formatr project
  • typescript - TypeScript project with types
  • advanced - Advanced project with examples
  • documentation - Documentation project

formatr format

Format template files according to style guidelines.

# Format single file
formatr format template.fmt

# Format directory
formatr format ./templates --recursive

# Check only (don't modify)
formatr format template.fmt --check

# Format with specific style
formatr format template.fmt --style compact

formatr lint

Lint templates for best practices and potential issues.

# Lint single template
formatr lint template.fmt

# Lint directory
formatr lint ./templates --recursive

# Fix auto-fixable issues
formatr lint template.fmt --fix

# Output as JSON for CI
formatr lint template.fmt --json

formatr playground

Launch an interactive playground.

# Launch playground in browser
formatr playground

# Launch on custom port
formatr playground --port 8080

# Launch with initial template
formatr playground --template examples/basic.fmt

# Launch in CLI mode (REPL)
formatr playground --cli

Configuration

The CLI supports configuration files in the following order of precedence:

  1. .formatrrc (JSON)
  2. .formatrrc.json
  3. .formatrrc.yaml / .formatrrc.yml
  4. formatr.config.js / formatr.config.mjs / formatr.config.cjs

Example .formatrrc.json:

{
  "templateExtension": ".fmt",
  "outputDir": "./dist",
  "locale": "en-US",
  "lint": {
    "extends": "recommended",
    "rules": {
      "no-empty-placeholders": "error"
    }
  },
  "format": {
    "style": "expanded",
    "indentation": 2
  },
  "watch": {
    "debounce": 300,
    "extensions": [".fmt", ".json", ".yaml"]
  }
}

Exit Codes

The CLI uses standard exit codes for CI/CD integration:

  • 0 - Success
  • 1 - Command failure (e.g., validation errors, render errors)
  • 2 - Invalid usage (e.g., missing required arguments)

Environment Variables

  • NO_COLOR - Disable colored output
  • FORCE_COLOR - Force colored output
  • DEBUG - Enable debug logging

CI/CD Integration

GitHub Actions

steps:
  - name: Validate templates
    run: formatr validate ./templates --recursive --json > validation.json
    
  - name: Lint templates
    run: formatr lint ./templates --recursive --json > lint.json
    
  - name: Check complexity
    run: formatr analyze ./templates --json --threshold complexity=10

Pre-commit Hook

{
  "scripts": {
    "precommit": "formatr lint ./templates --recursive && formatr format ./templates --check"
  }
}

Troubleshooting

Colors not displaying

Try setting FORCE_COLOR=1 or ensure your terminal supports ANSI colors.

YAML support not working

Install the optional yaml package:

npm install yaml

Watch mode not working

Install the optional chokidar package:

npm install chokidar

Interactive mode not working

Install the optional inquirer package:

npm install inquirer

License

MIT