Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jdeurt/sgex
Tagged template literals that produce regex with surrounding whitespace removed
https://github.com/jdeurt/sgex
Last synced: about 1 month ago
JSON representation
Tagged template literals that produce regex with surrounding whitespace removed
- Host: GitHub
- URL: https://github.com/jdeurt/sgex
- Owner: jdeurt
- License: mit
- Created: 2022-10-12T18:01:09.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-13T18:10:48.000Z (about 2 years ago)
- Last Synced: 2024-11-18T16:25:03.663Z (about 2 months ago)
- Language: TypeScript
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# sgex
[![Version](https://img.shields.io/npm/v/sgex.svg)](https://www.npmjs.com/package/sgex)
![Prerequisite](https://img.shields.io/badge/node-%3E%3D16-blue.svg)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](#)> Tagged template literals that produce regex with surrounding whitespace removed
## Installation
### NPM
```bash
npm i sgex
```### Yarn
```bash
yarn add sgex
```## Usage
An `sgex` tag will:
- Ignore escape sequences
```js
sgex`Hello\nWorld!`;// Returns
/Hello\nWorld/;
```- Remove all surrounding whitespace not inside interpolated expressions
```js
sgex`
Hello
${" "}
World !
`;// Returns
/Hello World !/;
```- Handle interpolated regular expressions correctly
```js
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:
```js
// Flags
sgex("gi")`^abc$`;// No flags
sgex`^abc$`;
```### Inline comments
```js
sgex`
${[ /* This is a comment */ ]}
^This is the regular expression$
`;
```## License
MIT © [Juan de Urtubey](https://jdeurt.xyz)