Browse Source

add formatter to attach a color variant to its data

axolotle 3 years ago
parent
commit
1405617850
1 changed files with 30 additions and 0 deletions
  1. 30 0
      src/helpers/formatter.js

+ 30 - 0
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
+}