2.0.0 • Published 2 years ago

sgex v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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