npm.io
0.6.1 • Published 1 month ago

@bufbuild/re2

Licence
MIT
Version
0.6.1
Deps
0
Size
399 kB
Vulns
0
Weekly
0
Stars
38

@bufbuild/re2

This package provides an RE2-compatible regular expression engine, designed for use with CEL-es and Protovalidate-es.

Usage

import { RE2JS } from '@bufbuild/re2';

const re = new RE2JS('^foo');
console.log(re.test('foo')); // true
console.log(re.testExact('fooxyz')); // false

console.log(RE2JS.matches('^foo','foo')); // true

Limitations

Only boolean matchers are supported: test and testExact.

The instance method matches is an alias for testExact. The static method RE2JS.matches compiles a regular expression and calls testExact.

As a size optimization, Unicode category and script information is generated on first use. This causes a slight slowdown the first time a pattern is compiled with a category or script (only the referenced category or script is generated). The categories and scripts in Unicode version 16.0 are supported. This package includes data to support Unicode version 16.0 on Unicode 15.0 or later.

Credits

This code is a fork of the RE2JS project. It has been converted to TypeScript and has a feature set tailored for CEL and Protovalidate-es.

Keywords