UNPKG

@ashraflabs/use-api

Version:

A simple and powerful custom React hook (useApi) that simplifies API requests with automatic loading and error states. Ideal for clean and maintainable data fetching in React components.

14 lines (13 loc) 497 B
/** * Removes multiple consecutive slashes from a string, preserving protocol slashes (e.g., http://). * @param str The input string, typically a URL or path. * @returns The string with multiple slashes reduced to a single slash. * @example * removeMultipleSlashes("http://example.com//api///data"); // "http://example.com/api/data" */ export function removeMultipleSlashes(str) { if (!str) return str; return str.replace(/(?<!https?:)\/+/g, "/").replace(/\/$/, ""); ; }