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

Method indent

src/Bundle.js:191–221  ·  view source on GitHub ↗
(indentStr)

Source from the content-addressed store, hash-verified

189 }
190
191 indent(indentStr) {
192 if (!arguments.length) {
193 indentStr = this.getIndentString();
194 }
195
196 if (indentStr === '') return this; // noop
197
198 let trailingNewline = !this.intro || this.intro.slice(-1) === '\n';
199
200 this.sources.forEach((source, i) => {
201 const separator = source.separator !== undefined ? source.separator : this.separator;
202 const indentStart = trailingNewline || (i > 0 && /\r?\n$/.test(separator));
203
204 source.content.indent(indentStr, {
205 exclude: source.indentExclusionRanges,
206 indentStart, //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
207 });
208
209 trailingNewline = source.content.lastChar() === '\n';
210 });
211
212 if (this.intro) {
213 this.intro =
214 indentStr +
215 this.intro.replace(/^[^\n]/gm, (match, index) => {
216 return index > 0 ? indentStr + match : match;
217 });
218 }
219
220 return this;
221 }
222
223 prepend(str) {
224 this.intro = str + this.intro;

Callers 2

Bundle.test.jsFile · 0.45

Calls 4

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

Tested by

no test coverage detected