Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
// /:slug -> { name: "slug", modifier: "" }
// /:slug* -> { name: "slug", modifier: "*" }
// /:slug? -> { name: "slug", modifier: "?" }
// /* -> { wildcard: "*" }
const tokenRegex = /:(?<name>\w+)(?<modifier>[?*]?)|(?<wildcard>(?<!:\w+)\*)/;
export const isPathnamePattern = (pathname: string) =>
tokenRegex.test(pathname);
// use separate regex from matchAll because regex.test is stateful when used with g flag
const tokenRegexGlobal = new RegExp(tokenRegex.source, "g");
export const matchPathnameParams = (pathname: string) => {
return pathname.matchAll(tokenRegexGlobal);
};
export const removeTrailingSlash = (pathname: string) => {
let end = pathname.length;
while (end > 1 && pathname[end - 1] === "/") {
end -= 1;
}
return pathname.slice(0, end);
};
/**
* Check if a string is an absolute URL (has a valid protocol)
*/
export const isAbsoluteUrl = (href: string) => {
try {
new URL(href);
return true;
} catch {
return false;
}
};