use internal fetch function of node instead external node-fetch library if node version >= v18

This commit is contained in:
Karsten Hassel 2022-05-27 19:46:28 +02:00
parent cbda20f67e
commit 0023c64d59
23 changed files with 69 additions and 46 deletions

20
js/fetch.js Normal file
View file

@ -0,0 +1,20 @@
/**
* fetch
*
* @param {string} url to be fetched
* @param {object} options object e.g. for headers
* @class
*/
async function fetch(url, options) {
const nodeVersion = process.version.match(/^v(\d+)\.*/)[1];
if (nodeVersion >= 18) {
// node version >= 18
return global.fetch(url, options);
} else {
// node version < 18
const nodefetch = require("node-fetch");
return nodefetch(url, options);
}
}
module.exports = fetch;