formatter.js 595 B

123456789101112131415161718192021222324252627282930
  1. const families = {
  2. 9: 'depart',
  3. 22: 'critique',
  4. 63: 'echo',
  5. 6: 'reflexion',
  6. 7: 'lecture',
  7. 8: 'sensible',
  8. 23: 'kit'
  9. // TODO creation ?
  10. }
  11. export function formatData (data, log = false) {
  12. function formatSingle (text) {
  13. text.variant = text.families ? families[text.families[0].id] : 'black'
  14. for (const arrType of ['siblings', 'children', 'parents']) {
  15. if (arrType in text && text[arrType]) {
  16. formatData(text[arrType], log)
  17. }
  18. }
  19. }
  20. if (Array.isArray(data)) {
  21. data.forEach(formatSingle)
  22. } else {
  23. formatSingle(data)
  24. }
  25. return data
  26. }