const stripLeadingSlash = s => s.indexOf('/') === 0 ? s.substring(1) : s
const stripEndingSlash = s => s.indexOf('/') === (s.length - 1) ? s.substring(0, s.length - 1) : s
The expression s.indexOf("/") returns the first index in the string. That means stripEndingSlash will only strip ending slashes from strings with exactly one slash. A string containing two slashes will return with the trailing slash still in place.
Problem
Note the following code found in /src/index.js
The expression
s.indexOf("/")
returns the first index in the string. That meansstripEndingSlash
will only strip ending slashes from strings with exactly one slash. A string containing two slashes will return with the trailing slash still in place.Example
Consider the following cases:
Suggestion
You could fix this by changing
indexOf
tolastIndexOf
, however, usingcharAt
provides a more readable and performant expression: