New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

regexpstructor

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regexpstructor

Build regular expressions in a safe and readable way.

latest
Source
npmnpm
Version
2.0.2
Version published
Weekly downloads
5
-44.44%
Maintainers
1
Weekly downloads
 
Created
Source

Test npm

RegExpStructor

Build regular expressions via a fluent api

Highlights

  • Describe your matcher in a human readable way
  • Fluent api to build your regular expressions
  • Make maintainable complex regular expressions
  • Immutable for maximum reuseablity: All methods return a fresh RegExpstructor. No implicit mutation of any internals that could lead to unexpected results
  • Composable: Build more complex expressions from your simple RegExpstructors. Use combinators like ReStructor.seq(...RegExpstructors) or ReStructor.or(...RegExpstructors) to combine your matchers.
  • No useless non-capture group wrapping in the output (the final Regexp will be as performant and readable as possible)

Getting started

Install with

npm i regexpstructor

or with yarn

yarn add regexpstructor

Usage

// ES module import:
import ReStructor from "regexpstructor";

// or in commonjs:
const ReStructor = require("regexpstructor");

/**
 * @example building a UUID regexp
 */
const hexChar = ReStructor().charOfRanges(["0", "9"], ["a", "f"]);

// tests for [0-9a-f]{8} - eg. "a019bc3f"
const digitBlock_8 = hexChar.repeatExactly(8);

// tests for [0-9a-f]{4} - eg. "bc3f"
const digitBlock_4 = hexChar.repeatExactly(4);

// uuid looks like this: "a019bc3f-1234-5678-9abc-def012345678"
const uuid = digitBlock_8
  .then("-")
  .then(
    // 3 times a 4-digit blocks, each followed by a dash
    digitBlock_4.then("-").repeatExactly(3)
  )
  .then(
    // block of size 12
    hexChar.repeatExactly(12)
  )
  .withAnyCase() // make case insensitive
  .searchOneLine(); // single line search

// compile the uuid reStructor into a regExp
const regex = uuid.compile();

// use it:
regex.test("a019bc3f-1234-5678-9abc-def012345678"); // result: true

// print it:
console.log(regex); /* logs: /[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}/gi */

Keywords

VerbalExpressions

FAQs

Package last updated on 01 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts