Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor collapseLeadingSlashes function for simplicity and readability #183

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
11 changes: 2 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,9 @@ function serveStatic (root, options) {
* Collapse all leading slashes into a single slash
* @private
*/
function collapseLeadingSlashes (str) {
for (var i = 0; i < str.length; i++) {
if (str.charCodeAt(i) !== 0x2f /* / */) {
break
}
}

return i > 1
? '/' + str.substr(i)
: str
function collapseLeadingSlashes(str) {
return str.replace(/^\/+/, '/') || '/';
}

/**
Expand Down
Loading