GithubHelp home page GithubHelp logo

stevenbenner / grunt-indent Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 3.0 41 KB

:bookmark_tabs: A Grunt task to change the indentation of files.

License: MIT License

JavaScript 94.33% CSS 5.67%
grunt grunt-plugins grunt-task javascript indentation nodejs

grunt-indent's Introduction

grunt-indent

A grunt task to change the indentation of files.

Build Status Dependency Status npm

Getting Started

This plugin requires Grunt >=0.4.0

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:

npm install grunt-indent --save-dev

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

grunt.loadNpmTasks('grunt-indent');

The "indent" task

Overview

This task will let you increase or decrease the indentation of lines within files. It simply walks all of the lines in the specified files, adds or removes indents as you specify in the options, and saves the modified files to the location you want.

This is useful for building JavaScript projects where you want the built/concatenated files to have proper indentation.

Options

options.style

Type: String Default value: tab

The type of indentation to add or remove. The options are tab or space.

options.size

Type: Number Default value: 1

The number of options.style characters in an indent. For example, if you use 2 spaces per indent then you would set options.style to space, and this to 2.

options.change

Type: Number Default value: 0

The indentation level change. If this is a positive number it will indent all lines the specified number of times. If this is a negative number it will remove the specified number of indents. If this number is zero then it will merely copy the files without modifying the contents.

Usage Examples

Increase Indentation

In this example the indent task will increase the indent of all .js files in the src directory by one and save the modified files in the dist directory.

grunt.initConfig({
  indent: {
    scripts: {
      src: [
        'src/*.js'
      ],
      dest: 'dist/',
      options: {
        style: 'space',
        size: 2,
        change: 1
      }
    }
  }
});

Decrease Indentation

In this example the indent task will decrease the indent of all .css files in the css directory by one and save the modified files in the dist directory.

grunt.initConfig({
  indent: {
    stylesheets: {
      src: [
        'css/*.css'
      ],
      dest: 'dist/',
      options: {
        style: 'space',
        size: 2,
        change: -1
      }
    }
  }
});

Release History

  • 2017-04-22   v1.0.0   Increase min Node.js version to 0.10. Corrected "main" target.
  • 2016-02-28   v0.1.5   Updated grunt peer dependency to support Grunt v1.0.
  • 2013-11-08   v0.1.4   Added success message to grunt output.
  • 2013-03-23   v0.1.3   Files will now be saved with Grunt defined line endings.
  • 2013-03-21   v0.1.2   Fixed bug with empty lines when file uses Windows style line endings.
  • 2013-03-17   v0.1.1   Added support for single-file destinations.
  • 2013-03-16   v0.1.0   Initial release.

grunt-indent's People

Contributors

davidnpma avatar echernyavskiy avatar stevenbenner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

grunt-indent's Issues

Support named file destinations

Right now indent assumes that the dest option is a folder, and will not let users set the destination file name. This should be changed to check if dest is a folder, if it is not a folder then save the result in the exact path that the user specified.

Example:

{
    src: 'path/to/file.js',
    dest: 'path/to/newFile.js'
}

Detect indentation

Would be nice if the plugin could just detect the size and style of indentation automatically.

Task is modifying empty lines on Windows

Running the task on files with Windows style line endings will cause the indent task to change the indent on empty lines.

It looks like the underscore.string lines() function is splitting on \n only. Since Windows uses \r\n for its line endings the resulting array will contain \r for empty lines, causing the empty string test to return false. This probably means that the lines() function doesn't work at all for Mac OS9 style line endings which are only an \r character.

Desired behavior: Do not modify empty lines.

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.