Tool for quick data transforming.
It is pre-configured VS Code workspace with simple API for manipulating files. Any file located in bin directory is executed upon saving for very quick iterating.
- Download ZIP of this repository or fork it and clone.
- open _DeTeTe.code-workspace in VS Code (File -> Open Workspace from File...)
- VS Code will ask if you trust the authors of the files in this folder, you can anser 'no', review code and disable restricted mode later. If you choose 'yes', VS Code will install 3 extensions (dart, file watcher and vs code runner) and enable running dart files in bin directory when the file is saved.
- Run
dart pub get
in VS Code terminal do download dependencies.
You can write single use scripts in bin/scratchpad.dart. If you wish to keep script for longer, you can duplicate file bin/template.dart and name it appropriately.
Your code goes into transform()
method. Three things are required:
- Read input(s)
var content = input.readAsString(filepath: "inputs/input1.txt");
- Modify data
content = content.replaceAll("foo", "bar");
- Write output(s)
output.writeAsString(content, filepath: "outputs/output1.txt");
API supports chain calls to allow writing short code:
input
.readAsString(filepath: "inputs/input1.txt")
.replaceAll("foo", "bar")
.writeAsString(filepath: "outputs/output1.txt");
Complete example and more here: EXAMPLES
Your script can be run from command line providing alternative paths for inputs and outputs. For clarity input path and output path lists are separated.
dart run bin/scratchpad.dart -i inputs/arg1.txt inputs/arg2.txt -o outputs/arg1.txt
This will map provided paths to inputs/outputs in script in order of execution. For code:
var content1 = input.readAsLines(filepath: "inputs/input1.txt");
content1.sublist(0, 5).writeIterableAsString(filepath: "outputs/output1.txt");
var content2 = input.readAsLines(filepath: "inputs/input2.txt");
var outputContent1 = content1 + content2;
output.writeIterableAsString(outputContent1,
filepath: "outputs/output2.txt", skipInCliArgs: true);
Mapping will be as follows:
inputs/input1.txt
will be replaced withinputs/arg1.txt
outputs/output1.txt
will be replaced withoutputs/arg1.txt
inputs/input2.txt
will be replaced withinputs/arg2.txt
outputs/output2.txt
will NOT be replaced, becauseskipInCliArgs
parameter is used, which disables assigning new path from command line arguments
NOTE: Counts of paths provided in
-i
and-o
arguments must be equal to inputs/outputs defined in code (minus those withskipInCliArgs
set totrue
). Script will terminate if not enought path are provided. When too much paths are provided script will run normally.
API documentation can be found here: API