MCPcopy Create free account
hub / github.com/Rich-Harris/magic-string / getIndentString

Method getIndentString

src/Bundle.ts:366–379  ·  view source on GitHub ↗

* Returns the most common indent string among the sources, falling back to a tab.

()

Source from the content-addressed store, hash-verified

364 * Returns the most common indent string among the sources, falling back to a tab.
365 */
366 getIndentString(): string {
367 const indentStringCounts = new Map<string, number>()
368
369 this.sources.forEach((source) => {
370 const indentStr = source.content._getRawIndentString()
371
372 if (indentStr == null)
373 return
374
375 indentStringCounts.set(indentStr, (indentStringCounts.get(indentStr) ?? 0) + 1)
376 })
377
378 return [...indentStringCounts.entries()].sort(([, a], [, b]) => b - a)[0]?.[0] ?? '\t'
379 }
380
381 /**
382 * Prefixes each line of every source and of the intro with `indentStr`, guessed with `getIndentString()`

Callers 3

indentMethod · 0.95
indent.test.tsFile · 0.45
indent.test.tsFile · 0.45

Calls 2

forEachMethod · 0.80
_getRawIndentStringMethod · 0.80

Tested by

no test coverage detected