Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
string-template-parser
Advanced tools
Readme
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.
evaluateStringTemplate
takes a string and a list of variables and
one of pipe functions and returns a string where the variables are
replaced with their values (transformed by the pipe functions if
necessary).
evaluateParsedString
takes a parsed string object generated by the
parseStringTemplate
function and returns a concatenated string with
the variables replaced by the given values in the variable dictionary,
passed through the pipe functions if necessary. This function is useful
when not using the default parseStringTemplate
function, but one
generated by passing a parameter to parseStringTemplateGenerator
.
evaluateParsedString(parseStringTemplateGenerator()(input), ...args)
is equivalent to evaluateStringTemplate(input, ...args)
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 parseAngularStringTemplate = parseStringTemplateGenerator({
VARIABLE_START: /^\{\{\s*/,
VARIABLE_END: /^\s*\}\}/
});
parseAngularStringTemplate('a {{v1|p:param}} b {{v2}} c');
/* returns:
{
literals: ['a ', ' b ', ' c'],
variables: [
{ name: 'v1', pipes: [{ name: 'p', parameters: ['param'] }],
{ name: 'v2', pipes: []}
]
}
*/
evaluateStringTemplate
import { evaluateStringTemplate } from 'string-template-parser';
evaluateStringTemplate(
'x ${a|upper} y',
{a: 'string'},
{upper: value => value.toUpperCase()}
);
// returns 'x STRING y'
evaluateParsedString
import {
parseStringTemplateGenerator,
evaluateParsedString
} from 'string-template-parser';
const parseAngularStringTemplate = parseStringTemplateGenerator({
VARIABLE_START: /^\{\{\s*/,
VARIABLE_END: /^\s*\}\}/
});
evaluateParsedString(
parseAngularStringTemplate('x {{a|upper}} y'),
{a: 'string'},
{upper: value => value.toUpperCase()}
);
// returns 'x STRING y'
FAQs
Parsing & evaluating utilities for string templates
The npm package string-template-parser receives a total of 1,885 weekly downloads. As such, string-template-parser popularity was classified as popular.
We found that string-template-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.