Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
QuiteAFancyEmerald
GitHub Repository: QuiteAFancyEmerald/Holy-Unblocker
Path: blob/master/lib/rammerhead/src/util/URLPath.js
6530 views
1
/**
2
* for lazy people who don't want to type out `new URL('http://blah' + req.url).searchParams.get(ugh)` all the time
3
*/
4
module.exports = class URLPath extends URL {
5
/**
6
* @param {string} path - /site/path
7
*/
8
constructor(path) {
9
super(path, 'http://foobar');
10
}
11
/**
12
* @param {string} param - ?param=value
13
* @returns {string|null}
14
*/
15
get(param) {
16
return this.searchParams.get(param);
17
}
18
/**
19
* @returns {{[param: string]: string}}
20
*/
21
getParams() {
22
return Object.fromEntries(this.searchParams);
23
}
24
};
25
26