How to use the jsbeautifier.default_options function in jsbeautifier

To help you get started, we’ve selected a few jsbeautifier 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 beautify-web / js-beautify / python / test-jsbeautifier.py View on Github external
#!/usr/bin/env python2

import sys
from sys import stdout
import re

from jsbeautifier import beautify, default_options

tests_passed = 0

opts = default_options()

opts.indent_size = 4
opts.indent_char = ' '
opts.preserve_newlines = True
opts.jslint_happy = False
opts.keep_array_indentation = False
opts.brace_style = 'collapse'


def test_fragment(input, expectation = None):
    global opts
    if expectation == None:
        expectation = input

    res = beautify(input, opts)
    if res != expectation:
github beautify-web / js-beautify / python / test-perf-jsbeautifier.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import io
import os
import copy
import jsbeautifier
options = jsbeautifier.default_options()
options.wrap_line_length = 80
data = ''
data_min = ''


def beautifier_test_underscore():
    jsbeautifier.beautify(data, options)


def beautifier_test_underscore_min():
    jsbeautifier.beautify(data_min, options)

def beautifier_test_github_min():
    jsbeautifier.beautify(github_min, options)
github cs50 / style50 / style50 / languages.py View on Github external
def style(self, code):
        opts = jsbeautifier.default_options()
        opts.end_with_newline = True
        opts.operator_position = "preserve-newline"
        opts.wrap_line_length = 132
        opts.brace_style = "collapse,preserve-inline"
        opts.keep_array_indentation = True
        return jsbeautifier.beautify(code, opts)
github mitmproxy / mitmproxy / mitmproxy / contentviews.py View on Github external
def __call__(self, data, **metadata):
        opts = jsbeautifier.default_options()
        opts.indent_size = 2
        data = data.decode("utf-8", "replace")
        res = jsbeautifier.beautify(data, opts)
        return "JavaScript", format_text(res)
github Shu-Ji / wechat_micro_jump_game_hero / js_beautifier.py View on Github external
# coding: u8

import jsbeautifier


opts = jsbeautifier.default_options()
opts.indent_size = 2
opts.break_chained_methods = True
opts.comma_first = True

min_js_file_path = '../wx7c8d593b2c3a7703_3.wxapkg.unpack/game.js'
res = jsbeautifier.beautify_file(min_js_file_path)

open('./game.beautified2.js', 'w').write(res)
github enginespot / js-beautify-sublime / jsbeautify.py View on Github external
def run(self, edit):
    settings = self.view.settings()
    opts = jsbeautifier.default_options()
    for (k,v) in  opts.__dict__.items():
      if s.has(k):
        setattr(opts,k,s.get(k))
    # try to make it useful without any settings per project
    if s.get('use_original_indentation',False):
      setattr(opts,'indent_with_tabs',not settings.get('translate_tabs_to_spaces'))
      setattr(opts,'indent_size',int(settings.get('tab_size', 8)))
    selection = self.view.sel()[0]
    formatSelection = False
    # formatting a selection/highlighted area
    if(len(selection) > 0):
      formatSelection = True

    if formatSelection:
      self.format_selection(edit, opts)
    else:
github takeshixx / deen / deen / transformers / formats.py View on Github external
def content(self, data):
        assert isinstance(data, (bytes, bytearray))
        if not JSBEAUTIFIER:
            LOGGER.warning('jsbeautifier is not available')
            return
        opts = jsbeautifier.default_options()
        opts.unescape_strings = True
        try:
            data = jsbeautifier.beautify(data.decode(), opts)
        except (UnicodeDecodeError, TypeError) as e:
            self._error = e
            return
        self._content = bytearray(data.encode())
github trentrichardson / Clientside / Clientside.py View on Github external
def get_js_formatted(self, codestr):
		opts = jsbeautifier.default_options()
		opts.eval_code = False

		# pull indentation from user prefs
		use_tab = self.user_settings.get('translate_tabs_to_spaces',False)
		if use_tab:
			opts.indent_with_tabs = True
		else:
			opts.indent_char = " "
			opts.indent_size = int(self.user_settings.get('tab_size',False))
		
		# pull the rest of settings from our config
		for k,v in self.settings.get('jsformat', {}).iteritems():
			setattr(opts, k, v)
				
		return jsbeautifier.beautify(codestr, opts)