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

oh-my-regex

v0.1.0

Published

Readable string validation without writing regex — chainable predicate API

Readme

oh-my-regex

Readable string validation without writing regex — chainable predicate API.

Install

npm i oh-my-regex

Quick start

import { regex } from "oh-my-regex";

regex("123cose98").hasNumber().hasLetter().ok(); // true
regex("ab").hasNumber().hasUppercase().ok();      // false

API (includes semantics)

All checks use includes semantics: "does the string contain somewhere (or satisfy) this condition?". There is no full-string match in this API.

| Method | Example | |--------|---------| | hasNumber() | regex("x1").hasNumber().ok() | | hasLetter() | regex("1a").hasLetter().ok() | | hasUppercase() / hasLowercase() | regex("Ab").hasUppercase().ok() | | hasLanguage("ko") | regex("한글").hasLanguage("ko").ok() (MVP: "ko" only) | | hasSymbol() | regex("a@").hasSymbol().ok() | | minLength(n) / maxLength(n) | regex("abc").minLength(3).ok() | | startsWith(needle) / endsWith(needle) / includes(needle) | regex("hello").includes("ell").ok() | | raw(re) | regex("123").raw(/\d{3}/).ok() (options like caseInsensitive do not apply) | | caseInsensitive() | regex("ABC").caseInsensitive().hasLetter().ok() |

End with:

  • ok() or test()true if all conditions pass (AND).
  • report(){ ok, failed: [{ name, message? }], passed: string[] }.
  • explain() — human-readable summary of what passed/failed.
  • build(options?) — returns the combined RegExp from combinable predicates, or null when there are none. Options: { global?: boolean } to add the g flag. Use .source on the result for the pattern string.

report() example

const r = regex("ab").hasNumber().hasUppercase().report();
// { ok: false, failed: [{ name: "hasNumber" }, { name: "hasUppercase" }], passed: [] }

explain() example

regex("a").hasNumber().hasLetter().explain();
// "Failed: hasNumber. Passed: hasLetter"

build() example

const re = regex("x").hasNumber().hasLetter().build();
// RegExp from combinable predicates; re.test("a1") === true

regex("x").build();                    // null (no combinable predicates)
regex("a1").hasNumber().build({ global: true });  // RegExp with "g" flag

Notes

  • Includes semantics: Only "somewhere" / substring-style checks. No "whole string must match" in this API.
  • raw(re): Uses your RegExp as-is; caseInsensitive() and other options do not apply. Multiple raw() predicates are distinguished in report().failed by a short pattern snippet in name (e.g. raw(/\d/)). Avoid patterns that cause catastrophic backtracking (e.g. nested quantifiers on overlapping alternations); raw() runs your RegExp as-is and can block the main thread.
  • hasLetter(): Latin letters only (A–Z, a–z). For other scripts use hasLanguage(locale) (e.g. hasLanguage("ko") for Hangul).
  • hasLanguage(locale): MVP supports only "ko". Unsupported locale (e.g. "en", "ja"): always false, no error.
  • hasSymbol(): At least one character that is not whitespace, digit, A–Z, a–z, or Hangul (가–힣). Non-ASCII scripts (Japanese, Chinese, Arabic, etc.) are treated as symbols in MVP; in i18n contexts, "symbol" here includes non-Latin scripts.
  • startsWith(re) / endsWith(re): When needle is a RegExp, a ^ or $ anchor is added automatically if not already present. caseInsensitive() does not apply to RegExp needles — set the i flag directly (e.g. /hel/i).
  • minLength(n) / maxLength(n): Throws when the predicate is created (at chain build time) if n is negative or non-integer (fail-fast).

License

MIT