Hi,
These scripts have been made for my own use, but you are welcome to use them as well.
The first is a request API that aims to be closer to fetch
.
The API exposes POST
, PUT
and GET
operations with the most common defaults (JSON content, etc.).
Usage:
const { get, post, put } = importModule("requests");
// post, put and get also accept `headers`
const postResult = await post({ url: "https://...", body: {...} });
const putResult = await put({ url: "https://...", body: {...} });
const getResult = await get({ url: "https://..." });
You can get it here:
requests.js
The second is a module requirement script that allows sourcing Unpkg or other CDN modules, and caches the modules on iCloud for future use.
Usage:
const require = importModule("require");
// also accepts `forceDownload` to always use online version
const _ = await require({ moduleName: "lodash", url: "https://unpkg.com/lodash/lodash.min.js" });
// lodash.js is created in the Scriptable iCloud folder
// use _
The goal of this script is to allow you to embed third party libraries in your scripts easily and share them without having to source the actual libraries, and to be able to maintain / update third party scripts in Scriptable.
Note that the current implementation uses the Scriptable iCloud folder, but could be modified to use another folder.
An update script could also be created to download and maintain multiple modules.
The script is divided into 3 modules:
getString.js
getModule.js
require.js
All three of which need to be added as scripts to use require.js
.