Template strings, without the superfluous whitespace.


101.0.14 years ago4 years agoMinified + gzip package size for @chooie/preformatted in KB



Template strings, without the superfluous whitespace.

The indenation is readjusted to be level with whatever the first line's indentation is. Leading and trailing whitespace is also removed (blanks and newlines).


const preformatted = require("./preformatted.js");

describe("SHARED: Preformatted", function() {
  it("demonstration", function() {
    const animal = "cat";
    const sound = "meow";
    const normalTemplateString = `
      The ${animal} goes

    console.log("Normal template string:");

    const preformattedTemplateString = preformatted`
      The ${animal} goes

    console.log("Preformatted template string:");


Normal template string:

      The cat goes


Preformatted template string:
The cat goes


Install the library


npm install --save-exact @chooie/preformatted


  • Copy generated/dist/client/bundle.js to your project and include it in a script tag on the desired page
  • If using Browserify, you can include the source at src/application/shared/preformatted.js


View the available tasks to run

Run on your local machine


Run within Docker



  • Install docker (I'm running 18.03.0-ce-mac60)

  • Start the Karma server

    ./docker-tasks.sh karma
  • Capture the browsers you want to test by visiting http://localhost:9876

  • Run all the checks

    ./docker-tasks.sh test:all
  • Start the application

    ./docker-tasks.sh run


Frontend testing requirements

In order to perform cross-browser testing professionally, we must test our application in real browsers. The testing infrastructure checks that the expected browsers are tested. You will need to install the necessary browsers and run the necessary emulators(or test loosely - see the error message).

I recommend that you test all browsers/platforms that you intend to serve as part of the automated testing.

With this in place, make sure to start the karma server and capture each of the browsers you would like to test by visiting http://localhost:9876 (may differ if you are in an emulator - read the docs for that environment).


When limiting the mocha tests that you want to run with .skip() or .only(), make sure to use the test:quick task first to get a passing suite (WITH NO LIMITS SPECIFIED YET). Then limit your tests and run test:quick again.

There is something weird going on with our jake test tasks, mocha, and/or karma that is stopping this from working properly (like with test:all).


Much of the inspiration and implementation is borrowed from James Shore (https://github.com/jamesshore). I highly recommend his webseries Let's Code Test Driven Javascript (http://www.letscodejavascript.com/).

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.