Currently Scripal has been tested only under a single JavaScript platform: Node.js. Scripal is most efficient when using UTF-8 as base encoding in JavaScript (default in Node.js). Using other encodings causes some performance overhead.
npm install scripal
Scripal relies on @makeomatic/ffi-napi, which requires modules nan and ref-napi
Now start to write your first code.
The JavaScript module is scripal.js. It consists of only one file.
See how to use Scripal in JavaScript test.js
The function scripal.baseInit(path) must be called once to initialize the library.
Every single thread must call scripal.libInit(config, encoding) to specify the entire path to the config file used (leave empty for default) and the encodig of the OS environment. scripal.ENC_DEFAULT will denote the standard.
const os = require('os');
const fs = require('fs');
// ffi-napi must be installed
// init functions
let lpath = "";
if (process.platform === "linux") {
global.scripal = require('./scripal');
}
if (process.platform === "win32") {
global.scripal = require('.\\scripal');
}
// set path to library or leave as "" for default
scripal.baseInit(lpath);
scripal.libInit("", scripal.ENC_UTF8);
scripal.logInit("buffer");
let obj = new scripal.TFScripal("source", "match find(bow 'a'); ifMatch matchEnd find(eow); loop;");
let result = obj.match("Find the words apple, ape and award.");
console.log("source match result: ", result , " , no. of results: " , obj.getResultSize());
for (let i = 0; i < obj.results.size(); i++) {
console.log(obj.results.text[i], obj.results.positions[i]);
}
for more information see matching with Scripal and library