Giter VIP home page Giter VIP logo

codepainter's Introduction

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.

codepainter's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.