doo.functions.scripts

Functions for working with external scripts. E. g. load external script from url.

Download external script

downloadScript

This function allows you to load an external java script. This can of course simplify the work a lot if there is a library for the task.

It depends on whether the function is run on the server. Check the script documentation to see if it allows both.

When the library is downloaded on the server, the require(library code) result is returned

On the client (in the browser) the script is run. That usually adds some property to the window object. This is then returned as the result (second parameter of the downloadScript function).

Best to show with examples.

Parse xml/json/csv

// download script
// on server it just require()
// in browser the script create a variable window.XLSX, which is returned
const XLSX = await doo.functions.scripts.downloadScript('https://cdn.sheetjs.com/xlsx-0.19.3/package/dist/xlsx.full.min.js', 'XLSX');

// example data
var data = [ { "name": "John", "city": "Seattle" }, { "name": "Zach", "city": "New York" } ];
const worksheet = XLSX.utils.json_to_sheet(data);
const csvOutput: string = XLSX.utils.sheet_to_csv(worksheet);

// show download file dialog
doo.functions.browser.saveFile(csvOutput, 'myfile2.csv', 'text/csv');