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

2.0.0 • Public • Published

sgex

Version Prerequisite License: MIT

Tagged template literals that produce regex with surrounding whitespace removed

Installation

NPM

npm i sgex

Yarn

yarn add sgex

Usage

An sgex tag will:

  • Ignore escape sequences
sgex`Hello\nWorld!`;

// Returns
/Hello\nWorld/;
  • Remove all surrounding whitespace not inside interpolated expressions
sgex`
    Hello
    ${" "}
    World !
`;

// Returns
/Hello World !/;
  • Handle interpolated regular expressions correctly
sgex`Hello${/ World/}!`;

// Returns
/Hello World!/;

Regular expression flags

You can specify flags that should be used for your expression by using the flags overload:

// Flags
sgex("gi")`^abc$`;

// No flags
sgex`^abc$`;

Inline comments

sgex`
    ${[ /* This is a comment */ ]}
    ^This is the regular expression$
`;

License

MIT © Juan de Urtubey

Package Sidebar

Install

npm i sgex

Weekly Downloads

1

Version

2.0.0

License

MIT

Unpacked Size

6.87 kB

Total Files

9

Last publish

Collaborators

  • jdeurt