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

1.0.1 • Public • Published

retemplate

Regular Expressions using Tagged Templates

Installation

npm i retemplate

Usage

import { R } from "retemplate";
 
// composing regular expressions with tagged templates:
const unsafe = "hello?";
const part = R`(?<part>${unsafe})`;
const whole = R`say ${part}`;
const re = new RegExp(whole); // re = /say (?:(?<part>hello\?))/
re.test("say hello?"); // true
 
// composite matchers
const results = R.matchAll({
    [R`foo`]: 0,
    [R`bar(\d)`]: (_, cap) => parseInt(cap),
    [R`baz`]: R.BREAK,
    [R`quxx`]: 3
}, "foo bar1 bar2 baz quxx");
 
result; // [0, 1, 2]

Readme

Keywords

none

Package Sidebar

Install

npm i retemplate

Weekly Downloads

2

Version

1.0.1

License

Apache-2.0

Unpacked Size

56.1 kB

Total Files

16

Last publish

Collaborators

  • rbuckton