core3-utils

@wixc3/common on Github

Home > @wixc3/common > templateCompilerProvider

templateCompilerProvider() function

Similar to templated string, given a fixed context object returns a function that parses strings in it

Signature:

export declare function templateCompilerProvider(context: Record<string, any>): (template: string) => string;

Parameters

Parameter Type Description
context Record<string, any> A context for the compiler

Returns:

(template: string) => string

A template compiler function which accepts a template and compile it with context

Example

const compile = templateCompilerProvider({ greetings: 'Hello', person: { name: 'Elad' } })
compile('${greetings} ${person.name}!')// => Hello Elad!
compile('${person.name} is awesome')// => Elad is awesome