mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-03-01 09:20:02 +00:00
Add setquerystring operator
This commit is contained in:
parent
261f0f5261
commit
9288420c67
@ -13,25 +13,11 @@ Filter operators for URL operations
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
exports["setquerystring"] = function(source,operator,options) {
|
exports["setquerystring"] = function(source,operator,options) {
|
||||||
var URL = $tw.browser ? window.URL : require("url").URL,
|
var name = operator.operands.length >= 1 ? operator.operands[0] : null,
|
||||||
URLSearchParams = $tw.browser ? window.URLSearchParams : require("url").URLSearchParams,
|
|
||||||
name = operator.operands.length >= 1 ? operator.operands[0] : null,
|
|
||||||
value = operator.operands.length >= 2 ? operator.operands[1] : "",
|
value = operator.operands.length >= 2 ? operator.operands[1] : "",
|
||||||
results = [];
|
results = [];
|
||||||
source(function(tiddler,title) {
|
source(function(tiddler,title) {
|
||||||
var url;
|
results.push($tw.utils.setQueryStringParameter(title,name,value));
|
||||||
try {
|
|
||||||
url = new URL(title);
|
|
||||||
} catch(e) {
|
|
||||||
}
|
|
||||||
if(url) {
|
|
||||||
var params = new URLSearchParams(url.search);
|
|
||||||
if(name) {
|
|
||||||
params.set(name,value);
|
|
||||||
}
|
|
||||||
url.search = params.toString();
|
|
||||||
results.push(url.toString());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
@ -10,6 +10,7 @@ title: Output
|
|||||||
<$let lf={{{ [charcode[10],[13]]}}}>
|
<$let lf={{{ [charcode[10],[13]]}}}>
|
||||||
|
|
||||||
<$text text={{{
|
<$text text={{{
|
||||||
|
[[$$$]setquerystring[habitat],[desert]]
|
||||||
[<url>setquerystring[]]
|
[<url>setquerystring[]]
|
||||||
[<url>setquerystring[animal],[elephant]]
|
[<url>setquerystring[animal],[elephant]]
|
||||||
[<url>setquerystring[animal],[elephant]setquerystring[animal],[ostrich]]
|
[<url>setquerystring[animal],[elephant]setquerystring[animal],[ostrich]]
|
||||||
@ -21,6 +22,7 @@ title: Output
|
|||||||
+
|
+
|
||||||
title: ExpectedResult
|
title: ExpectedResult
|
||||||
|
|
||||||
|
$$$
|
||||||
https://tiddlywiki.com/
|
https://tiddlywiki.com/
|
||||||
https://tiddlywiki.com/?animal=elephant
|
https://tiddlywiki.com/?animal=elephant
|
||||||
https://tiddlywiki.com/?animal=ostrich
|
https://tiddlywiki.com/?animal=ostrich
|
||||||
|
Loading…
x
Reference in New Issue
Block a user