0.1.2 • Published 10 months ago

@webreflection/re v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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

0.1.2

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago