import { Meta } from '@storybook/addon-docs/blocks'

<Meta title='@dxtmisha/en/functional-basic/Functions/replaceTemplate - Substituting values into a template string'/>

# `replaceTemplate`

Searches the original string for markers in the form `[pattern]` and replaces them with corresponding values from the provided object. If the marker's value is a function, it is automatically called, and its result is substituted into the string.

**Parameters:**
- `value: string` — The template string containing markers (e.g., `[name]`).
- `replaces: Record<string, string | FunctionReturn<string>>` — An object containing replacement data, where the key is the marker name inside brackets, and the value is a string or a function returning a string.

**Returns:**
`string` — A new string with the substituted values.

```typescript
import { replaceTemplate } from '@dxtmisha/functional-basic'

const template = 'Hello, [name]! Your balance: [balance].'
const data = {
  name: 'John',
  balance: () => '$100' // The function is evaluated during substitution
}

console.log(replaceTemplate(template, data)) 
// 'Hello, John! Your balance: $100.'
```
