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

Method appendLeft

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

128 * See also `s.prependLeft(...)`.
129 */
130 appendLeft(index: number, content: string): this {
131 index = index + this.offset
132
133 if (typeof content !== 'string')
134 throw new TypeError('inserted content must be a string')
135
136 if (DEBUG)
137 this.stats.time('appendLeft')
138
139 this._split(index)
140
141 const chunk = this.byEnd.get(index)
142
143 if (chunk) {
144 chunk.appendLeft(content)
145 }
146 else {
147 this.intro += content
148 }
149
150 if (DEBUG)
151 this.stats.timeEnd('appendLeft')
152 return this
153 }
154
155 /**
156 * 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