MCPcopy
hub / github.com/vuejs/core / dedent

Function dedent

packages/compiler-sfc/src/parse.ts:465–485  ·  view source on GitHub ↗

* Dedent a string. * * This removes any whitespace that is common to all lines in the string from * each line in the string.

(s: string)

Source from the content-addressed store, hash-verified

463 * each line in the string.
464 */
465function dedent(s: string): [string, number] {
466 const lines = s.split('\n')
467 const minIndent = lines.reduce(function (minIndent, line) {
468 if (line.trim() === '') {
469 return minIndent
470 }
471 const indent = line.match(/^\s*/)?.[0]?.length || 0
472 return Math.min(indent, minIndent)
473 }, Infinity)
474 if (minIndent === 0) {
475 return [s, minIndent]
476 }
477 return [
478 lines
479 .map(function (line) {
480 return line.slice(minIndent)
481 })
482 .join('\n'),
483 minIndent,
484 ]
485}

Callers 1

parseFunction · 0.85

Calls 1

mapMethod · 0.80

Tested by

no test coverage detected