Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const formatSingleFile = (value: string, browserify: boolean) => {
const result = `// tslint:disable\n/* eslint-disable */\n${prettier.format(value, {
arrowParens: 'always',
parser: 'typescript',
plugins: [parser],
printWidth: 120,
singleQuote: true,
trailingComma: 'all',
})}`;
return browserify ? result.replace(/'@neo-one\/client'/gu, "'@neo-one/client-browserify'") : result;
};
this.setState({
loading: false
})
if (response.headers.get('Content-Type') !== 'application/json') {
return this.setState({
error: await response.text()
})
}
const json = await response.json()
let plugin = { ...json }
plugin.code = `
optionsParam?: Options = DEFAULT_OPTIONS
) {
if (!model) {
throw new Error('slate-hyperprint: Expected a Slate model');
}
const options = {
...DEFAULT_OPTIONS,
...optionsParam
};
const printed = parse(model, options)
.map(tag => tag.print(options))
.join('\n');
const formatted = prettier.format(printed, {
...options.prettier,
parser: 'babylon',
plugins: [babylon]
});
const noSemi = formatted.trim().replace(/^;/, '');
return noSemi;
}
)
}, 1000)
const syntaxPlugins = Object.keys(availablePlugins)
.filter(it.startsWith('syntax') && it !== 'syntax-flow')
.map(it === 'syntax-decorators' ? [it, { decoratorsBeforeExport: false }] : it)
.map(it === 'syntax-pipeline-operator' ? [it, { proposal: 'minimal' }] : it)
const compilerPlugins = [...syntaxPlugins, plugin]
const compileSource = transform(_, {
presets: [],
plugins: compilerPlugins
}).code
const formatCompiled = prettier.format(_, {
parser: 'babylon',
plugins: [babylon],
printWidth: 50,
useTabs: false,
tabWidth: 2,
singleQuote: true,
semi: false
})
const handleCodeChange = () => {
const pos = editor.getSelection().getCursor()
const source = editor.getValue()
let initial
try {
initial = compileSource(source)
buttonElem.addEventListener("click", event => {
event.preventDefault();
const formattedText = prettier.format(textArea.value, {
parser: "markdown",
plugins: prettierPlugins
});
textArea.focus();
textArea.select();
document.execCommand("delete", false, null);
document.execCommand("insertText", false, formattedText);
});
}
const format = (code) => prettier.format(code, {
parser: 'typescript',
plugins: [parserTypescript],
singleQuote: true,
trailingComma: 'all',
});
const [value, setValue] = useState(() =>
prettier.format(JSON.stringify(defaultValue), {
parser: 'json',
plugins: [prettierBabylon]
})
)
const zipFile = (zip, { name, content, config }) =>
zip.file(name, prettier.format(content, config.prettier))
function format(text, width) {
const options = { ...config, printWidth: width, proseWrap: 'always' };
return prettier.format(text, options);
}
return (
{this.props.copy && (
<div> this.copy(source)} className="container">
{this.state.copied ? (
<span>Copied!</span>
) : (
<span>Copy</span>
)}
</div>
)}
{prettier
.format(source, { parser: "babylon", plugins: [babylon] })
.replace(">;", ">")}
);
}
}