@darkobits/strip-indent
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

Normalizes whitespace in multi-line strings. Plays nice with ANSI escape sequences.

Install

npm i @darkobits/strip-indent

Use

import stripIndent from '@darkobits/strip-indent';

const str = `
  Lorem ipsum dolor amet hoodie kogi copper
  mug, whatever lomo shaman VHS try-hard
  kinfolk beard disrupt chartreuse etsy.
`;

stripIndent(str)

/*

`
Lorem ipsum dolor amet hoodie kogi copper
mug, whatever lomo shaman VHS try-hard
kinfolk beard disrupt chartreuse etsy.
`

*/

If you need to strip leading / trailing newlines or whitespace, call trim() on the string:

import stripIndent from '@darkobits/strip-indent';

const str = `
  Kogi cold-pressed sriracha bespoke,
  readymade kombucha pickled listicle tumblr
  tousled truffaut shoreditch pop-up brunch.
`;

stripIndent(str).trim();

/*

`Kogi cold-pressed sriracha bespoke,
readymade kombucha pickled listicle tumblr
tousled truffaut shoreditch pop-up brunch.`

*/

Package Sidebar

Install

npm i @darkobits/strip-indent

Weekly Downloads

12

Version

2.0.0

License

WTFPL

Unpacked Size

8.78 kB

Total Files

7

Last publish

Collaborators

  • darkobits