UNPKG

@crazy-web/feedback

Version:

A feedback form handler package that shows a popup based on allowed URLs.

22 lines (21 loc) 959 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMatchedUrlItem = void 0; const getMatchedUrlItem = (url, data) => { for (const item of data) { for (const pattern of item === null || item === void 0 ? void 0 : item.allowed_url) { // Replace * in the pattern with a regex that matches any string except '/' const regexPattern = pattern .replace(/\*/g, "[^/]+") // Match any single URL segment (excluding '/') .replace(/\/$/, ""); // Normalize trailing slashes const regex = new RegExp(`^${regexPattern}$`); // Test if the URL matches the pattern if (regex.test(url.replace(/\/$/, ""))) { return item; // Return the matching item } } } // Return "not found" if no match is found after checking all patterns return null; }; exports.getMatchedUrlItem = getMatchedUrlItem;