How to use the js-beautify 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 vipshop / ams / docs / zh-CN / .vuepress / components / try / demo-try.vue View on Github external
get() {
                let fields
                if (this.templateIndex === 1) {
                    fields = this.configForm.blocks.routerBlock.blocks.chart1.data
                }
                const stringFields = JSON.stringify(fields)
                // return stringFields
                return beautify(stringFields, { indent_size: 4, space_in_empty_paren: true });
            },
            set(newvalue) {
github liriliri / eruda / src / Sources / Sources.js View on Github external
const data = this._data

    let code = data.val
    const len = data.val.length

    // If source code too big, don't process it.
    if (len < MAX_BEAUTIFY_LEN && this._formatCode) {
      switch (data.type) {
        case 'html':
          code = beautify.html(code, { unformatted: [] })
          break
        case 'css':
          code = beautify.css(code)
          break
        case 'js':
          code = beautify(code)
          break
      }

      const curTheme = evalCss.getCurTheme()
      code = highlight(code, data.type, {
        keyword: `color:${curTheme.keywordColor}`,
        number: `color:${curTheme.numberColor}`,
        operator: `color:${curTheme.operatorColor}`,
        comment: `color:${curTheme.commentColor}`,
        string: `color:${curTheme.stringColor}`
      })
    } else {
      code = escape(code)
    }

    if (len < MAX_LINE_NUM_LEN && this._showLineNum) {
github microsoft / vscode-js-debug / src / common / sourceUtils.ts View on Github external
export async function prettyPrintAsSourceMap(
  fileName: string,
  minified: string,
): Promise {
  const source = beautify(minified);
  const from = generatePositions(source);
  const to = generatePositions(minified);
  if (from.length !== to.length) return Promise.resolve(undefined);

  const generator = new sourceMap.SourceMapGenerator();
  generator.setSourceContent(fileName, source);

  // We know that AST for both sources is the same, so we can
  // walk them together to generate mapping.
  for (let i = 0; i < from.length; i += 2) {
    generator.addMapping({
      source: fileName,
      original: { line: from[i], column: from[i + 1] },
      generated: { line: to[i], column: to[i + 1] },
    });
  }
github vipshop / ams / docs / zh-CN / .vuepress / components / block / form / demo.vue View on Github external
mounted(){
        const stringConfig = stringify(block[this.blockName])
        this.configCode = beautify(stringConfig, { indent_size: 2, space_in_empty_paren: true })
        
        // 如果已经注册过则不再注册
        if (ams && ams.blocks && ams.blocks[this.blockName]) {
            this.init = true;
            return;
        }

        ams.block(`${this.blockName}`, block[this.blockName])

        this.init = true
    }
}
github vipshop / ams / docs / zh-CN / .vuepress / components / try / demo-try.vue View on Github external
onToProduceHTML(e){
            const config = beautify(stringify(this.filterConfig()), { indent_size: 4, space_in_empty_paren: true });
            downloadTemplate(e.currentTarget, this.templateFileName[this.templateIndex], config)
        }
    }
github ShailenNaidoo / hydrogen / src / services / service_worker / index.ts View on Github external
return {
      route,
      filename,
      index: filename === 'index.html',
      depth: path.length - 1,
    };
  }).sort((a, b): number => a.depth - b.depth);

  const serviceWorker = `
    const DEV = ${JSON.stringify(dev)};
    const routes = ${JSON.stringify(paths, null, 3)}

    ${swFile}
  `;

  const cleanUpFile = beautify(serviceWorker, { indent_size: 2, keep_array_indentation: true });

  return fs.outputFile(normalize(`${CWD}/dist/${sw}`), cleanUpFile);
};
github xtemplate / xtemplate / stories / gen-func.stories.js View on Github external
function jsBeauty(str) {
  const opts = {
    indent_size: '4',
    indent_char: ' ',
    preserve_newlines: true,
    brace_style: 'collapse',
    keep_array_indentation: false,
    space_after_anon_function: true,
  };
  return jsBeautify(str, opts);
}
github liriliri / eruda / src / Console / Log.js View on Github external
function formatJs(code) {
  const curTheme = evalCss.getCurTheme()
  return highlight(beautify(code), 'js', {
    keyword: `color:${curTheme.keywordColor}`,
    number: `color:${curTheme.numberColor}`,
    operator: `color:${curTheme.operatorColor}`,
    comment: `color:${curTheme.commentColor}`,
    string: `color:${curTheme.stringColor}`
  })
}
github aweary / json-to-graphql / src / index.js View on Github external
function createRootSchema(AST) {
  for (let key in AST) {
    const schema = AST[key]
    if (schema.customType) {
      rootTypes.push(schema.fieldsType)
      if (schema.nestedSchema) {
        createRootSchema(schema.nestedSchema)
      }
    }
    fields.push(schema.schema)
  }
  const root = schemaTemplate(fields.join(','), rootTypes)
  return beautify(root)
}