@webreflection/re
v0.1.2
Published
A template literal tag that sanitizes interpolations
Downloads
7
Maintainers
Readme
@webreflection/re
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 👋