uriPath.ts 490 B

123456789101112131415161718
  1. export function sanitizePath(input: string): string {
  2. let out = '';
  3. for (const ch of String(input ?? '')) {
  4. const code = ch.charCodeAt(0);
  5. if (ch === ':' || ch === '*' || ch === ' ' || ch === '\\' || code < 0x20 || code === 0x7f)
  6. continue;
  7. out += ch;
  8. }
  9. return out;
  10. }
  11. export function normalizePath(input: string): string {
  12. let p = input || '/';
  13. if (!p.startsWith('/')) p = '/' + p;
  14. if (!p.endsWith('/')) p += '/';
  15. p = p.replace(/\/+/g, '/');
  16. return p;
  17. }