JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4240
  • Score
    100M100P100Q125566F

jsbeautifier.org for grunt

Package Exports

  • grunt-jsbeautifier/tasks/jsbeautifier

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (grunt-jsbeautifier) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

grunt-jsbeautifier

jsbeautifier.org for grunt

Getting Started

This plugin recommends using Grunt ~0.4.1. Grunt ~0.3.0 is only suported till version 0.1.4

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

Grunt ~0.4.1

npm install grunt-jsbeautifier --save-dev

One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-jsbeautifier');

Grunt ~0.3.0

Install this grunt plugin next to your project's grunt.js gruntfile with:

npm install grunt-jsbeautifier@0.1.4

Then add this line to your project's grunt.js gruntfile:

grunt.loadNpmTasks('grunt-jsbeautifier');

Examples

Single Task

  • files (required): Your source files to beautify
  • options (optional): Overwrite default jsbeautifier options
"jsbeautifier" : {
    files : ["src/**/*.js"],
    options : {
    }
}

Multi Task

  • src (required): Your source files to beautify
  • options (optional): Overwrite default jsbeautifier options
"jsbeautifier" : {
    "default": {
        src : ["src/**/*.js"]
    },
    "git-pre-commit": {
        src : ["src/**/*.js"],
        options : {
            mode:"VERIFY_ONLY"
        }
    }
}

Config

files

Type: Files Default value: []

List of files to be beautified. This option is applicable only for Single Task

src

Type: Files Default value: []

List of files to be beautified. This option is applicable only for Multi Task

mode (optional)

Type: String Default value: VERIFY_AND_WRITE

If mode is "VERIFY_ONLY", then task will fail if at least one file can be beautified. This is useful for pre-commit check.

config (optional)

Type: String

The file path (relative to your process's cwd) to the config file. This is usually in JSON format, and named .jsbeautifyrc (like the one supported by js-beautify itself)

Default options from jsbeautifier.org can be used

"jsbeautifier": {
    files: ["src/**/*.js"],
    config: "path/to/configFile",
    options: {
        "html": {
            "brace_style": "collapse",
            "indent_char": " ",
            "indent_scripts": "keep",
            "indent_size": 4,
            "max_preserve_newlines": 10,
            "preserve_newlines": true,
            "unformatted": ["a", "sub", "sup", "b", "i", "u"],
            "wrap_line_length": 0
        },
        "css": {
            "indent_char": " ",
            "indent_size": 4
        },
        "js": {
            "brace_style": "collapse",
            "break_chained_methods": false,
            "e4x": false,
            "eval_code": false,
            "indent_char": " ",
            "indent_level": 0,
            "indent_size": 4,
            "indent_with_tabs": false,
            "jslint_happy": false,
            "keep_array_indentation": false,
            "keep_function_indentation": false,
            "max_preserve_newlines": 10,
            "preserve_newlines": true,
            "space_before_conditional": true,
            "space_in_paren": false,
            "unescape_strings": false,
            "wrap_line_length": 0
        }
    }
},

Only specifiy options to overwrite

Tips

1. Exclude files

All files from foo folder except bar.js

jsbeautifier: {
    files: ['foo/*.js', '!foo/bar.js']
}

Release History

  • 0.2.0: Added support for css, html and json files
  • 0.1.10: Added verify only mode 15. This will fail if any file needs beautification.
  • 0.1.9: Upgraded js-beautify to 1.4.0. Fixed issues 13
  • 0.1.8: Upgraded js-beautify to ~1.3.1. Fixed issues 10, 12
  • 0.1.7: Upgraded grunt to ~0.4.1, js-beautify to ~1.2.0. Fixed issues 6, 7, 8, 9
  • 0.1.6: Make sure new line at the end of file. Fixed issue 5
  • 0.1.5: Upgraded to grunt ~0.4.0. Fixed issues 2, 3, 4
  • 0.1.4: Upgraded js-beautify to latest version (0.3.2)
  • 0.1.3: Added fix for block comment formatting.
  • 0.1.2: Supported grunt 0.4~.
  • 0.1.1: Readme file changes
  • 0.1.0: Initial version.

License

Copyright (c) 2012 Vishal Kadam
Licensed under the MIT license.