Custom Scripts

Allows you to write custom implementation of some features in Datasaur.

Custom Scripts feature can be found in Team workspace. You can hover to the left sidebar and click the Custom Scripts.

Click Create a New Script to start writing your script. We are currently allows you to write an import and export script.

We also provide the script template. You can follow the function and your script is ready to use.

/**
* This function should be written as this template and correctly implements ImportFunction interface.
*/
(fileContent: string): SimpleDocument => {
/// Implement import function here
return {
name: 'Document name',
cells: [],
labels: [],
};
};

Sample Case

We want to label a subtitle file in .srt format and show the timestamp as metadata. The custom script will be shown below.

/**
* This function should be written as this template and correctly implements ImportFunction interface.
*/
(fileContent: string): SimpleDocument => {
/// Implement import function here
const lines = fileContent.split('\r\n\r\n');
let currLine: number = 0;
const cells: Cell[] = [];
lines.forEach((line) => {
const [, timestamp, ...subtitles] = line.split('\r\n');
subtitles.forEach((subtitle) => {
cells.push({
index: 0,
line: currLine,
content: subtitle,
tokens: subtitle.split(' '),
metadata: [
{key: "timestamp", value: timestamp, pinned: true, config: { color: "#3399cc", backgroundColor: "", borderColor: "#cc3399"}}
]
});
currLine += 1;
});
});
return {
name: "Document name",
cells,
labels: [],
};
};

Let's try this out!

The first step is you have to rename the file by adding .txt. You can use the following sample file.

Click Custom Script, then copy and paste the script above.

After uploading the file, choose the Subtitle script on the Custom Import script dropdown. Finish the project creation and launch the project.

Your project is ready!

Notes

  • You need to add Metadata extension to the project.

  • If you want to the metadata is readable in the text editor, set pinned: true.

  • Use HTML code color for text color, border color, and background color.

    If you have any questions, please reach out to [email protected]