Function: applyChangesToString

applyChangesToString(text, changes): string

Applies a list of changes to a string's original value.

This is useful when working with ASTs.

For Example, to rename a property in a method's options:

const code = `bootstrap({ target: document.querySelector('#app') })`; const indexOfPropertyName = 13; // Usually determined by analyzing an AST. const updatedCode = applyChangesToString(code, [ { type: ChangeType.Insert, index: indexOfPropertyName, text: 'element', }, { type: ChangeType.Delete, start: indexOfPropertyName, length: 6, }, ]); bootstrap({ element: document.querySelector('#app'), });

Parameters

NameType
textstring
changesStringChange[]

Returns

string