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

ts-regex-builder

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-regex-builder

TypeScript adaptation of Swift Regex Builder API

  • 0.8.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
121K
increased by86.17%
Maintainers
1
Weekly downloads
 
Created
Source

TS Regex Builder

User-friendly Regular Expression builder for TypeScript and JavaScript.

Goal

Regular expressions are a powerful tool for matching complex text patterns, yet they are notorious for their hard-to-understand syntax.

Inspired by Swift's Regex Builder, this library allows users to write easily and understand regular expressions.

// Before
const hexColor = /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/;

// After
const hexDigit = characterClass(
  characterRange('a', 'f'),
  characterRange('A', 'F'),
  characterRange('0', '9')
);

const hexColor = buildRegex(
  startOfString,
  optionally('#'),
  capture(
    choiceOf(repeat({ count: 6 }, hexDigit), repeat({ count: 3 }, hexDigit))
  ),
  endOfString
);

Installation

npm install ts-regex-builder

Usage

import { buildRegex, capture, oneOrMore } from 'ts-regex-builder';

// /Hello (\w+)/
const regex = buildRegex(['Hello ', capture(oneOrMore(word))]);

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

See the project guidelines to understand our core principles.

License

MIT

Reference


Made with create-react-native-library

Keywords

FAQs

Package last updated on 26 Dec 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc