Proper Way to Include External Scripts?

What is the proper way to “install” external scripts in Drafts? For example, I want to include number-in-letters script.

I downloaded index.min.js and rearmed it to “number-in-letters.min.js” It is saved in the Drafts/Library/Scripts folder in iCloud.

I then added a simple script:

const writtenNumber = require('number-in-letters.min.js');

alert(writtenNumber(12));

Running the script results in an Error.

Script Error: TypeError: writtenNumber is not a function. (In 'writtenNumber(12)', 'writtenNumber' is undefined)
Line number: 3, Column 20
1 Like

That particular library requires node.js so isn’t designed to work with something like Drafts. It also requires JSON files in a particular folder structure by the looks of it,

Browserify might be able to convert it for use in something like Drafts. Alternatively, you could write your own Drafts compatible version.