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

@azlib/formatter

v0.2.0

Published

Universal, extensible text formatting library for TypeScript and JavaScript. Zero external dependencies, modular language formatters, syntax highlighters, and `@azlib/schema`-powered options validation.

Readme

@azlib/formatter

Universal, extensible text formatting library for TypeScript and JavaScript. Zero external dependencies, modular language formatters, syntax highlighters, and @azlib/schema-powered options validation.

Features

  • Unified Dispatcher (format): Format any text by language name or alias (sql, json, xml, html, css, env, query-string, markdown).
  • Extensible Registry: Register custom formatters and aliases via registerFormatter.
  • SQL Formatter & Highlighter: Full SQL query formatter with clause-level indentation, dialect support, casing normalization, and HTML syntax highlighting.
  • JSON Pretty-Printer: Relaxed parser handling comments (//, /* */), trailing commas, unquoted keys, recursive key sorting, compact inlining, and @azlib/schema runtime validation.
  • XML & HTML Formatter: Clean tag indentation, HTML5 void element recognition, attribute wrapping (auto / always / never), attribute sorting, and <tag></tag> to <tag /> collapsing.
  • CSS Formatter: Declaration block indentation, at-rule nesting (@media, @supports), alphabetical property sorting, and concise single-line rule mode.
  • ENV / Properties Formatter: Equal sign (=) alignment across consecutive keys, section preservation, key sorting, and quote normalization.
  • Query String / URL Formatter: Sort query parameters, multiline layout for clean inspection, and URI decoding/encoding.
  • Markdown Formatter: Neatly padded and aligned Markdown tables, ATX heading normalization, and code block preservation.
  • Text Utilities: indentString, dedent, alignColumns, and wrapText.

Installation

pnpm add @azlib/formatter

Quick Start

Unified format()

import { format } from "@azlib/formatter";

// SQL
const sql = format("select id, name from users where active = true;", "sql");

// JSON with key sorting
const json = format("{ b: 2, a: 1 }", { language: "json", sortKeys: true });

// HTML
const html = format("<div><h1>Hello</h1><p>World</p></div>", "html");

Dedicated Formatters

SQL Formatter & Syntax Highlighter

import { formatSql, highlightSql } from "@azlib/formatter";

const query = `
  SELECT u.id, u.name, count(o.id) as order_count
  FROM users u
  LEFT JOIN orders o ON o.user_id = u.id
  WHERE u.status = 'active'
  GROUP BY u.id, u.name
  ORDER BY order_count DESC;
`;

const formatted = formatSql(query, {
  keywordCase: "upper",
  indent: 2,
});

const html = highlightSql(query, {
  theme: "dark",
  wrap: "pre",
});

JSON Formatter

import { formatJson } from "@azlib/formatter";
import { s } from "@azlib/schema";

const dirtyJson = `
  {
    // Profile configuration
    name: 'Alice',
    age: 30,
    roles: ['admin', 'developer',],
  }
`;

const clean = formatJson(dirtyJson, {
  sortKeys: true,
  inlineThreshold: 30,
  schema: s.object({
    name: s.string(),
    age: s.number(),
    roles: s.array(s.string()),
  }),
});

ENV Formatter

import { formatEnv } from "@azlib/formatter";

const env = `
PORT=3000
DATABASE_URL=postgresql://localhost:5432/db
DEBUG=true
`;

const aligned = formatEnv(env, { alignValues: true });
// PORT         = 3000
// DATABASE_URL = postgresql://localhost:5432/db
// DEBUG        = true

Markdown Formatter

import { formatMarkdown } from "@azlib/formatter";

const table = `
| Name | Age | Status |
| :--- | ---: | :---: |
| Alice | 30 | Active |
| Bob | 5 | Inactive |
`;

const formattedTable = formatMarkdown(table, { formatTables: true });

Options Validation

@azlib/formatter exports schemas built on @azlib/schema:

  • sqlFormatOptionsSchema
  • jsonFormatOptionsSchema
  • xmlFormatOptionsSchema
  • cssFormatOptionsSchema
  • envFormatOptionsSchema
  • queryStringFormatOptionsSchema
  • markdownFormatOptionsSchema
  • formatterOptionsSchema

License

MIT