Resafe / api
API Reference
Complete API documentation for Resafe.
check(regex, options)
The primary function that analyzes regex patterns for ReDoS vulnerabilities.
import { check } from "resafe";
const result = check(pattern, options);
Parameters
regex
- Type:
string | RegExp - Required: Yes
- Description: The regex pattern to analyze
// String pattern
check("(a+)+$");
// RegExp object
check(/(a+)+$/);
options
- Type:
Options - Required: No
- Description: Configuration options
Options
| Property | Type | Default | Description |
|---|---|---|---|
threshold | number | 1.0 | Spectral radius threshold for unsafe patterns |
silent | boolean | false | Disable console logging |
throwErr | boolean | false | Throw error for unsafe patterns |
Return Value
Returns a Result object:
interface Result {
safe: boolean; // Whether the pattern is safe
radius: number; // Spectral radius value
}
checkAsync(regex, options)
Asynchronous version of check() that returns a Promise. Useful for integration with async workflows.
import { checkAsync } from "resafe";
const result = await checkAsync(pattern, options);
Parameters
Same as check():
regex:string | RegExp- The regex pattern to analyzeoptions:Options- Configuration options (optional)
Return Value
Returns a Promise<Result>:
interface Result {
safe: boolean;
radius: number;
}