MCPcopy
hub / github.com/vitest-dev/vitest / stripIndent

Function stripIndent

test/test-utils/index.ts:402–413  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

400>
401
402export function stripIndent(str: string): string {
403 const normalized = str.replace(/\t/g, ' ')
404 const match = normalized.match(/^[ \t]*(?=\S)/gm)
405 if (!match) {
406 return normalized
407 }
408 const indent = match.filter(m => !!m).reduce((min, line) => Math.min(min, line.length), Infinity)
409 if (indent === 0) {
410 return normalized
411 }
412 return normalized.replace(new RegExp(`^[ ]{${indent}}`, 'gm'), '')
413}
414
415function getGeneratedFileContent(content: TestFsStructure[string]) {
416 if (typeof content === 'string') {

Callers 2

runFixtureTestsFunction · 0.90
getGeneratedFileContentFunction · 0.70

Calls 2

filterMethod · 0.65
matchMethod · 0.45

Tested by 1

runFixtureTestsFunction · 0.72