Last active
June 12, 2019 12:04
-
-
Save devCola/d024ba3fa7f788847ef5ffa4482f7445 to your computer and use it in GitHub Desktop.
typescript stripMargins
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
// 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