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 🙏

© 2024 – Pkg Stats / Ryan Hefner

swyft-regex

v1.0.4

Published

RegexBuilder is a JavaScript library that provides a convenient way to build regular expressions using a fluent and chainable API.

Downloads

14

Readme

RegexBuilder

RegexBuilder is a JavaScript library that provides a convenient way to build regular expressions using a fluent and chainable API.

Installation

You can install RegexBuilder using npm:

npm install regex-builder

Usage

// Import RegexBuilder
import { RegexBuilder } from 'swyft-regex';

// Create a RegexBuilder instance
const regex = new RegexBuilder('abc')
  .digit()
  .multiple()
  .or('def', 'ghi')
  .build();

// Use the generated RegExp
const result = regex.test('abc123'); // true
console.log(regex); // /abc\d+(def|ghi)/

API Reference

constructor(regex: string) Creates an instance of RegexBuilder

includes(char: string): RegexBuilder Appends a character to the regular expression

onlyOne(): RegexBuilder Adds {1} to the regular expression, allowing only one occurrence

multiple(): RegexBuilder Adds + to the regular expression, allowing multiple occurrences

atLeast(count: number): RegexBuilder Adds {count,} to the regular expression, specifying a minimum occurrence count

atMost(count: number): RegexBuilder Adds {0, count} to the regular expression, specifying a maximum occurrence count

anyOf(chars: string): RegexBuilder Adds a character class [chars] to the regular expression

digit(): RegexBuilder Adds \d to the regular expression, matching any digit character

nonDigit(): RegexBuilder Adds \D to the regular expression, matching any non-digit character

word(): RegexBuilder Adds \w to the regular expression, matching any word character

nonWord(): RegexBuilder Adds \W to the regular expression, matching any non-word character

whitespace(): RegexBuilder Adds \s to the regular expression, matching any whitespace character

nonWhitespace(): RegexBuilder Adds \S to the regular expression, matching any non-whitespace character

startOfInput(): RegexBuilder Adds ^ to the beginning of the regular expression, indicating the start of input

endOfInput(): RegexBuilder Adds $ to the end of the regular expression, indicating the end of input

or(...patterns: (string | RegexBuilder)[]): RegexBuilder Adds a group with | for alternation between the current pattern and other patterns

alpha(): RegexBuilder Adds [a-zA-Z] to the regular expression, matching any alphabetical character

caseInsensitive(): RegexBuilder Adds i to the regular expression, making it case-insensitive

escape(str: string): string Escapes special characters in a given string

global(): RegexBuilder Adds g to the regular expression, making it global

multiline(): RegexBuilder Adds m to the regular expression, making it multiline

reset(): RegexBuilder Resets the regular expression to an empty string

comment(commentText: string): RegexBuilder Adds a comment to the regular expression using the (?:commentText) syntax

build(): RegExp Builds a RegExp object based on the current regular expression string.

License

This project is licensed under the MIT License.