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

Method appendLeft

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

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