@webreflection/re

0.1.2 • Public • Published

@webreflection/re

Coverage Status

A template literal tag that sanitizes interpolations.

import re from '@webreflection/re';

// strings get escaped
const interpolations = '?';

// arrays get joined by `|` after
// escaping each single value
const options = ['reg', 'exp'];

const safe = re`/unescaped (${options}) code with ${interpolations}!/m`;

safe.test('unescaped reg code with ?!');  // true
safe.test('unescaped exp code with ?!');  // true
safe.test('unescaped nope code with ?!'); // false

This module simply allows creating RegExp instances without worrying about interpolation content because it gets sanitized out of the box via latest RegExp.escape feature or via escape-string-regexp when the former has not been implemented yet.

The whole source code is less than 20 LOC.

Enjoy 👋

Package Sidebar

Install

npm i @webreflection/re

Weekly Downloads

0

Version

0.1.2

License

MIT

Unpacked Size

5.04 kB

Total Files

7

Last publish

Collaborators

  • webreflection