Skip to content

Instantly share code, notes, and snippets.

@devCola
Last active June 12, 2019 12:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devCola/d024ba3fa7f788847ef5ffa4482f7445 to your computer and use it in GitHub Desktop.
Save devCola/d024ba3fa7f788847ef5ffa4482f7445 to your computer and use it in GitHub Desktop.
typescript stripMargins
// NOT MINE - FROM SOMEONE @ INTERNET
// same as scala's stripMargin
export function stripMargin(template: TemplateStringsArray, ...expressions: any[]) {
let result = template.reduce((accumulator, part, i) => {
return accumulator + expressions[i - 1] + part
})
return result.replace(/\r?(\n)\s*\|/g, '$1');
}
// usage:
(function someFunc() {
(function someFunc1 () {
(function someFunc2() {
stripMargin`
|hello world 1+1 is ${1+1}
`
})()
})()
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment