Skip to main content

template

$template

Operator that interpolates a template string using properties from the input object. Placeholders use {key} syntax; double braces {{ and }} are literal brace escapes.

The input must be a plain object. Unknown keys resolve to an empty string.

Parameters

  • template (string, required): The template string to interpolate.

Example

// Build a connection string from object properties
new Schema('object', {
host: new Schema('string'),
port: new Schema('number'),
database: new Schema('string'),
}).transformer({$template: 'postgresql://{host}:{port}/{database}'})

// Format a greeting from a user object
new Schema('object').transformer({$template: 'Hello, {firstName} {lastName}!'})

// Use double-braces to produce literal curly braces
new Schema('object').transformer({$template: 'Value: {{literal}}'})
// {} → 'Value: {literal}'