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A,SAAU,GAExB,EAAgB,UAAU,EAAa,GAG7C,OAFsB,EAAA,aAAA,SAAU,EAAe,EAGhD,CAAC,MAAO,GACP,GACO,WADC,EAAI,KAER,MAAM,IAAI,MAAM,kBAEhB,MAAM,IAAI,MAAM,QAErB,CACF","file":"/npm/gendiff-cli@1.0.0/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/gendiff-cli@1.0.0/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/* @flow */\n\nimport _ from 'lodash';\nimport fs from 'fs';\nimport path from 'path';\nimport getParser from './parsers';\nimport getRender from './formatters';\n\nconst encoding = 'utf8';\n\nconst readData = filePath => ({\n  body: fs.readFileSync(filePath, encoding),\n  ext: path.parse(filePath).ext });\nconst buildTree = (before, after) => Object.keys({ ...before, ...after }).reduce((acc, key) => {\n  if (_.has(before, key) && _.has(after, key)) {\n    if (_.isEqual(before[key], after[key])) {\n      return [...acc, { type: 'same', key, value: before[key] }];\n    } else if (typeof before[key] === 'object') {\n      return [...acc, { type: 'same', key, value: buildTree(before[key], after[key]) }];\n    }\n    return [...acc, { type: 'change', key, value: after[key], oldValue: before[key] }];\n  }\n  return (_.has(before, key) ?\n          [...acc, { type: 'delete', key, value: before[key] }] :\n          [...acc, { type: 'new', key, value: after[key] }]);\n}, []);\n\nexport default (path1: string, path2: string, outputFormat = 'complex') => {\n  try {\n    const dataFromFile1 = readData(path1);\n    const dataFromFile2 = readData(path2);\n\n    const parsedData1 = getParser(dataFromFile1);\n    const parsedData2 = getParser(dataFromFile2);\n\n    const treeFromMerge = buildTree(parsedData1, parsedData2);\n    const diffFromMerge = getRender(treeFromMerge, outputFormat);\n\n    return diffFromMerge;\n  } catch (err) {\n    switch (err.code) {\n      case 'ENOENT':\n        throw new Error('File not found');\n      default:\n        throw new Error('Error');\n    }\n  }\n};\n"]}