New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@jf/tpl

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jf/tpl

Replace placeholders in a string with values in object. Placeholders delimiters are customizables.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

jfTpl stable

A very simple system to replace placeholders in a string with values in object.

Sometime we need replace placeholders in translated strings but other alternatives (mustache, handlebars, underscore, etc) are too big for our requirements.

Placeholders delimiters are customizables (default: {}).

Usage

npm install jfTpl

Options

  • context Context with variables to replace in template.
  • defaults Default values for context.
  • delKeys If true, all keys found in template will be removed from context/defaults, depending of which object provide the key (default: false).
  • keep Preserve plaholders not replaced (default: false).
  • left Left delimiter (default: {).
  • right Right delimiter (default: }).
  • tpl Template to render.

Examples

// Displaying `Hello Guest, welcome to home` using 
// differents configurations.
const jfTpl = require('jf-tpl');
// Simple
console.log(
    jfTpl(
        {
            tpl     : 'Hello {name}, welcome to {site}',
            context : {
                name : 'Guest',
                site : 'home'
            }
        }
    )
);
// All options used.
console.log(
    jfTpl(
        {
            tpl      : 'Hello <[name]>, welcome to <[site]>',
            defaults : {
                site : 'home'
            },
            left     : '<[',
            right    : ']>',
            context  : {
                name : 'Guest'
            }
        }
    )
);
// Param keep
console.log(
    jfTpl(
        {
            tpl     : 'Hello {name}, welcome to {site}',
            context : {
                name : 'Guest'
            }
        }
    )
); // Hello Guest, welcome to
console.log(
    jfTpl(
        {
            tpl     : 'Hello {name}, welcome to {site}',
            keep    : true,
            context : {
                name : 'Guest'
            }
        }
    )
); // Hello Guest, welcome to {site}

Keywords

handlebars

FAQs

Package last updated on 07 Apr 2019

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