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

@chaisser/regex-humanizer

v1.0.1

Published

Convert regex patterns to human readable descriptions

Readme

🔍 @chaisser/regex-humanizer

Convert regex patterns to human-readable descriptions with English and Turkish support


✨ Features

  • 🎯 Type-safe - Full TypeScript support
  • 🌍 Multi-locale - English and Turkish descriptions
  • 📖 Humanize - Convert patterns to plain-text descriptions
  • 📋 Explain - Detailed token-by-token breakdown
  • 🧩 Comprehensive - Supports anchors, character classes, quantifiers, groups, lookaheads, escapes
  • 🪶 Zero dependencies - Lightweight and tree-shakeable
  • 🏎️ ESM + CJS - Dual module format support

📦 Installation

npm install @chaisser/regex-humanizer
# or
yarn add @chaisser/regex-humanizer
# or
pnpm add @chaisser/regex-humanizer

🚀 Quick Start

import { humanize, explain } from '@chaisser/regex-humanizer';

// Simple humanization
humanize('^\\w+@\\w+\\.\\w+$');
// "start of string any word character one or more times @ any word character one or more times . any word character one or more times end of string"

// Detailed explanation
const result = explain('\\d{3}-\\d{4}');
console.log(result.description);
// "any digit between 3 and 3 times - any digit between 4 and 4 times"
console.log(result.breakdown);
// ["\\d → any digit", "{3} → exactly 3 times", "\\d → any digit", "{4} → exactly 4 times"]

// Turkish locale
humanize('^\\w+$', { locale: 'tr' });
// "satır başı herhangi bir kelime karakteri ... satır sonu"

📖 What It Does

This package converts regular expression patterns into human-readable descriptions. It parses regex tokens — anchors, character classes, quantifiers, groups, lookaheads, and escape sequences — and translates each one into natural language. It also provides a detailed breakdown explaining each token individually.


🎯 How It Works

The package provides two main functions:

  • humanize - Parses a regex pattern and produces a single readable description string
  • explain - Returns both a description and a token-by-token breakdown array

Supported token types:

  • Anchors - ^, $, \b, \B
  • Wildcards - .
  • Quantifiers - *, +, ?, {n}, {n,}, {n,m}
  • Character classes - [a-z], [A-Z], [0-9], and custom classes
  • Shorthand classes - \d, \D, \w, \W, \s, \S
  • Groups - (...), (?:...), (?=...), (?!...)
  • Escape sequences - \n, \r, \t
  • Alternation - |

🎨 What It's Useful For

  • Documentation - Auto-generate regex descriptions for API docs
  • Debugging - Understand complex regex patterns at a glance
  • Education - Teach regex by showing what each token means
  • Code Review - Make regex patterns readable in pull requests
  • Accessibility - Present regex logic in plain language
  • Internationalization - Describe patterns in English or Turkish

💡 Usage Examples

Basic Patterns

import { humanize } from '@chaisser/regex-humanizer';

// Email-like pattern
humanize('^\\w+@\\w+\\.\\w+$');
// "start of string any word character one or more times @ ..."

// Phone number pattern
humanize('\\d{3}-\\d{3}-\\d{4}');
// "any digit exactly 3 times - any digit exactly 3 times - any digit exactly 4 times"

// Optional suffix
humanize('colou?r');
// "c o l o zero or one time (optional) r"

Character Classes

humanize('[a-zA-Z]+');
// "any letter one or more times"

humanize('[0-9]{2,4}');
// "any digit between 2 and 4 times"

Groups and Lookaheads

// Capturing group
humanize('(\\d+)-(\\d+)');
// "(capturing group: any digit one or more times) - (capturing group: any digit one or more times)"

// Non-capturing group
humanize('(?:ab)+');
// "(non-capturing group: a b) one or more times"

// Positive lookahead
humanize('\\w+(?=\\.)');
// "any word character one or more times (positive lookahead: .)"

// Negative lookahead
humanize('foo(?!bar)');
// "f o o (negative lookahead: b a r)"

Detailed Explanation

import { explain } from '@chaisser/regex-humanizer';

const result = explain('^\\d{4}-\\d{2}-\\d{2}$');

console.log(result.pattern);    // "^\\d{4}-\\d{2}-\\d{2}$"
console.log(result.description); // Full readable description
console.log(result.breakdown);
// [
//   "^ → start of string",
//   "\\d → any digit",
//   "{4} → exactly 4 times",
//   "\\d → any digit",
//   "{2} → exactly 2 times",
//   "\\d → any digit",
//   "{2} → exactly 2 times",
//   "$ → end of string"
// ]

Turkish Locale

humanize('^\\w+$', { locale: 'tr' });
// "satır başı herhangi bir kelime karakteri bir veya daha fazla kez satır sonu"

explain('\\d+', { locale: 'tr' });
// breakdown: ["\\d → herhangi bir rakam", "+ → bir veya daha fazla kez"]

📚 API Reference

humanize(pattern, options?)

Converts a regex pattern to a human-readable description string.

| Parameter | Type | Description | |---|---|---| | pattern | string | The regex pattern to humanize | | options.locale | 'en' \| 'tr' | Language for descriptions (default: 'en') |

Returns: string — Human-readable description

explain(pattern, options?)

Returns a detailed breakdown of a regex pattern.

| Parameter | Type | Description | |---|---|---| | pattern | string | The regex pattern to explain | | options.locale | 'en' \| 'tr' | Language for descriptions (default: 'en') |

Returns:

{
  pattern: string;      // Original pattern
  description: string;  // Full human-readable description
  breakdown: string[];  // Token-by-token explanations
}

Supported Tokens

| Token | English | Turkish | |---|---|---| | ^ | start of string | satır başı | | $ | end of string | satır sonu | | . | any character | herhangi bir karakter | | * | zero or more times | sıfır veya daha fazla kez | | + | one or more times | bir veya daha fazla kez | | ? | zero or one time (optional) | sıfır veya bir kez (opsiyonel) | | \| | or | veya | | \d | any digit | herhangi bir rakam | | \D | any non-digit | herhangi bir rakam olmayan | | \w | any word character | herhangi bir kelime karakteri | | \W | any non-word character | herhangi bir kelime karakteri olmayan | | \s | any whitespace | herhangi bir boşluk karakteri | | \S | any non-whitespace | herhangi bir boşluk olmayan | | \b | word boundary | kelime sınırı | | \B | non-word boundary | kelime sınırı değil |


🔗 Related Packages

Explore our other utility packages in the @chaisser namespace:


🔒 License

MIT - Free to use in personal and commercial projects


👨 Developed by

Doruk Karaboncuk [email protected]


📄 Repository


🤝 Contributing

Contributions are welcome! Feel free to:

  • Report bugs
  • Suggest new features
  • Submit pull requests
  • Improve documentation

📞 Support

For issues, questions, or suggestions, please reach out through:


Made with ❤️ by @chaisser

npm license downloads typescript