function matchScheduledApiEndpoints(endpoints) {
const patterns = [
/api\/schedule\/[a-zA-Z0-9_-]+/, // Basic schedule endpoint
/api\/cron\/[a-zA-Z0-9_-]+/, // Cron schedule endpoint
/api\/recurring\/[a-zA-Z0-9_-]+/, // Recurring schedule endpoint
/api\/scheduled\/[a-zA-Z0-9_-]+/, // Another schedule endpoint
/api\/task\/schedule\/[a-zA-Z0-9_-]+/, // Task scheduling
];
for (const endpoint of endpoints) {
for (const pattern of patterns) {
if (new RegExp(pattern).test(endpoint)) {
return { endpoint, pattern }; // Return the matching endpoint and pattern
}
}
}
return null; // No match found
}
//Example usage
//const endpoints = ["/api/schedule/daily_report", "/api/cron/hourly_backup", "/api/some/other/endpoint"];
//const match = matchScheduledApiEndpoints(endpoints);
//if (match) {
// console.log(`Endpoint "${match.endpoint}" matches pattern "${match.pattern}"`);
//} else {
// console.log("No matching endpoint found.");
//}
Add your comment