shift-left

Moves formatted multiline strings to the left without ruining your code's indentation.

Usage no npm install needed!

<script type="module">
  import shiftLeft from 'https://cdn.skypack.dev/shift-left';
</script>

README

shift-left

Moves formatted multiline strings to the left without ruining your code's indentation.

Why does this exist?

Have you ever wanted to log a multi-line string? If so, you've probably seen code like this:

function printStuff() {
  console.log(`
This string is all the way to the left in my code file.

  and sometimes {
    it has {
      indentation
    }
  }

I'm doing this because I want it to start all the way to the left when it appears in the console.

But I sure wish it didn't mess with my code's indentation.
  `);
}

If you wish you could preserve your code's indentation without moving your ouput to the right, this library has an answer for you.

Usage

Example code:

import { shiftLeft } from "shift-left";

const recipient = "Bob Loblaw";

const message = shiftLeft`
  I have a lovely little {
    multiline message

    for you

        and you

            and also ${recipient}
  }
`;

console.log(message);

The code above produces the following output:

I have a lovely little {
  multiline message

  for you

      and you

          and also Bob Loblaw
}