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.
eval-interpolation-sandbox
Advanced tools
Readme
Interpolate strings with sandboxed JS code
parseTemplate = require('eval-interpolation-sandbox')
parseTemplate( "`name`", {name: "John"} )
// 'John'
parseTemplate( "`name.join(' ')`", {name: ["John", "Locke"]} )
// 'John Locke'
parseTemplate( "`++i`; `++i`; `++i`", {i:0} )
// '1; 2; 3'
context = { i:0, names: ["John", "Paul"] }
parseTemplate( "`++i` - `names.shift()`", context )
parseTemplate( "`++i` - `names.shift()`", context )
// '1 - John'
// '2 - Paul'
npm install eval-interpolation-sandbox
To get the synchronous parser function with default options, just import the package root:
parseTemplate = require('eval-interpolation-sandbox')
result = parseTemplate( "`name.join(\" \")`", {name: ["Paul", "Jefferson"]} ) // 'Paul Jefferson'
To get the asynchronous parser, or set custom defalut options
ParserSync = parseTemplate.ParserSync
ParserAsync = parseTemplate.ParserAsync
parserAsync = new ParserAsync( {delimiter: ["\#{", "}"]} )
parserAsync.parseTemplate( "#{value}", {value: 42}, function(err,res){ console.log(res) } ) // '42'
opts
is an object with the default values of the same options passed to parseTemplate
template
is the string containing the tokens that will be evaluated.
context
is the object containing the values that will be available for the tokens.
callback(err,res)
opts
is an object which can receive the following options:
sandbox
(default: false)
Clones the context before parsing each token, thereby isolating the context for each token.
ignore
(default: false)
Ignores errors while parsing the template. The callback will return a list of errors, and the formatted string with the placeholders where the errors occurred replaced by blank space.
delimiter
(default: "`"
)
Defines the symbol that delimits both sides of the placeholders within the string. Accepts a string, which will define both delimiters, or an array with two strings, which will define the left and right delimiters, respectively.
parseTemplate( "\'value\'", {value: 42}, { delimiter: "\'" } )
parseTemplate( "\#{value}", {value: 42}, { delimiter: ["\#{", "}"] } )
The same as ParserAsync
, with parseTemplate
being synchronous and not accepting
the ignore
option.
opts
: {sandbox=0, delimiter="`"}
FAQs
Javascript string interpolation with sandboxed JS code
The npm package eval-interpolation-sandbox receives a total of 5 weekly downloads. As such, eval-interpolation-sandbox popularity was classified as not popular.
We found that eval-interpolation-sandbox 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.