Zero-dependency back-tick templates using property names instead of expressions. Part of the Metarhia stack.
npm install tickplatePlace tag t before a template literal. Placeholders use property names (strings)
as keys; pass a data object to the returned function to render.
const t = require('tickplate');
const data = {
hello: 'Ave!',
myFriend: {
name: 'Marcus Aurelius',
toString() {
return this.name;
},
},
positions: ['emperor', 'philosopher', 'writer'],
};
const templ = t`${'hello'} ${'myFriend'}, great ${'positions'} of Rome`;
console.log(templ(data));
// Ave! Marcus Aurelius, great emperor, philosopher, writer of Romeimport t from 'tickplate';
const templ = t`Hello ${'name'}!`;
console.log(templ({ name: 'World' }));
// Hello World!Tagged template literal. Returns a function (values, opts?) => string.
- Placeholders:
${'key'}— property name from the data object. - Default values:
${'key=value'}— JSON-parsable default when the key is missing. Example:${'greeting="Hello"'}or${'count=0'}. - Arrays: Values are joined with
,by default. Useopts.delimiterto customize (e.g.{ delimiter: ', ' }).
Renders the template.
- values: Data object. Keys not present render as empty string.
nullandundefinedare treated as{}. - opts.delimiter: String (or coercible value) used to join array elements.
Default:
','.
console.log(templ(data, { delimiter: ', ' }));
// Ave! Marcus Aurelius, great emperor, philosopher, writer of Romeconst templ = t`${'greeting='} ${'person="Marcus Aurelius"'}, great ${'positions=["emperor", "philosopher"]'} of Rome from ${'ruleFrom=161'} to ${'ruleTo=180'} AD`;
const data = {
greeting: 'Valē!',
person: {
name: 'Lucius Verus',
toString() {
return this.name;
},
},
positions: ['brother', 'emperor', 'co-emperor'],
ruleFrom: 161,
ruleTo: 169,
};
console.log(templ(data));
// Valē! Lucius Verus, great brother,emperor,co-emperor of Rome from 161 to 180 ADCopyright (c) 2017-2026 Metarhia contributors. Tickplate is MIT licensed. Tickplate is a part of Metarhia technology stack.