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

Method prependLeft

src/MagicString.ts:664–687  ·  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

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