Socket
Socket
Sign inDemoInstall

string-template

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-template

A simple string template function based on named or indexed arguments


Version published
Weekly downloads
1.9M
decreased by-3.4%
Maintainers
1
Weekly downloads
 
Created

What is string-template?

The string-template npm package allows you to easily create and manipulate string templates. It provides a simple way to replace placeholders in a string with actual values, making it useful for generating dynamic content.

What are string-template's main functionalities?

Basic Template Replacement

This feature allows you to replace placeholders in a string with corresponding values from an object. In this example, the placeholder {name} is replaced with 'World'.

const template = require('string-template');
const result = template('Hello, {name}!', { name: 'World' });
console.log(result); // Output: Hello, World!

Multiple Placeholders

You can use multiple placeholders in a single string and replace them with values from an object. This example replaces {firstName} and {lastName} with 'John' and 'Doe' respectively.

const template = require('string-template');
const result = template('Hello, {firstName} {lastName}!', { firstName: 'John', lastName: 'Doe' });
console.log(result); // Output: Hello, John Doe!

Nested Object Replacement

The package supports nested object replacement, allowing you to access properties within nested objects. In this example, {user.name} is replaced with 'Alice'.

const template = require('string-template');
const result = template('Hello, {user.name}!', { user: { name: 'Alice' } });
console.log(result); // Output: Hello, Alice!

Other packages similar to string-template

Keywords

FAQs

Package last updated on 06 May 2015

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