sgex
v2.0.0
Published
Tagged template literals that produce regex with surrounding whitespace removed
Downloads
8
Maintainers
Readme
sgex
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