added doga
This commit is contained in:
24
25_02_24/node_modules/@tinyhttp/url/dist/index.js
generated
vendored
Normal file
24
25_02_24/node_modules/@tinyhttp/url/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
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
|
||||
Reference in New Issue
Block a user