I’m trying to use the Dayjs time and date library in Scriptable, but I can’t get it to work. Any suggestions would be appreciated.
I saved the minified source code of Dayjs in a Scriptable file called Dayjs. Then I wrote this test code in another Scriptable file:
// Import the Dayjs library
const dayJS = "var/mobile/Library/Mobile Documents/iCloud~dk~simonbs~Scriptable/Documents/Dayjs.js";
let fmLocal = FileManager.local();
eval(fmLocal.readString(dayJS));
// Get today's date and format it
var today = dayjs();
today.format('MMM D');
(I’m using @sylumer’s technique for importing a library. Is there a better way now? I didn’t find anything else via Google.)
The script fails with this message:
2020-02-07 09:17:10: Error on line 7:18: ReferenceError: Can't find variable: dayjs
dayjs
is the base-level object of Dayjs. It should be created by the code that’s evaluated in Line 4. That evaluation seems to be working; I’ve checked the output of that line and it’s “true.”
Is there some namespace issue I’m not aware of? Do I need to do something other than eval
to have Scriptable understand the library?