Socket
Book a DemoInstallSign in
Socket

string-interp

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-interp

Shell-style string interpolation

0.3.6
latest
Source
npmnpm
Version published
Weekly downloads
251
7.26%
Maintainers
1
Weekly downloads
 
Created
Source

string-interp

Build Status Coverage Status Dependency Status Language grade: JavaScript

A small library to do shell-style string interpolation, with extensions to make it useful to prepare messages shown to the user.

This is the library used to replace placeholders in Thingpedia formatted strings.

Usage

const interp = require('string-interp');

// returns "foo bar baz"
interp('foo $p1 ${p2}', { p1: 'bar', p2: 'baz' }, { locale: 'en-US' });

Syntax

The syntax recognizes parameters preceded by a dollar sign $.

In the short form, the parameter name follows the dollar sign immediately. In this case, all identifier-like letters following the dollar sign are considered part of the parameter name. Example:

interp('$a $a$aa$a,a', { a: '1', aa: '2' }) === '1 121,a'

In the long form, the parameter name is wrapped in {}. Use this form if the parameter is immediately followed by another letter or number. Example:

interp('${a} ${a}a ${aa}', { a: '1', aa: '2' }) === '1 1a 2'

In the long form the parameter can be followed by an option, separated with :. Options affect how the parameter value is transformed into a string. Example:

interp('${a} ${a:url}', { a: '/' }) === '/ %2F'

Available options

General options:

  • url: URL-encode the value with encodeURIComponent

Options for Date:

  • iso-date: format a Date object as an ISO 8661 string.

FAQs

Package last updated on 27 Sep 2020

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.