From c992100a388acdacec636431bad440f0f036dd25 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Thu, 11 Jan 2018 21:36:43 -0800 Subject: [PATCH] added option to append CSV headers --- .../_locales/storage-jsdoc-strings.json | 5 ++++- libs/storage/_locales/storage-strings.json | 1 + libs/storage/storage-core.ts | 18 +++++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/libs/storage/_locales/storage-jsdoc-strings.json b/libs/storage/_locales/storage-jsdoc-strings.json index cd0cd6fb..e6a246f3 100644 --- a/libs/storage/_locales/storage-jsdoc-strings.json +++ b/libs/storage/_locales/storage-jsdoc-strings.json @@ -2,8 +2,11 @@ "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.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|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|param|data": "the data to append", "storage.Storage.appendLine|param|filename": "the file name to append data, eg: \"data.txt\"", diff --git a/libs/storage/_locales/storage-strings.json b/libs/storage/_locales/storage-strings.json index 7e651bb3..ee929629 100644 --- a/libs/storage/_locales/storage-strings.json +++ b/libs/storage/_locales/storage-strings.json @@ -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.appendLine|block": "storage %source|%filename|append line %data", "storage.Storage.append|block": "storage %source|%filename|append %data", diff --git a/libs/storage/storage-core.ts b/libs/storage/storage-core.ts index f8ae0b13..12ba8490 100644 --- a/libs/storage/storage-core.ts +++ b/libs/storage/storage-core.ts @@ -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 - * @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 */ //% blockId=storageAppendCSV block="storage %source|%filename|append CSV %data"