How to use the js-beautify.javascript function in js-beautify

To help you get started, we’ve selected a few js-beautify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jsbin / jsbin / src / lib / CodeMirror / ext-formatter.js View on Github external
import CodeMirror from 'codemirror';
import { cmCmd } from '../is-mac';

// FIXME I want to *only* use the HTML formatter, and then use prettier
// for js, CSS and JSON - but I need something working now, so this is a start.
import * as tidy from 'js-beautify';
tidy.javascript = tidy.js; // alias to allow our named sources to work

CodeMirror.defineOption('autoFormat', false, (cm, autoFormatOn) => {
  if (autoFormatOn) {
    cm.on('keyHandled', (cm, name) => {
      if (name === `${cmCmd}-S`) {
        cm.autoFormat(cm);
      }
    });
  }
});

CodeMirror.defineExtension('autoFormat', cm => {
  let from, to;
  const doc = cm.doc;

  if (doc.somethingSelected()) {