Resafe / quick-start
Quick Start
Get up and running with Resafe in minutes.
Basic Usage
Start by checking a regex pattern:
import { check } from "resafe";
// This will log warnings to console
check("(a+)+$");
/*
Output:
RESAFE Unsafe Regex! regex=/(a+)+$/
│ Spectral radius: 4 (threshold: 1)
│ ? Consider simplifying quantifiers
*/Production Guard
Use throwErr to prevent unsafe patterns in production:
import { check } from "resafe";
try {
check("^[0-9]+$", {
throwErr: true,
silent: true
});
// Pattern is safe, proceed with usage
const regex = new RegExp("^[0-9]+$");
} catch (error) {
console.error("Unsafe regex blocked:", error.message);
}Analyze Results
Get detailed analysis results:
import { check } from "resafe";
const result = check("(a+)+$", { silent: true });
console.log(result.safe); // false
console.log(result.radius); // 4.0
if (!result.safe) {
console.log(`Spectral radius ${result.radius} exceeds threshold`);
}