tezx
Version:
TezX is a high-performance, lightweight JavaScript framework designed for speed, scalability, and flexibility. It enables efficient routing, middleware management, and static file serving with minimal configuration. Fully compatible with Node.js, Deno, an
36 lines (35 loc) • 1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.wildcardOrOptionalParamRegex = void 0;
exports.sanitizePathSplit = sanitizePathSplit;
exports.urlParse = urlParse;
function normalizePath(path) {
return ("/" + path.replace(/\\/g, "").replace(/\/+/g, "/").replace(/^\/+/, ""));
}
function sanitizePathSplit(basePath, path) {
const parts = `${basePath}/${path}`
.replace(/\\/g, "")
.replace(/\/+/g, "/")
?.split("/")
.filter(Boolean);
return parts;
}
exports.wildcardOrOptionalParamRegex = /\/\*|:[^/]+[?*]/;
function urlParse(url) {
let u = URL.parse(url);
let query = {};
if (u?.search) {
new URLSearchParams(u?.search).forEach((value, key) => {
query[key] = value;
});
}
return {
pathname: u?.pathname,
query: query,
protocol: u?.protocol,
origin: u?.origin,
hostname: u?.hostname,
href: url,
port: u?.port,
};
}