8000 GitHub - WebReflection/re: A template literal tag that sanitizes interpolations.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

WebReflection/re

Repository files navigation

@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 👋

About

A template literal tag that sanitizes interpolations.

Resources

License

Stars

Watchers

Forks

Packages

No packages published
0