export function sanitizeViewName(viewName: string) { try { const replaceIds = viewName .toLowerCase() .replace(/\/(\d+[^/]*)(?=\/|$)/g, '/{id}') // turn numbers to {id} placeholder .replace(/\/(null|undefined)(?=\/|$)/g, '/{id}') // turn null and undefined to {id} placeholder .replace(/\/([^/]*\.[a-z]+)(?=\/|$)/g, '/{id}') // turn file names to {id} placeholder .replace(/\/([^/]*[=%+][^/]*)(?=\/|$)/g, '/{id}') // turn dates, phone numbers and query parameters to {id} placeholder .replace(/(.+?)(\/+)$/, '$1') // remove '/' from the end of the line .replace(/(\/)(\/+)/g, '/') // remove duplicate '/' .replace('#', ''); if (replaceIds.startsWith('/proxy')) { return replaceIds.replace(/^\/proxy/, '/').replace(/\/[^/]*$/, ''); } return replaceIds; } catch (e) { // eslint-disable-next-line no-console console.error(e); return viewName; } }