Socket
Socket
Sign inDemoInstall

expand-template

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    expand-template

Expand placeholders in a template string


Version published
Weekly downloads
5.9M
increased by4.58%
Maintainers
1
Install size
6.20 kB
Created
Weekly downloads
 

Package description

What is expand-template?

The expand-template npm package is designed for string templating. It allows users to interpolate variables within a string template, making it useful for generating dynamic strings based on variable inputs. This can be particularly useful in applications that require dynamic generation of content, configuration files, or code snippets based on user input or application state.

What are expand-template's main functionalities?

Variable Interpolation

This feature allows the user to interpolate variables within a string template. The example demonstrates how to use the expand-template package to replace the {{name}} placeholder with the string 'World'.

`const expand = require('expand-template')({open: '{{', close: '}}'});
let template = 'Hello, {{name}}!';
let result = expand({name: 'World'});
console.log(result); // Outputs: Hello, World!`

Custom Delimiters

This feature enables the use of custom delimiters for the template placeholders. In the provided code, the delimiters are set to '<<' and '>>', and the example shows how to replace the <<year>> placeholder with 2023.

`const expand = require('expand-template')({open: '<<', close: '>>'});
let template = 'Current year: <<year>>';
let result = expand({year: 2023});
console.log(result); // Outputs: Current year: 2023`

Other packages similar to expand-template

Readme

Source

expand-template

Expand placeholders in a template string.

npm Node version Build Status JavaScript Style Guide

Install

$ npm i expand-template -S

Usage

Default functionality expands templates using {} as separators for string placeholders.

var expand = require('expand-template')()
var template = '{foo}/{foo}/{bar}/{bar}'
console.log(expand(template, {
  foo: 'BAR',
  bar: 'FOO'
}))
// -> BAR/BAR/FOO/FOO

Custom separators:

var expand = require('expand-template')({ sep: '[]' })
var template = '[foo]/[foo]/[bar]/[bar]'
console.log(expand(template, {
  foo: 'BAR',
  bar: 'FOO'
}))
// -> BAR/BAR/FOO/FOO

License

All code, unless stated otherwise, is dual-licensed under WTFPL and MIT.

Keywords

FAQs

Last updated on 27 Nov 2018

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