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

Method prependLeft

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

701 * Same as `s.appendLeft(...)`, except that the inserted content will go *before* any previous appends or prepends at index
702 */
703 prependLeft(index: number, content: string): this {
704 index = index + this.offset
705
706 if (typeof content !== 'string') {
707 throw new MagicStringError(`content must be a string, got ${typeof content}`)
708 }
709
710 if (DEBUG)
711 this.stats.time('insertRight')
712
713 this._split(index)
714
715 const chunk = this.byEnd.get(index)
716
717 if (chunk) {
718 chunk.prependLeft(content)
719 }
720 else {
721 this.intro = content + this.intro
722 }
723
724 if (DEBUG)
725 this.stats.timeEnd('insertRight')
726 return this
727 }
728
729 /**
730 * 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