You can use JavaScript to extend the ability of LanceX.
Public API
$done()
function
Since all scripts run asynchronously, $done() should be called to indicate completion, even for scripts that do not require results. Otherwise, the script will print a warning due to a timeout.
Basic Information
$lancex
The object means that you are in the environment of LanceX.
Persistent Store
$persistentStore.write(data<String>, [key<String>])
Save data permanently. Only a string is allowed
$persistentStore.read([key<String>])
Get the saved data. Return a string or null.
Http Request
$httpClient.post(URL<String> or options<Object>, callback<Function>)
Start an HTTP POST request. The first parameter can be a URL or object. An example object may look like that.
{
url: "http://www.example.com/",
headers: {
"Content-Type": "application/json"
},
body: "{}",
timeout: 5,
callback: callback(error, response, data) {
}
}
The url
is always required. body
can be a string or object. When presenting an object, it is encoded to JSON string, and the Content-Type
is set to application/json
automatically.
Similar function: $httpClient.get
, $httpClient.put
,$httpClient.delete
, $httpClient.head
, $httpClient.options
, $httpClient.patch
.
fetch(URL<String>, options<Object>)
It’s an implementation of Fetch API, for example
fetch("http://www.example.com/",{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: "{}"
}).then(v=>v.text())
.then(v=>console.log(v));
Utilities
console.log(message<String>)
Log to LanceX logfile. Similar function: console.warn
, console.error
, console.info
.
setTimeout(function[, delay])
Same as the setTimeout in browsers. Similar function: setInterval
.
$notification.post(title<String>, subtitle<String>, body<String>, info<Object>)
Post a notification. Please turn on Allow Notifications
before using it. info
allows you to open a url when user clicks the notification. For example:
{
"open-url" : "https://www.example.com"
}