Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
regexp-worker
Advanced tools
Execute Regular Expression Matches on a Node Worker Thread.
Regular Expressions can suffer from Catastrophic Backtracking. A very simple expression like /(x+x+)+y/
can cause your JavaScript application to freeze. This library allows you to run these expressions on another thread. If they take to long to complete, they are terminated, protecting your application from locking up.
npm install regexp-worker
In the example below:
For the occasional request, this is the easiest way, but the Worker startup and shutdown is expensive.
import { execRegExpOnWorker } from 'regexp-worker'
//...
const response = await execRegExpOnWorker(/\b\w+/g, 'Good Morning')
console.log(response.matches.map(m => m[0]))
Result:
console.log
[ 'Good', 'Morning' ]
import { execRegExpOnWorker } from 'regexp-worker'
//...
const response = await execRegExpOnWorker(/\b/g, 'Good Morning');
console.log(response.matches.map(m => m.index))
Result:
console.log
[ 0, 4, 5, 12 ]
interface ExecRegExpResult {
elapsedTimeMs: number;
matches: RegExpExecArray[];
}
Where RegExpExecArray
is RegExp.prototype.exec() result.
RegExpWorker
InstanceTo reduce the cost of starting and stopping the Worker, it is possible to create a RegExpWorker
instance.
This instance allows you to make multiple requests using the same worker. The request are queued and handled
one at a time. If a request takes too long, it is terminated and the promise is rejected with an ErrorCanceledRequest
.
import { RegExpWorker } from 'regexp-worker'
// ...
const defaultTimeOutMs = 10
const worker = new RegExpWorker(defaultTimeOutMs);
// Find all words in some text
let words = await worker.execRegExp(/\b\w+/g, 'Lots of text ...')
// Find all numbers in some text
let numbers = await worker.execRegExp(/\b\d+/g, 'Lots of text ...')
// Find 3 letter word pairs
let moreTimeMs = 100
let numbers = await worker.execRegExp(/\b\w{3}\s+\w{3}/g, 'Lots of text ...', moreTimeMs)
// ...
// It is a good idea to dispose of the worker before shutdown.
// The worker thread will stop on its own if left idle for more than 200ms.
worker.dispose();
If the request times out, the promise will be rejected with:
interface TimeoutError {
message: string;
elapsedTimeMs: number;
}
FAQs
Runs regular expressions on a background thread.
The npm package regexp-worker receives a total of 158 weekly downloads. As such, regexp-worker popularity was classified as not popular.
We found that regexp-worker demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.