sensai
Version:
Because even AI needs a master
38 lines (37 loc) • 961 B
JavaScript
/**
* Extract URL path and search parameters.
* @notes we are not using URL or URLSearchParams because of speed.
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
parseUrl: function() {
return parseUrl;
},
sanitize: function() {
return sanitize;
}
});
const parseUrl = (url)=>{
const index = url.indexOf("?");
return index > -1 ? {
url: url.substring(0, index),
searchParams: url.substring(index + 1)
} : {
url,
searchParams: ""
};
};
const sanitize = (url)=>{
if (url === "/") return url;
const normalized = url.replace(/\/{2,}/g, "/");
const len = normalized.length;
return normalized[len - 1] === "/" ? normalized.substring(0, len - 1) : normalized;
};