Giter Site home page Giter Site logo

node-beautify's Introduction

Node-Beautify

Node-Beautify is a node.js module that can be easily required and used to beautify assets from within a Node.js script. It is not meant to be a command-line tool, there are plenty of existing tools for that. The purpose of Node-Beautify is for javascript based build scripts or the like that want to be able to 'require' a beautifier module. Currently it only supports javascript. The original intent was to encapsulate additional syntax support, such as css. I may still do that at some point, but if you would like to add another formatting parser in the meantime, feel free to fork this repo and send a pull request.

Installation

npm install node-beautify

Usage

to beautify javascript:

    require('node-beautify').beautifyJs(source, options);

where source is a string of javascript source code and options (optional) allows overriding the defaults (see below)

Default Options

  • indentSize : 4
  • indentChar : ' ' (space character)
  • preserveNewlines : true
  • bracesOnOwnLine : false
  • keepArrayIndentation : false
  • spaceAfterAnonFunction: true
  • indentLevel : 0

Example

// require the module
var nb = require('node-beautify');

// pass a string of ugly javascript to the beautifyJs method
var prettyJs = nb.beautifyJs("function test(){console.log('test');}");

// the results should be a nicely formatted javascript string
console.log(prettyJs);

To run tests

Mocha should be installed globally. If it is not, you can install it by typing

npm install mocha -g

Clone the repository using git, e.g.

git clone https://github.com/fshost/node-beautify

After the repo has been cloned, in the repo directory type

npm install

After all dependencies are installed, the tests can be run by typing

mocha

Requirements

  • node.js

Acknowledgements

The original JS Beautifier is written by Einar Lielmanis.

License

MIT-License, see LICENSE.txt.

Roadmap

  • Add support for other asset types
  • Integrate into Node Build Tool

node-beautify's People

Contributors

fshost avatar janpaepke avatar rhalff 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.