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

Method prependLeft

src/MagicString.ts:663–686  ·  view source on GitHub ↗

* Same as `s.appendLeft(...)`, except that the inserted content will go *before* any previous appends or prepends at index

(index: number, content: string)

Source from the content-addressed store, hash-verified

661 * Same as `s.appendLeft(...)`, except that the inserted content will go *before* any previous appends or prepends at index
662 */
663 prependLeft(index: number, content: string): this {
664 index = index + this.offset
665
666 if (typeof content !== 'string')
667 throw new TypeError('inserted content must be a string')
668
669 if (DEBUG)
670 this.stats.time('insertRight')
671
672 this._split(index)
673
674 const chunk = this.byEnd[index]
675
676 if (chunk) {
677 chunk.prependLeft(content)
678 }
679 else {
680 this.intro = content + this.intro
681 }
682
683 if (DEBUG)
684 this.stats.timeEnd('insertRight')
685 return this
686 }
687
688 /**
689 * Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`

Callers

nothing calls this directly

Calls 3

_splitMethod · 0.95
timeMethod · 0.80
timeEndMethod · 0.80

Tested by

no test coverage detected