import babelPlugin from 'prettier/plugins/babel';
import estreePlugin from 'prettier/plugins/estree';
import prettier from 'prettier/standalone';
/**
* Formats code using Prettier
* @param {string} code - Code to be formatted
* @param {Object} config - Optional Prettier config
* @return {string}
*/
export default async function prettify(code, config = {}) {
try {
return await prettier.format(code, {
parser: 'babel',
plugins: [babelPlugin, estreePlugin],
printWidth: 80,
...config,
});
} catch (error) {
console.error(error);
return code;
}
}