krivtsov/project-lvl2-s93

View on GitHub
src/formats/json.js

Summary

Maintainability
A
0 mins
Test Coverage

const getJson = (ast) => {
  const result = ast.reduce((acc, obj) => ({
    ...acc,
    [obj.type]: {
      key: obj.key,
      oldValue: obj.oldValue,
      newValue: obj.newValue,
      children: obj.children,
    },
  }), {});

  return JSON.stringify(result, null, 2);
};


export default getJson;