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

Method appendLeft

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

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