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

Method indent

benchmark/data.js:973–996  ·  view source on GitHub ↗
(indentStr)

Source from the content-addressed store, hash-verified

971 );
972 }
973 indent(indentStr) {
974 if (!arguments.length) {
975 indentStr = this.getIndentString();
976 }
977 if (indentStr === '') return this;
978 let trailingNewline = !this.intro || this.intro.slice(-1) === '\n';
979 this.sources.forEach((source, i) => {
980 const separator = source.separator !== void 0 ? source.separator : this.separator;
981 const indentStart = trailingNewline || (i > 0 && /\r?\n$/.test(separator));
982 source.content.indent(indentStr, {
983 exclude: source.indentExclusionRanges,
984 indentStart,
985 });
986 trailingNewline = source.content.lastChar() === '\n';
987 });
988 if (this.intro) {
989 this.intro =
990 indentStr +
991 this.intro.replace(/^[^\n]/gm, (match, index) => {
992 return index > 0 ? indentStr + match : match;
993 });
994 }
995 return this;
996 }
997 prepend(str) {
998 this.intro = str + this.intro;
999 return this;

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected