Socket
Socket
Sign inDemoInstall

lodash.template

Package Overview
Dependencies
2
Maintainers
2
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

lodash.template

The Lodash method `_.template` exported as a module.


Version published
Maintainers
2
Weekly downloads
4,433,234
increased by1.44%
Install size
68.3 kB

Weekly downloads

Package description

What is lodash.template?

The lodash.template package is a part of the Lodash library which provides utility functions for common programming tasks using the functional programming paradigm. It is specifically designed for creating compiled templates which can be used to interpolate values into strings.

What are lodash.template's main functionalities?

Template Compilation

Compiles templates into functions that can be used to interpolate values. The 'template' function takes a string and returns a compiled template function.

const _ = require('lodash.template');
const compiled = _.template('hello <%= user %>!');
console.log(compiled({ 'user': 'fred' }));
// => 'hello fred!'

HTML Escaping

Supports HTML escaping. The '<%-' sequence in the template string is used to escape values that are interpolated, preventing XSS attacks.

const _ = require('lodash.template');
const compiled = _.template('<b><%- value %></b>');
console.log(compiled({ 'value': '<script>' }));
// => '<b>&lt;script&gt;</b>'

Use of JavaScript Expressions

Allows the use of JavaScript expressions inside templates. This enables iteration and conditional logic within the template string.

const _ = require('lodash.template');
const compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
console.log(compiled({ 'users': ['fred', 'barney'] }));
// => '<li>fred</li><li>barney</li>'

Custom Delimiters

Supports custom delimiters. Users can define their own delimiters for interpolation, evaluation, and escaping.

const _ = require('lodash.template');
const compiled = _.template('hello ${ user }!', { 'interpolate': /\${([\s\S]+?)}/g });
console.log(compiled({ 'user': 'pebbles' }));
// => 'hello pebbles!'

Other packages similar to lodash.template

Readme

Source

lodash.template v4.5.0

The Lodash method _.template exported as a Node.js module.

Installation

Using npm:

$ {sudo -H} npm i -g npm
$ npm i --save lodash.template

In Node.js:

var template = require('lodash.template');

See the documentation or package source for more details.

Keywords

FAQs

Last updated on 10 Jul 2019

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc