trucks-transform-trim

Trim inline styles and scripts

Usage no npm install needed!

<script type="module">
  import trucksTransformTrim from 'https://cdn.skypack.dev/trucks-transform-trim';
</script>

README

Trim Transform

Removes whitespace from inline content

Designed to prettify inline content so that styles and scripts have leading whitespace removed:

<dom-module id="x-blog-post">
  <script>
    skate.define('{{id}}', {});
  </script>
</dom-module>

Yields script content without the leading indentation:

skate.define('{{id}}', {});

Using this transform is not typically necessary as you would ordinarily build to a minified file (possibly with source maps) however it is used internally to simplify test assertions.

Install

npm i trucks-transform-trim --save-dev

For the command line interface see trucks-cli.



Usage

Use the trim key to configure this transform:

const trucks = require('trucks');

trucks(
  {
    files: ['components.html'],
    transforms: ['trim'],
    conf: {
      transforms: {
        trim: {
          lines: false
        } 
      }
    }
  }, (err, res) => {
    if(err) {
      throw err; 
    }
    console.log(res);
  }
);

API

trim

public trim(state, conf)

Removes leading and trailing whitespace from inline styles and scripts.

When the lines option is given each line is stripped of leading whitespace that matches the pattern regular expression.

Returns map of visitor functions.

  • state Object compiler state.
  • conf Object transform plugin configuration.

Options

  • inline Boolean=true only replace inline elements.
  • lines Boolean=true strip each line.
  • pattern RegExp used for line whitespace.
  • templates Boolean=false also trim template elements.

License

MIT


Created by mkdoc on July 18, 2016