Recursive matching plugin for the `regex` package
MIT License
Bot releases are hidden (Show)
Breaking changes
rregex
template tag previously provided as sugar. Instead of e.g. rregex`…`
, import the base regex
library separately and use regex({plugins: [recursion]})`…`
.regex-recursion.min.js
browser bundle from Regex.ext
to Regex.plugins
.Improvements
regex
v4.0.0 plugin API.Fixes
If desired, you can recreate the rregex
tag from previous versions:
import {regex} from 'regex';
import {recursion} from 'regex-recursion';
function rregex(first, ...values) {
const plugins = (first?.plugins || []).concat(recursion);
// Given a template
if (Array.isArray(first?.raw)) {
return regex({plugins})(first, ...values);
// Given flags
} else if ((typeof first === 'string' || first === undefined) && !values.length) {
return regex({flags: first, plugins});
// Given an options object
} else if ({}.toString.call(first) === '[object Object]' && !values.length) {
return regex({...first, plugins});
}
throw new Error(`Unexpected arguments: ${JSON.stringify([first, ...values])}`);
}
Published by slevithan 4 months ago
$rN
to _$N
.RegExp
instances, by throwing a descriptive error.n
is disabled.