You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

string-template-parser

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-template-parser

Parsing & evaluating utilities for string templates

1.0.0-rc.0
Source
npmnpm
Version published
Weekly downloads
2.8K
18.71%
Maintainers
1
Weekly downloads
 
Created
Source

string-template-parser

String template parsing utilities.

parseStringTemplate uses the default configuration (i.e. variable start is marked by ${ and variable end by }, the escape character is \, a pipe is started with | and a pipe parameter starts after a :, e.g. 'string ${var | pipe : parameter}').

parseStringTemplateGenerator returns a string parsing function that uses the supplied expressions from the configuration parameter to parse the string.

Usage

parseStringTemplate

import { parseStringTemplate } from 'string-template-parser';

parseStringTemplate('a ${v1|p:param} b ${v2} c');
/* returns:
        {
          literals: ['a ', ' b ', ' c'],
          variables: [
            { name: 'v1', pipes: [{ name: 'p', parameters: ['param'] }],
            { name: 'v2', pipes: []}
          ]
        }
 */

parseStringTemplateGenerator

import { parseStringTemplateGenerator } from 'string-template-parser';
const myParseStringTemplate = parseStringTemplateGenerator({VARIABLE_START: /^\{\{/, VARIABLE_END: /^\}\}/});

myParseStringTemplate('a {{v1|p:param}} b {{v2}} c');
/* returns:
        {
          literals: ['a ', ' b ', ' c'],
          variables: [
            { name: 'v1', pipes: [{ name: 'p', parameters: ['param'] }],
            { name: 'v2', pipes: []}
          ]
        }
 */

FAQs

Package last updated on 13 Nov 2016

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