UNPKG

storybook-addon-playground

Version:

A playground to enable consumers learn how to use the component library or to reproduce bugs

33 lines (30 loc) 844 B
import { format } from 'prettier'; import parserHtml from 'prettier/parser-html'; import parserTypeScript from 'prettier/parser-typescript'; import parserPostCss from 'prettier/parser-postcss'; const jsxOptions = { parser: "typescript", arrowParens: "avoid", trailingComma: "es5", plugins: [parserHtml, parserTypeScript], }; const cssOptions = { parser: "css", plugins: [parserPostCss], }; function formatJsx(code) { return formatCode(code, jsxOptions); } function formatCss(code) { return formatCode(code, cssOptions); } function formatCode(code, options) { try { return format(code, options).replace(/;\s*$/, ""); } catch (e) { throw new Error(`[Playground Error]: Error formatting code: ${e}`); } } export { formatCss, formatJsx }; //# sourceMappingURL=prettier-utils.js.map