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

Method appendLeft

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

221 * See also `s.prependLeft(...)`.
222 */
223 appendLeft(index: number, content: string): this {
224 index = index + this.offset
225
226 if (typeof content !== 'string') {
227 throw new MagicStringError(`content must be a string, got ${typeof content}`)
228 }
229
230 if (DEBUG)
231 this.stats.time('appendLeft')
232
233 this._split(index)
234
235 const chunk = this.byEnd.get(index)
236
237 if (chunk) {
238 chunk.appendLeft(content)
239 }
240 else {
241 this.intro += content
242 }
243
244 if (DEBUG)
245 this.stats.timeEnd('appendLeft')
246 return this
247 }
248
249 /**
250 * 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