Socket
Socket
Sign inDemoInstall

typed-regex

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    typed-regex

A typescript library for writing type-safe regular expressions using named capture groups


Version published
Weekly downloads
604
decreased by-49.37%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

typed-regex

A typescript library for writing type-safe regular expressions using named capture groups.

npm npm bundle size

Install

To install the latest stable version of typed-regex -

yarn add typed-regex
// OR
npm install --save typed-regex

Usage

The type of the result object is infered from the regular expression.

import { TypedRegEx } from 'typed-regex';

const regex = TypedRegEx('^(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})$', 'g');
const result = regex.captures('2020-12-02');

result // : undefined | { year: string, month: string, day: string }

NOTE: The regular expression has to be a string literal for the types to be valid

Optional properties

If the capture group is marked as optional in the regular expression, the generated type will reflect that

const regex = TypedRegEx('(?<first>\\d+)/(?<second>\\w+)?', 'g');
const result = regex.captures('1234/foobar');

result // : undefined | { first: string, second?: string }
API Docs

You can find more information about the library in the API documentation

Browser support

Named capture groups are supported in these browser

License

Typed-Regex is licensed under MIT

Keywords

FAQs

Last updated on 13 Jun 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc