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

Method prependRight

src/MagicString.ts:868–890  ·  view source on GitHub ↗

* Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`

(index: number, content: string)

Source from the content-addressed store, hash-verified

866 * Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`
867 */
868 prependRight(index: number, content: string): this {
869 index = this._resolveIndex(index)
870 if (index < 0 || index > this.original.length) {
871 throw new MagicStringError(`index ${index} is out of bounds`)
872 }
873
874 if (typeof content !== 'string') {
875 throw new MagicStringError(`content must be a string, got ${typeof content}`)
876 }
877
878 this._split(index)
879
880 const chunk = this.byStart.get(index)
881
882 if (chunk) {
883 chunk.prependRight(content)
884 }
885 else {
886 this.outro = content + this.outro
887 }
888
889 return this
890 }
891
892 /**
893 * Removes the characters from `start` to `end` (of the original string, **not** the generated string).

Callers 2

insertRightMethod · 0.95
indentAtMethod · 0.45

Calls 2

_resolveIndexMethod · 0.95
_splitMethod · 0.95

Tested by

no test coverage detected