2.0.0 • Published 3 years ago
sgex v2.0.0
sgex
Tagged template literals that produce regex with surrounding whitespace removed
Installation
NPM
npm i sgexYarn
yarn add sgexUsage
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