added option to append CSV headers

This commit is contained in:
Peli de Halleux 2018-01-11 21:36:43 -08:00
parent 20a4673f98
commit c992100a38
3 changed files with 22 additions and 2 deletions

View File

@ -2,8 +2,11 @@
"storage.Storage.append": "Append string data to a new or existing file.", "storage.Storage.append": "Append string data to a new or existing file.",
"storage.Storage.appendBuffer": "Append a buffer to a new or existing file.", "storage.Storage.appendBuffer": "Append a buffer to a new or existing file.",
"storage.Storage.appendCSV": "Append a row of CSV data", "storage.Storage.appendCSV": "Append a row of CSV data",
"storage.Storage.appendCSVHeaders": "Append a row of CSV headers",
"storage.Storage.appendCSVHeaders|param|filename": "the file name to append data, eg: \"data.csv\"",
"storage.Storage.appendCSVHeaders|param|headers": "the data to append",
"storage.Storage.appendCSV|param|data": "the data to append", "storage.Storage.appendCSV|param|data": "the data to append",
"storage.Storage.appendCSV|param|filename": "the file name to append data, eg: \"data.txt\"", "storage.Storage.appendCSV|param|filename": "the file name to append data, eg: \"data.csv\"",
"storage.Storage.appendLine": "Appends a new line of data in the file", "storage.Storage.appendLine": "Appends a new line of data in the file",
"storage.Storage.appendLine|param|data": "the data to append", "storage.Storage.appendLine|param|data": "the data to append",
"storage.Storage.appendLine|param|filename": "the file name to append data, eg: \"data.txt\"", "storage.Storage.appendLine|param|filename": "the file name to append data, eg: \"data.txt\"",

View File

@ -1,4 +1,5 @@
{ {
"storage.Storage.appendCSVHeaders|block": "storage %source|%filename|append CSV headers %headers",
"storage.Storage.appendCSV|block": "storage %source|%filename|append CSV %data", "storage.Storage.appendCSV|block": "storage %source|%filename|append CSV %data",
"storage.Storage.appendLine|block": "storage %source|%filename|append line %data", "storage.Storage.appendLine|block": "storage %source|%filename|append line %data",
"storage.Storage.append|block": "storage %source|%filename|append %data", "storage.Storage.append|block": "storage %source|%filename|append %data",

View File

@ -61,8 +61,24 @@ namespace storage {
} }
/** /**
* Append a row of CSV headers
* @param filename the file name to append data, eg: "data.csv"
* @param headers the data to append
*/
//% blockId=storageAppendCSVHeaders block="storage %source|%filename|append CSV headers %headers"
appendCSVHeaders(filename: string, headers: string[]) {
let s = ""
for (const d of headers) {
if (s) s += "\t"
s = s + d;
}
s += "\r\n"
this.append(filename, s)
}
/**
* Append a row of CSV data * Append a row of CSV data
* @param filename the file name to append data, eg: "data.txt" * @param filename the file name to append data, eg: "data.csv"
* @param data the data to append * @param data the data to append
*/ */
//% blockId=storageAppendCSV block="storage %source|%filename|append CSV %data" //% blockId=storageAppendCSV block="storage %source|%filename|append CSV %data"