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

Method appendLeft

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

218 * See also `s.prependLeft(...)`.
219 */
220 appendLeft(index: number, content: string): this {
221 index = this._resolveIndex(index)
222 if (index < 0 || index > this.original.length) {
223 throw new MagicStringError(`index ${index} is out of bounds`)
224 }
225
226 if (typeof content !== 'string') {
227 throw new MagicStringError(`content must be a string, got ${typeof content}`)
228 }
229
230 this._split(index)
231
232 const chunk = this.byEnd.get(index)
233
234 if (chunk) {
235 chunk.appendLeft(content)
236 }
237 else {
238 this.intro += content
239 }
240
241 return this
242 }
243
244 /**
245 * Appends the specified content at the index in the original string.

Callers 1

insertLeftMethod · 0.95

Calls 2

_resolveIndexMethod · 0.95
_splitMethod · 0.95

Tested by

no test coverage detected