(strings: TemplateStringsArray, ...values: any[])
| 8 | |
| 9 | /** Template string function that can be used to strip indentation from a given string literal. */ |
| 10 | export function dedent(strings: TemplateStringsArray, ...values: any[]) { |
| 11 | let joinedString = ''; |
| 12 | for (let i = 0; i < values.length; i++) { |
| 13 | joinedString += `${strings[i]}${values[i]}`; |
| 14 | } |
| 15 | joinedString += strings[strings.length - 1]; |
| 16 | const lines = joinedString.split('\n'); |
| 17 | while (isBlank(lines[0])) { |
| 18 | lines.shift(); |
| 19 | } |
| 20 | while (isBlank(lines[lines.length - 1])) { |
| 21 | lines.pop(); |
| 22 | } |
| 23 | let minWhitespacePrefix = lines.reduce( |
| 24 | (min, line) => Math.min(min, numOfWhiteSpaceLeadingChars(line)), |
| 25 | Number.MAX_SAFE_INTEGER, |
| 26 | ); |
| 27 | return lines.map((line) => line.substring(minWhitespacePrefix)).join('\n'); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Tests to see if the line is blank. |
nothing calls this directly
no test coverage detected
searching dependent graphs…