str_template
Tiny string templating library for JavaScript and TypeScript. Fill placeholders like {name} in a string from an object, in Node or the browser
- Platform
- Libraries
- Category
- Developer Tools
- Available from
- npm
About this app
str_template is a tiny string templating library for JavaScript and TypeScript. When a message or text comes from a file, a database or a translation, you can't use a template literal, and joining strings by hand gets ugly. Write {placeholders} in the string and fill them from an object with one call.
I made it because I needed a small string templating tool. The others out there pretty much all do the same thing, so I thought: okay, let's make my own as well.
- One function:
StrTemplate.format(text, values). - Your own separator: use
{}by default, or something like[[ ]]if braces are already in your text. - Works the same in Node.js and the browser.
- Written in TypeScript, small and fast.
Great for message templates, emails and any text with values filled in later.
Install
npm install str-template-ts
StrTemplate.format('Hello {name}!', { name: 'Fayaz' }) // Hello Fayaz!
Want help tidying up how your app handles text and messages? Contact me through my portfolio: https://p32929.github.io