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

Method appendRight

src/MagicString.ts:249–271  ·  view source on GitHub ↗

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

(index: number, content: string)

Source from the content-addressed store, hash-verified

247 * See also `s.prependRight(...)`.
248 */
249 appendRight(index: number, content: string): this {
250 index = this._resolveIndex(index)
251 if (index < 0 || index > this.original.length) {
252 throw new MagicStringError(`index ${index} is out of bounds`)
253 }
254
255 if (typeof content !== 'string') {
256 throw new MagicStringError(`content must be a string, got ${typeof content}`)
257 }
258
259 this._split(index)
260
261 const chunk = this.byStart.get(index)
262
263 if (chunk) {
264 chunk.appendRight(content)
265 }
266 else {
267 this.outro += content
268 }
269
270 return this
271 }
272
273 /**
274 * Returns an independent copy: the chunk list, string-level intro/outro,

Callers 4

replaceMatchMethod · 0.95
_replaceStringMethod · 0.95
_replaceAllStringMethod · 0.95
indentAtMethod · 0.45

Calls 2

_resolveIndexMethod · 0.95
_splitMethod · 0.95

Tested by

no test coverage detected