typed-regexp
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

typed-regexp

A typescript package that strongly restricts types of regular expressions.

Examples

As direct dependency: npm i typed-regexp

import { TypedRegExp } from "typed-regexp";

const regexp = new TypedRegExp<[`{${string}`],{name:"a"|"b"}>("(?<name>[ab])({.*)");
const match = "string to match".match(regexp);
if (match) {
  const namedGroup = match.groups.name;
  // => "a"|"b"
  const group = match[1];
  // => `{${string}`
}

or as dev dependency: npm i -D typed-regexp

import type { TypedRegExp } from "typed-regexp";

const regexp = /(?<name>[ab])({.*)/ as TypedRegExp<[`{${string}`],{name:"a"|"b"}>;
const match = "string to match".match(regexp);
if (match) {
  const namedGroup = match.groups.name;
  // => "a"|"b"
  const group = match[1];
  // => `{${string}`
}

Dependencies (0)

    Dev Dependencies (1)

    Package Sidebar

    Install

    npm i typed-regexp

    Weekly Downloads

    0

    Version

    1.0.4

    License

    MIT

    Unpacked Size

    11.7 kB

    Total Files

    6

    Last publish

    Collaborators

    • sertonix