Skip to content

template

Template a string with values from a data object using a search expression

155 bytes

Usage

Given a string, an object of data, and a format expression to search for, returns a string with all elements that matched the search replaced with their matching value from the data object.

import * as
import _
_
from 'radashi'
import _
_
.
function template(str: string, data: Record<string, any>, regex?: RegExp): string
export template

Replace data by name in template strings. The default expression looks for {{name}} to identify names.

@seehttps://radashi.js.org/reference/string/template

@example

template('Hello, {{name}}', { name: 'Radashi' })
// "Hello, Radashi"
template('Hello, <name>', { name: 'Radashi' }, /<(.+?)>/g)
// "Hello, Radashi"

@version12.1.0

template
('It is {{color}}', {
color: string
color
: 'blue' }) // => It is blue
import _
_
.
function template(str: string, data: Record<string, any>, regex?: RegExp): string
export template

Replace data by name in template strings. The default expression looks for {{name}} to identify names.

@seehttps://radashi.js.org/reference/string/template

@example

template('Hello, {{name}}', { name: 'Radashi' })
// "Hello, Radashi"
template('Hello, <name>', { name: 'Radashi' }, /<(.+?)>/g)
// "Hello, Radashi"

@version12.1.0

template
('It is <color>', {
color: string
color
: 'blue' }, /<(.+?)>/g) // => It is blue