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

Method prependLeft

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

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