New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

regexp-manager

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regexp-manager

regexp builder for node.js developer

0.16.2
Source
npm
Version published
Weekly downloads
5
-95.5%
Maintainers
1
Weekly downloads
 
Created
Source

regexp-manager

regexp-manager

$ npm i regexp-manager

This library creates regular expressions in a form similar to query builders. The benefits of this library are three.

  • To intuitively use various methods of regular expressions that developers do not usually deal with
  • To increase the reuse of regular expressions
  • To infer regular expressions at the type level and allow problems to be found at the time of compilation

Methods currently implemented

// `or` method
// Below return 'left|right'. And it's also inferred from the type.
const leftOrRight = new RegExpPatternBuilder('left').or('right').expression;

// `and` method
// Below return 'leftright'. And it's also inferred from the type.
const leftAndRight = new RegExpPatternBuilder('left').and('right').expression;

// `capturing` method
// Below return '(A)'. And it's also inferred from the type.
const capturingA = new RegExpPatternBuilder('').capturing('A').expression;

// `lessThan` method
// Below return 'a{1,9}'. And it's also inferred from the type.
const lessThanTen = new RegExpPatternBuilder('a').lessThan(10).expression;

// `lessThanOrEqual` method
// Below return 'a{1,10}'. And it's also inferred from the type.
const lessThanOrEqualTen = new RegExpPatternBuilder('a').lessThanOrEqual(10).expression;

// `moreThan` method
// Below return 'a{4,}'. And it's also inferred from the type.
const moreThanThree = new RegExpPatternBuilder('a').moreThan(3).expression;

// `moreThanOrEqual` method
// Below return 'a{3,}'. And it's also inferred from the type.
const moreThanOrEqualThree = new RegExpPatternBuilder('a').moreThanOrEqual(3).expression;

// `include`("left", P) method means lookbehind
// Below return '(?<=a)b'. And it's also inferred from the type.
const lookhehind = new RegExpPatternBuilder('b').includes('LEFT', 'a');

// `include`("right", P) method means lookahead
// Below return 'b(?=a)'. And it's also inferred from the type.
const lookahead = new RegExpPatternBuilder('b').includes('RIGHT', 'a');

// `exclude`("left", P) method means negative lookbehind
// Below return '(?<!a)b'. And it's also inferred from the type.
const nagativeLookbhind = new RegExpPatternBuilder('b').excludes('LEFT', 'a');

// `exclude`("left", P) method means negative lookbehind
// Below return 'b(?!a)'. And it's also inferred from the type.
const negativeLookahead = new RegExpPatternBuilder('b').excludes('RIGHT', 'a');

How to use a builder

import { RegExpPatternBuilder } from 'regexp-manager';

/**
 * result : '(010|011)[0-9]{3,4}[0-9]{4,4}'
 */
const koreanPhoneNumber = new RegExpPatternBuilder('')
    .capturing(() => new RegExpPatternBuilder('010').or('011'))
    .and(() => new RegExpPatternBuilder('[0-9]').between(3, 4))
    .and(() => new RegExpPatternBuilder('[0-9]').between(4, 4)).expression;

If you write a function that returns the string or additional builder according to the inferred type, you can check the result at the time of compilation.

Keywords

regexp

FAQs

Package last updated on 22 May 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