Created
May 29, 2017 22:38
-
-
Save cesarfigueroa/5e8566b0aaff4436da717fbeced48122 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const WHITESPACE_PATTERN = /^[ \t]*(?=\S)/gm; | |
export function stripIndent(strings, ...expressions) { | |
const resultString = strings.reduce((accumulator, part, i) => { | |
return accumulator + expressions[i - 1] + part; | |
}); | |
const indents = Math.min( | |
...resultString.match(WHITESPACE_PATTERN).map(whitespace => whitespace.length) | |
); | |
return resultString.split('\n').map(line => line.slice(indents)).join('\n'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment