Files
plainleaf/plugs/federation/util.ts
T
Zef HemelandGitHub 25d14031c9 Fixes #926
Libraries have been rethought, see associated documentation.
2024-07-11 20:36:26 +02:00

15 lines
586 B
TypeScript

export function wildcardPathToRegex(pattern: string): RegExp {
// Escape special characters in the pattern except for the wildcard "*"
const escapedPattern = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
// Replace the wildcard "*" with ".*" to match any character sequence
const regexPattern = escapedPattern.replace(/\*/g, ".*");
// Create a new regular expression with the converted pattern
return new RegExp(`^${regexPattern}(\\.md)?$`);
}
export function federatedPathToLocalPath(path: string): string {
return path.split("/").slice(1).join("/");
}