Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSBeautify options for programmatic use? #1327

Closed
ORESoftware opened this issue Jan 16, 2018 · 3 comments
Closed

JSBeautify options for programmatic use? #1327

ORESoftware opened this issue Jan 16, 2018 · 3 comments
Milestone

Comments

@ORESoftware
Copy link

ORESoftware commented Jan 16, 2018

With this code in mind:

  context(b => {
        before(async h => {

            await driver.get('https://github.com/notifications');



        });
   });

I'd like to be able to remove excess blank lines. I looked at the readme, all the options are CLI options. Where can I find the options for programmatic use instead of CLI use? I can't seem to find the docs for programmatic use.

I asked this question on SO...https://stackoverflow.com/questions/48273979/js-beautify-programmatic-options-api

@bitwiseman bitwiseman added this to the v1.7.x milestone Jan 17, 2018
@bitwiseman
Copy link
Member

Beautifier can remove blank lines between tokens using the preserve_newlines: false setting or limit the number of newlines using the max_preserve_newlines with a number value.

An example of API level usage is show in https://github.com/beautify-web/js-beautify#javascript .

The configuration option names are the same as the CLI names but with underscores instead of dashes.

So to remove all empty lines:

import {js_beautify} from 'js-beautify';

const originalCode = `
    const foo = 'bar';



    console.log(foo);
`)


const beautifiedCode = js_beautify(originalCode, { indent_size: 2, preserve_newlines: false})

@bitwiseman
Copy link
Member

Thanks for your feedback! I've made updates in d092453 to make this clearer.

@ORESoftware
Copy link
Author

cool thank you

@bitwiseman bitwiseman modified the milestones: v1.7.x, v1.7.6 May 21, 2018
@bitwiseman bitwiseman modified the milestones: v1.8.0-rc2, 1.8.0 Aug 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants