Frontend/25_02_24/node_modules/@tinyhttp/url/dist/index.js

25 lines
726 B
JavaScript
Raw Normal View History

2025-02-25 08:55:29 +00:00
import { parse } from "node:querystring";
const getURLParams = ({ pattern, keys }, reqUrl = "/") => {
const matches = pattern.exec(reqUrl);
const params = {};
if (matches && typeof keys !== "boolean")
for (let i = 0; i < keys.length; i++) {
if (matches[i + 1]) {
params[keys[i]] = decodeURIComponent(matches[i + 1]);
}
}
return params;
};
const getQueryIndex = (url) => {
const index = url.indexOf("?");
return index === -1 ? url.length : index;
};
const getPathname = (url) => url.slice(0, getQueryIndex(url));
const getQueryParams = (url = "/") => parse(url.slice(getQueryIndex(url) + 1));
export {
getPathname,
getQueryParams,
getURLParams
};
//# sourceMappingURL=index.js.map