New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

interpolate-tmpl

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

interpolate-tmpl

String interpolation made easy.

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

interpolate-tmpl

Simple string interpolation.

Simple interpolation utility based on the JavaScript RegExp, String#replace and the npm module get-safe for safe access to nested properties.


Install:

npm install interpolate-tmpl --save

How to use

let interpolate = require('interpolate-tmpl');

let str = `
<div>
<h1 class="{{ color}}">{{ title('Albert',Einstein  ) }}</h1>
<p>Born on {{birthDate(March, 14, '1879')}}</p>
<p>Died in {{'death.location' }}, {{ death.date }}</p>
</div>`;

let data = {
 color:"red",
 death: {
   location: "Princeton",
   date: "April 18, 1955"
 },
 title(firstname, lastname) {
 return `Mr. ${firstname} ${lastname}`;
 },
 birthDate(month, day, year) {
   return `${month} ${day}, ${year}`;
 }
};

console.log(interpolate(str, data, "{{}}") ); // Logs interpolated string

You can call functions with simple arguments (strings & integers only, no variable) and change the delimiter. Just pass the delimiter as a string to the interpolate function as the last parameter (default is {{}}).

Supported delimiters are: {{}}, {}, [[]], [], <$$>, <##>, <%%>.


The browser version adds a interpolate function to the window object.

Keywords

FAQs

Package last updated on 20 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc