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

Method prependLeft

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

839 * Same as `s.appendLeft(...)`, except that the inserted content will go *before* any previous appends or prepends at index
840 */
841 prependLeft(index: number, content: string): this {
842 index = this._resolveIndex(index)
843 if (index < 0 || index > this.original.length) {
844 throw new MagicStringError(`index ${index} is out of bounds`)
845 }
846
847 if (typeof content !== 'string') {
848 throw new MagicStringError(`content must be a string, got ${typeof content}`)
849 }
850
851 this._split(index)
852
853 const chunk = this.byEnd.get(index)
854
855 if (chunk) {
856 chunk.prependLeft(content)
857 }
858 else {
859 this.intro = content + this.intro
860 }
861
862 return this
863 }
864
865 /**
866 * 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 2

_resolveIndexMethod · 0.95
_splitMethod · 0.95

Tested by

no test coverage detected