SevHope/frontend-project-46

View on GitHub
src/parser.js

Summary

Maintainability
A
0 mins
Test Coverage
B
80%
import { load } from 'js-yaml';

const parse = (data, type) => {
  switch (type) {
    case 'json':
      return JSON.parse(data);
    case 'yaml':
    case 'yml':
      return load(data);
    default:
      throw new Error(`Data type ${type} is incorrect!`);
  }
};

export default parse;