mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-13 19:09:03 -05:00
35 lines
763 B
TypeScript
35 lines
763 B
TypeScript
export const stripIndent = (strings: TemplateStringsArray, ...args: any[]): string => {
|
|
const parts: any[] = []
|
|
|
|
for (let i = 0; i < strings.length; i++) {
|
|
parts.push(strings[i])
|
|
|
|
if (i < strings.length - 1) {
|
|
parts.push(`<<${i}>>`)
|
|
}
|
|
}
|
|
|
|
const lines = parts.join('').split('\n')
|
|
const firstLine = (lines[0]?.length === 0 ? lines[1] : lines[0]) ?? ''
|
|
let indentSize = 0
|
|
|
|
for (let i = 0; i < firstLine.length; i++) {
|
|
if (firstLine[i] === ' ') {
|
|
indentSize++
|
|
continue
|
|
}
|
|
|
|
break
|
|
}
|
|
|
|
const strippedLines = lines.map((line) => line.substring(indentSize))
|
|
|
|
let result = strippedLines.join('\n').trimLeft()
|
|
|
|
args.forEach((arg, i) => {
|
|
result = result.replace(`<<${i}>>`, `${arg}`)
|
|
})
|
|
|
|
return result
|
|
}
|