Creates a template function that can be used with string literals or tagged template literals
The template string or template strings array
Rest ...keys: (PropPath<T> | ((data) => any))[]The template keys (paths or functions)
A function that takes data and returns a Promise with the processed template
// String literal usage
const tpl = template('Hello, {{name}}!');
const result = await tpl({ name: 'Flavio Ever' });
// Result: "Hello, Flavio Ever!"
// Tagged template literal usage
const tpl = template`Hello, ${'name'}!`;
const result = await tpl({ name: 'Flavio Ever' });
// Result: "Hello, Flavio Ever!"
Registers transformers for use in templates
The transformers configuration object
Optional default?: TransformFnOptional fallback?: stringtemplate.use({
transformers: {
uppercase: (v) => v.toUpperCase(),
lowercase: (v) => v.toLowerCase(),
formatCurrency: (v, currency, locale) => new Intl.NumberFormat(locale, { style: 'currency', currency }).format(v)
},
default: (value) => value, // transformador padrão
fallback: "N/A" // valor padrão para propriedades ausentes
});
A powerful template engine that supports multiple syntax styles and transformers
Example