* Removes everything after (and including) the first single slash (/) in a string, * but skips over '//' (double slashes), which are used in protocols like 'http://'. * This is primarily used to extract the base URL (protocol + host) from a full URL. * * Example: * removeAfterFirstSlash("htt
(inputString: string)
| 723 | * removeAfterFirstSlash("https://example.com") // "https://example.com" |
| 724 | */ |
| 725 | function removeAfterFirstSlash(inputString: string): string { |
| 726 | let i = 0; |
| 727 | const strLen = inputString.length; |
| 728 | while (i < strLen) { |
| 729 | const char = inputString[i]; |
| 730 | if (char === '/') { |
| 731 | // Check for double slash (e.g., 'http://') |
| 732 | if (i + 1 < strLen && inputString[i + 1] === '/') { |
| 733 | i += 2; |
| 734 | continue; |
| 735 | } else { |
| 736 | // Single slash: trim here |
| 737 | return inputString.substring(0, i); |
| 738 | } |
| 739 | } |
| 740 | i++; |
| 741 | } |
| 742 | // No single slash found (or only part of protocol), return the whole input |
| 743 | return inputString; |
| 744 | } |
| 745 | |
| 746 | /** |
| 747 | * Configuration class for API. |