adding UtilsTest.convertDict2CSV

This commit is contained in:
frankknoll
2023-10-15 10:23:20 +02:00
parent 05e4b26087
commit 5cc2b0c99f
5 changed files with 2585 additions and 0 deletions

View File

@@ -24,4 +24,17 @@ class Utils {
static sliceDict(dict, start, end) {
return Object.fromEntries(Object.entries(dict).slice(start, end));
}
static convertDict2CSV(dict) {
const {'keys': columns, 'values': firstRow} = Utils.getKeysAlignedWithValues(dict);
return `${Utils.#quoteValues(columns)}\n${firstRow}`;
}
static #quoteValues(values) {
return values.map(Utils.#quoteValue);
}
static #quoteValue(value) {
return '"' + value + '"';
}
}