123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- const SHORTENED_TYPE = {
- organizations: 'org',
- customers: 'customer',
- projects: 'project',
- teams: 'team',
- };
- export function sanitizePath(path: string) {
- return path.replace(
- /(?<start>.*?)\/(?<type>organizations|customers|projects|teams)\/(?<primarySlug>[^/]+)\/(?<contentType>[^/]+\/)?(?<tertiarySlug>[^/]+\/)?(?<end>.*)/,
- function (...args) {
- const matches = args[args.length - 1];
- const {start, type, contentType, tertiarySlug, end} = matches;
-
- const isOrg = ['organizations', 'customers'].includes(type);
- const isProject = type === 'projects';
- const isRuleConditions = isProject && contentType === 'rule-conditions/';
-
-
- let suffix = `${tertiarySlug ?? ''}${end}`;
- if (isOrg && contentType === 'events/' && typeof tertiarySlug === 'string') {
-
-
- suffix = tertiarySlug.replace(/[^:]+(.*)/, '{projectSlug}$1');
- } else if (isOrg && contentType === 'members/') {
-
-
- suffix = `${tertiarySlug}${end.replace(
- /teams\/([^/]+)\/$/,
- 'teams/{teamSlug}/'
- )}`;
- } else if (isProject && tertiarySlug === 'teams/') {
-
-
- suffix = `${tertiarySlug}{teamSlug}/`;
- } else if (isRuleConditions) {
-
-
- suffix = '';
- }
- const contentTypeOrSecondarySlug = isOrg
- ? contentType ?? ''
- : isRuleConditions
- ? 'rule-conditions/'
- : `{${SHORTENED_TYPE[type]}Slug}/`;
- return `${start}/${type}/{orgSlug}/${contentTypeOrSecondarySlug}${suffix}`;
- }
- );
- }
|