Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

700 B
Raw Blame
const encodeSegment = (value: string): string => value.replaceAll('/', '/').replaceAll('\\', '\');

export const buildSegment = (name: string, isFolder: boolean): string => {
  const segment = encodeSegment(name);
  return isFolder ? `${segment}/` : segment;
};

export const toCanonicalTreePath = (path: string, isFolder: boolean): string =>
  isFolder && !path.endsWith('/') ? `${path}/` : path;

export const extractName = (path: string): string => {
  const trimmed = path.endsWith('/') ? path.slice(0, -1) : path;
  const lastSep = trimmed.lastIndexOf('/');
  const leaf = lastSep >= 0 ? trimmed.slice(lastSep + 1) : trimmed;
  return leaf.replaceAll('/', '/').replaceAll('\', '\\');
};