1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-09 13:59:41 +00:00
TiddlyWiki5/core/modules/filters/url-ops.js
jeremy@jermolene.com 4b9a6b5757 Add a Zotero demo for the new http mechanism
An initial experiment for handling paginated APIs. This isn't perfect; it isn't possible to interrupt things, for example.
2023-01-18 09:06:34 +00:00

40 lines
912 B
JavaScript

/*\
title: $:/core/modules/filters/url-ops.js
type: application/javascript
module-type: filteroperator
Filter operators for URL operations
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports["setquerystring"] = function(source,operator,options) {
var URL = $tw.browser ? window.URL : require("url").URL,
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] : "",
results = [];
source(function(tiddler,title) {
var url;
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;
};
})();