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

Method overwrite

src/MagicString.ts:725–745  ·  view source on GitHub ↗

* Replaces the characters from `start` to `end` with `content`, along with the appended/prepended content in * that range. The same restrictions as `s.remove()` apply. * * The fourth argument is optional. It can have a storeName property - if true, the original name will be stored * for

(
    start: number,
    end: number,
    content: string,
    options?: boolean | OverwriteOptions,
  )

Source from the content-addressed store, hash-verified

723 * It may be preferred to use `s.update(...)` instead if you wish to avoid overwriting the appended/prepended content.
724 */
725 overwrite(
726 start: number,
727 end: number,
728 content: string,
729 options?: boolean | OverwriteOptions,
730 ): this {
731 if (options === true) {
732 if (!warned.storeName) {
733 console.warn(
734 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
735 )
736 warned.storeName = true
737 }
738 return this.update(start, end, content, { storeName: true, overwrite: true })
739 }
740 const optionObject = typeof options === 'object' && options ? options : {}
741 return this.update(start, end, content, {
742 ...optionObject,
743 overwrite: !optionObject.contentOnly,
744 })
745 }
746
747 /**
748 * Replaces the characters from `start` to `end` with `content`. The same restrictions as `s.remove()` apply.

Callers 3

replaceMatchMethod · 0.95
_replaceStringMethod · 0.95
_replaceAllStringMethod · 0.95

Calls 1

updateMethod · 0.95

Tested by

no test coverage detected