JS Script Component
Execute custom JavaScript logic for advanced data processing.
Last updated:
The JS Script Component is the "Swiss Army Knife" of DataLensia pipelines. It allows you to write custom code to handle complex transformations that aren't possible with standard visual nodes.
⚙️ Configuration
- Script Editor: A full Monaco editor with syntax highlighting for writing your JavaScript logic.
🧪 Execution Context
Your script has access to several global variables:
| Variable | Description |
|---|---|
input | The primary input data (usually from the first upstream connection). |
inputs | An array of all inputs from all connected upstream nodes. |
getValue(path) | Helper to get a value from input using dot notation. |
getValueByPath(data, path) | Helper to get a value from any object using dot notation. |
🛡️ Security & Sandbox
Scripts are executed in a highly restricted sandbox:
- No Network Access:
fetch,XMLHttpRequest, etc., are disabled. - No DOM Access:
window,document, andnavigatorare undefined. - No Storage Access:
localStorageandcookiesare blocked. - Strict Mode: All scripts run in JavaScript "Strict Mode".
💡 Example
// Calculate total order value with a custom tax rate
return input.map(record => ({
...record,
total: record.price * (1 + (record.taxRate / 100)),
category: record.price > 100 ? 'Premium' : 'Standard'
}));