Include

Include

JavaScriptCore doesn’t offer any generic ways to manage packages. But package management is important, even what you write are really simple scripts.

Thus OK JSON offers a dead simple $include method to manage packages. Think of it as a text-replacment method. You shouldn’t expect any other features from $include.

How to Use $include

Step 1

Create a new folder name packages in the scripts folder.

Step 2

Places your packages in the packages folder.

Step 3

Include the package in your script with $include. You need to omit the js extension.

Example

Step 1

Create a file named hello-world.js in the packages folder.

hello-world.js
const text = 'Hello World';

Step 2

OK JSON will replace $include('hello-world'); with the script content so that you can access the text variable directly.

/*
@okjson.schemaVersion 1
@okjson.name Include Example
@okjson.description A $include example.
@okjson.openResultInNewWindow no
*/
 
$include('hello-world');
 
function main(string) {
  $alert.info('Now', text);
  return '';
}

So the actual script becomes:

/*
@okjson.schemaVersion 1
@okjson.name Include Example
@okjson.description A $include example.
@okjson.openResultInNewWindow no
*/
 
const text = 'Hello World';
 
function main(string) {
  $alert.info('Now', text);
  return '';
}