GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - sandywu/codepainter: A JavaScript beautifier that can infer coding style from a sample

BranchesTags
Open more actions menu

Latest commit

 

History

20 Commits
20 Commits

Folders and files

NameName
Last commit message
Last commit date
bin
bin
 
 
lib
lib
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.markdown
README.markdown
 
 
codepainter.js
codepainter.js
 
 
package.json
package.json
 
 

Repository files navigation

Code Painter

Code Painter is a JavaScript beautifier that instead of asking you to manually specify the desired formatting style, can infer it from a code sample provided by you. This could, for instance, be a code snippet from the same project that your new code is supposed to be integrated with.

It uses the excellent Esprima parser by Ariya Hidayat (thanks!).

The name is inspired by Word's Format Painter, which does a similar job for rich text.

Usage

For now, it can only be used as a command-line tool but a Web version is in the works.

./bin/codepaint -i input.js -s sample.js -o output.js

transforms the input.js file using formatting style from sample.js and writes the output to output.js

-i and -o can both be ommitted, in that case standard I/O streams will be used.

./bin/codepaint -s sample.js < input.js > output.js

The style can still be specified manually with a JSON string as the --style argument:

./bin/codepaint --style '{ "QuoteType": "double" }' < input.js > output.js

Supported style properties

  1. Indentation: { character: '?', width: ? }

    Specifies the indentation used for scopes.

    character should be one of: ' ', '\t' and width should be a positive integer, e.g.:

    { character: ' ', width: 4 } or { character: '\t', width: 1 }

  2. LastEmptyLine: present, omitted

    Specifies if there should always be an empty line at the end of a file.

  3. QuoteType: single, double

    Specifies what kind of quoting you would like to use for string literals:

    console.log("Hello world!") -> console.log('Hello world!')

    Adds proper escaping when necessary, obviously.

    console.log('Foo "Bar" Baz') -> console.log("Foo \"Bar\" Baz")

  4. SpaceAfterControlStatements: present, omitted

    Specifies whether or not there should be a space between if/for/while and the following (.

    if(x === 4) -> if (x === 4) or while (foo()) { -> while(foo()) {

  5. SpaceAfterAnonymousFunctions: present, omitted

    Specifies whether or not there should be a space between function and () in anonymous functions.

    function(x) { } -> function (x) { }

  6. SpacesAroundOperators: present, omitted

    Specifies whether or not there should be spaces around operators such as +,=,+=,>=,!==.

    var x = 4; -> var x=4; or a>=b -> a >= b or a>>2 -> a >> 2

  7. TrailingWhitespaces: strip

    Specifies whether trailing whitespaces should be stripped from the end of the lines.

About

A JavaScript beautifier that can infer coding style from a sample

Resources

Readme
MIT license
Activity

Stars

2 stars

Watchers

1 watching

Forks

24 forks
Report repository

Releases

Packages

Contributors

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.