dmitryfirsanov/frontend-project-lvl2

View on GitHub
src/parser.js

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import yaml from 'js-yaml';

const parser = (file, format) => {
  switch (format) {
    case 'json':
      return JSON.parse(file);
    case 'yml':
    case 'yaml':
      return yaml.load(file);
    default:
      throw new Error(`Unsupported format - ${format}`);
  }
};

export default parser;