Skip to content

Latest commit

 

History

History
37 lines (25 loc) · 1 KB

templates.readme.md

File metadata and controls

37 lines (25 loc) · 1 KB

Commonly Typescript

Go back

Templates module

commonly.typescript/templates


  • regexp

Creates a RegExp object from a Tagged Template Literal or a string pattern.

Flags are passed as a property or chain of properties of the regexp tag. Each flags property can be called as a function with a boolean condition argument to ascertain such flags.

interface regexp {
	(strings: TemplateStringsArray, ...keys: string[]): RegExp;

	(pattern: string): RegExp;

	[flags]: regexp;

	[flags]: (condition: boolean) => regexp;
}

Usage:

regexp('<.+>') == /<.+>/;
regexp`\b(${ ['hello', 'world'].join('|') })\b` == /\b(hello|world)\b/;
regexp.gi`another regexp` == /another regexp/gi;
regexp.g.m(true)`conditional m flag` == /conditional m flag/gm;