Skip to content

v4.0.0

Latest
Compare
Choose a tag to compare
@slevithan slevithan released this 07 Aug 20:46

Breaking changes

  • Removed the rregex template tag previously provided as sugar. Instead of e.g. rregex`…`, import the base regex library separately and use regex({plugins: [recursion]})`…`.
  • Changed the global name in the regex-recursion.min.js browser bundle from Regex.ext to Regex.plugins.

Improvements

  • Updated documentation and tests to use the regex v4.0.0 plugin API.

Fixes

  • Fixed a syntax error when using a named backreference within recursion that references a group outside of the recursive subpattern.

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])}`);
}