@darkobits/strip-indent
v2.0.0
Published
strip-indent
Downloads
18
Maintainers
Readme
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.`
*/