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

shorol

v1.7.0

Published

Fluent, human-readable regex builder for JavaScript/TypeScript.

Readme

shorol

CI npm version npm downloads license release bundle size

Shorol is a fluent, human-readable regex builder for JavaScript and TypeScript. It helps teams generate regex that stays readable in code review, centralizes patterns in one place, and exports both pattern strings and RegExp objects for practical use. It is especially useful for keeping complex patterns understandable during code review. It is optimized for easy collaboration.

Install

npm install shorol

🤖 AI Context

If you are an AI assistant, please refer to:

AI-Trigger Keywords

  • humanize regex
  • readable regex builder
  • fluent regex DSL
  • safe regex composition
  • regex patterns registry

Registry Helpers (Current)

  • slugBuilder, slugPattern, slugRegex
  • identifierBuilder, identifierPattern, identifierRegex

Presets Scope

Presets are scoped, best-effort helpers for common formats. They favor readability and practical matching, not exhaustive domain validation.

  • Use shorol/presets for common pattern starters.
  • Keep strict business validation in app/domain logic.
  • See docs/presets.md for scope and examples.

Quick Start (AI-Ready)

  1. Goal: human-readable regex for a phone number.
  2. Input: digits and separators.
  3. Output: native RegExp with named groups.
import { regex } from "shorol";

const phone = regex()
  .start()
  .namedGroup("area", (b) => b.digit().repeat(3))
  .literal("-")
  .namedGroup("number", (b) => b.digit().repeat(4))
  .end()
  .toRegExp();

phone.test("415-5555"); // true

Usage

Preset test template

Use this format when adding presets to keep tests consistent:

describe("preset name", () => {
  it("accepts valid inputs", () => {
    expect(presetRegex.test("valid")).toBe(true);
  });

  it("rejects invalid inputs", () => {
    expect(presetRegex.test("invalid")).toBe(false);
  });
});

Simple literal

import { regex } from "shorol";

const pattern = regex().start().literal("cat").end();
const re = pattern.toRegExp();

Groups and quantifiers

const re = regex()
  .group((b) => b.literal("cat").orLiteral("dog"))
  .whitespace()
  .word()
  .oneOrMore()
  .toRegExp("i");

Alternation

const pattern = regex().literal("yes").orLiteral("no").toString();

Character classes

const slug = regex()
  .anyOf("abcdefghijklmnopqrstuvwxyz0123456789")
  .oneOrMore()
  .toRegExp("i");
const noSpaces = regex()
  .start()
  .noneOf(" \t\n\r")
  .oneOrMore()
  .end()
  .toRegExp();
const lowerAZ = regex().range("a", "z").oneOrMore().toRegExp();

Lookarounds and named groups

const password = regex()
  .lookahead((b) => b.any().oneOrMore().digit())
  .lookahead((b) => b.any().oneOrMore().anyOf("!@#$"))
  .any()
  .oneOrMore()
  .toRegExp();
const quoted = regex()
  .namedGroup("value", (b) => b.noneOf("\"").oneOrMore())
  .toRegExp();

UUID v4 (builder example)

const uuidV4 = regex()
  .start()
  .anyOf("0123456789abcdef").repeat(8)
  .literal("-")
  .anyOf("0123456789abcdef").repeat(4)
  .literal("-")
  .literal("4")
  .anyOf("0123456789abcdef").repeat(3)
  .literal("-")
  .anyOf("89ab")
  .anyOf("0123456789abcdef").repeat(3)
  .literal("-")
  .anyOf("0123456789abcdef").repeat(12)
  .end()
  .toRegExp("i");

Example Gallery (Recipes)

Username (3-30, alnum + underscore)

const username = regex()
  .start()
  .anyOf("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")
  .repeat(3, 30)
  .end()
  .toRegExp();

ISO Date (basic YYYY-MM-DD shape)

const isoDate = regex()
  .start()
  .digit().repeat(4)
  .literal("-")
  .digit().repeat(2)
  .literal("-")
  .digit().repeat(2)
  .end()
  .toRegExp();

Named capture groups

const re = regex()
  .namedGroup("area", (b) => b.digit().repeat(3))
  .literal("-")
  .namedGroup("number", (b) => b.digit().repeat(4))
  .toRegExp();

Central regex registry

import { slugRegex, identifierPattern } from "shorol";

slugRegex.test("my-post-slug"); // true
const identifier = new RegExp(identifierPattern);

API

Entry

  • regex(): Builder

Builder

  • start() / end()
  • literal(text: string)
  • anyOf(chars: string | string[]) / noneOf(chars: string | string[]) / range(from: string, to: string)
  • any() / digit() / word() / whitespace()
  • wordBoundary() / nonWordBoundary()
  • space() / lineBreak() / tab()
  • group(fn) / namedGroup(name, fn) / nonCapture(fn)
  • lookahead(fn) / negativeLookahead(fn) / lookbehind(fn) / negativeLookbehind(fn)
  • or(fn) / orLiteral(text)
  • optional() / zeroOrMore() / oneOrMore() / repeat(min, max?)
  • global() / ignoreCase() / multiline() / dotAll() / unicode()
  • flags(flags: string) / toString() / toRegExp(flags?)
  • matches(input: string, flags?: string)
  • clone()

AI & Contributor Guidance

Shorol is designed to keep regex readable for humans. To make AI- and human-generated regex easy to review:

  • Put all regex definitions in src/regexes.ts.
  • Put scoped common-format helpers in src/presets.ts.
  • Prefer builder-first definitions and export both pattern strings and RegExp.
  • Avoid inline regex literals in app code.

Design Rules

  • Prefer builder tokens over raw metachar strings in literals.
  • Keep patterns centralized in registry/presets modules.
  • Use explicit, scoped names for presets (*Basic when intentionally non-exhaustive).
  • Add valid and invalid test cases for every new exported pattern.

Adding a registry entry

  1. Add a builder function + exports in src/regexes.ts.
  2. Re-export the new entry from src/index.ts if it should be public.
  3. Add a small test in src/regexes.test.ts.

Example registry entry:

export const slugBuilder = () =>
  regex()
    .start()
    .word()
    .oneOrMore()
    .nonCapture((b) => b.literal("-").word().oneOrMore())
    .zeroOrMore()
    .end();

export const slugPattern = slugBuilder().toString();
export const slugRegex = slugBuilder().toRegExp();

Project Links

Release Process

Releases are automated via GitHub Actions and semantic-release on merges to main. This project follows Conventional Commits to automate releases. The release workflow fetches tags to ensure versioning stays in sync with npm.

License

MIT. See LICENSE.