0.1.0 • Published 3 years ago

reg-ex-machina v0.1.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 years ago

reg-ex-machina

Regular expressions with timeout. Based on VM

Install

Yarn

yarn add reg-ex-machina

NPM

npm install reg-ex-machina

Usage

Common

const { test } = require('reg-ex-machina');

const regexp = /abc$/;
const stringOk = 'abc';
const stringNotOk = 'abcd';

const timeout = 5; //ms

test(regexp, stringOk, timeout); // true
test(regexp, stringNotOk, timeout); // false

const evilRegexp = /(a|a)+$/;
const evilString = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!';

test(evilRegexp, evilString, timeout); // throws error, because timeout exceeded

test

const { test } = require('reg-ex-machina');
// ...
test(regexp, string, timeout);

exec

const { exec } = require('reg-ex-machina');
// ...
exec(regexp, string, timeout);

search

const { search } = require('reg-ex-machina');
// ...
// reverse order, because search is a method of string
search(string, regexp, timeout);

matchAll

const { matchAll } = require('reg-ex-machina');
// ...
// reverse order, because matchAll is a method of string
matchAll(string, regexp, timeout);