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

Method indent

src/Bundle.ts:250–281  ·  view source on GitHub ↗
(indentStr?: string)

Source from the content-addressed store, hash-verified

248 }
249
250 indent(indentStr?: string): this {
251 if (!arguments.length) {
252 indentStr = this.getIndentString()
253 }
254
255 if (indentStr === '')
256 return this // noop
257
258 let trailingNewline = !this.intro || this.intro.slice(-1) === '\n'
259
260 this.sources.forEach((source, i) => {
261 const separator = source.separator !== undefined ? source.separator : this.separator
262 const indentStart = trailingNewline || (i > 0 && /\r?\n$/.test(separator))
263
264 source.content.indent(indentStr, {
265 exclude: source.indentExclusionRanges,
266 indentStart, // : trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
267 })
268
269 trailingNewline = source.content.lastChar() === '\n'
270 })
271
272 if (this.intro) {
273 this.intro
274 = indentStr
275 + this.intro.replace(/^[^\n]/gm, (match, index) => {
276 return index > 0 ? indentStr + match : match
277 })
278 }
279
280 return this
281 }
282
283 prepend(str: string): this {
284 this.intro = str + this.intro

Callers 2

Bundle.test.tsFile · 0.45

Calls 4

getIndentStringMethod · 0.95
sliceMethod · 0.45
lastCharMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected