1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-17 03:51:13 +02:00
Files
php-web-maker/app/lib/prettier-worker.js
Kushagra Gour b006b4849e build 3.6.0
2018-11-17 00:28:34 +05:30

30 lines
628 B
JavaScript

importScripts('./prettier/standalone.js');
function prettify({ content, type }) {
let plugins, parser;
if (type === 'html') {
importScripts('./prettier/parser-html.js');
parser = 'html';
}else if (type === 'js') {
parser = 'babylon';
importScripts('./prettier/parser-babylon.js');
}
else if (type === 'css') {
parser = 'css';
importScripts('./prettier/parser-postcss.js');
}
if (!parser) {
return content;
}
const formattedContent = prettier.format(content, {
parser,
plugins: self.prettierPlugins
});
return formattedContent || content;
}
onmessage = e => {
postMessage(prettify(e.data));
};