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

Method appendLeft

src/MagicString.ts:132–156  ·  view source on GitHub ↗

* Appends the specified content at the index in the original string. * If a range *ending* with index is subsequently moved, the insert will be moved with it. * See also `s.prependLeft(...)`.

(index: number, content: string)

Source from the content-addressed store, hash-verified

130 * See also `s.prependLeft(...)`.
131 */
132 appendLeft(index: number, content: string): this {
133 index = index + this.offset
134
135 if (typeof content !== 'string') {
136 throw new MagicStringError(`content must be a string, got ${typeof content}`)
137 }
138
139 if (DEBUG)
140 this.stats.time('appendLeft')
141
142 this._split(index)
143
144 const chunk = this.byEnd.get(index)
145
146 if (chunk) {
147 chunk.appendLeft(content)
148 }
149 else {
150 this.intro += content
151 }
152
153 if (DEBUG)
154 this.stats.timeEnd('appendLeft')
155 return this
156 }
157
158 /**
159 * Appends the specified content at the index in the original string.

Callers 1

insertLeftMethod · 0.95

Calls 3

_splitMethod · 0.95
timeMethod · 0.80
timeEndMethod · 0.80

Tested by

no test coverage detected