nx/docs/generated/devkit/applyChangesToString.md

45 lines
1.0 KiB
Markdown

# 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:
```typescript
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
| Name | Type |
| :-------- | :------------------------------------------------------ |
| `text` | `string` |
| `changes` | [`StringChange`](../../devkit/documents/StringChange)[] |
#### Returns
`string`