Extend Stof
Extending Stof with custom libraries.
Stof is extended with libraries. In a TypeScript context, Stof allows you to call your TypeScript functions directly from Stof using this feature.
Insert Library
In this example, we add a single function called "add" in a Stof library named "CustomLibrary". To call this function from Stof, reference the library name and function name just like any other library: CustomLibrary.add(...)
.
You may build a library with multiple, separate calls to insertLibrary with the same library name. Functions will be added or replaced if the names collide.
Document Context
When Stof calls out to TypeScript, it sets the StofDoc as the current context ("this").
The StofDoc is not the same thing as the Stof interface provided by the package. StofDoc is what is held within the Stof interface. Take a look at the JSR package for more information and documentation on the StofDoc object.
In JavaScript, arrow functions do not have a "this" context, so when you define your library functions, do so with the "function" keyword if you intend to work with the document.
Last updated
Was this helpful?