From 1405617850c97e40ece7732f3ec8de8cb2e763b1 Mon Sep 17 00:00:00 2001 From: axolotle Date: Sun, 23 May 2021 21:39:02 +0200 Subject: [PATCH] add formatter to attach a color variant to its data --- src/helpers/formatter.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/helpers/formatter.js diff --git a/src/helpers/formatter.js b/src/helpers/formatter.js new file mode 100644 index 0000000..6806890 --- /dev/null +++ b/src/helpers/formatter.js @@ -0,0 +1,30 @@ +const families = { + 9: 'depart', + 22: 'critique', + 63: 'echo', + 6: 'reflexion', + 7: 'lecture', + 8: 'sensible', + 23: 'kit' + // TODO creation ? +} + + +export function formatData (data, log = false) { + function formatSingle (text) { + text.variant = text.families ? families[text.families[0].id] : 'black' + for (const arrType of ['siblings', 'children', 'parents']) { + if (arrType in text && text[arrType]) { + formatData(text[arrType], log) + } + } + } + + if (Array.isArray(data)) { + data.forEach(formatSingle) + } else { + formatSingle(data) + } + + return data +}