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

Method prependLeft

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

809 * Same as `s.appendLeft(...)`, except that the inserted content will go *before* any previous appends or prepends at index
810 */
811 prependLeft(index: number, content: string): this {
812 index = index + this.offset
813
814 if (typeof content !== 'string') {
815 throw new MagicStringError(`content must be a string, got ${typeof content}`)
816 }
817
818 if (DEBUG)
819 this.stats.time('insertRight')
820
821 this._split(index)
822
823 const chunk = this.byEnd.get(index)
824
825 if (chunk) {
826 chunk.prependLeft(content)
827 }
828 else {
829 this.intro = content + this.intro
830 }
831
832 if (DEBUG)
833 this.stats.timeEnd('insertRight')
834 return this
835 }
836
837 /**
838 * 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