mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-05-02 06:26:16 -04:00
refactor URL generators
This commit is contained in:
parent
9fb7aee589
commit
37ee3b1c7c
2 changed files with 40 additions and 49 deletions
21
js/common.js
21
js/common.js
|
@ -131,3 +131,24 @@ exports.jscMimeTypes = function() {
|
|||
exports.jscFormats = function() {
|
||||
return jsc.elements(formats);
|
||||
};
|
||||
|
||||
// provides random URLs
|
||||
exports.jscUrl = function(withFragment = true, withQuery = true) {
|
||||
let url = {
|
||||
schema: exports.jscSchemas(),
|
||||
address: jsc.nearray(exports.jscA2zString()),
|
||||
};
|
||||
if (withFragment) {
|
||||
url.fragment = jsc.string;
|
||||
}
|
||||
if(withQuery) {
|
||||
url.query = jsc.array(exports.jscQueryString());
|
||||
}
|
||||
return jsc.record(url);
|
||||
};
|
||||
|
||||
exports.urlToString = function (url) {
|
||||
return url.schema + '://' + url.address.join('') + '/' + (url.query ? '?' +
|
||||
encodeURI(url.query.join('').replace(/^&+|&+$/gm,'')) : '') +
|
||||
(url.fragment ? '#' + encodeURI(url.fragment) : '');
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue