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.
jshiki
Advanced tools
Changelog
v3.4.0 (2021-09-10)
parseAsync
returns an async function
const expr = jshiki.parseAsync('1 + 2')
await expr() // => 3
evaluateAsync
returns a promise
await jshiki.evaluateAsync('1 + 2') // => 3
await
is supported within async expressions
const expr = jshiki.parseAsync('await a()')
await expr({ a: async () => 1 }) // => 1
Fixed bug where calling a method on a property using optional chaining syntax would instead operate as though regular member access was used. Example:
// Prior behavior:
jshiki.evaluate('a?.b?.()') // throws TypeError
jshiki.evaluate('a?.b()') // throws TypeError
// Patched behaviour:
jshiki.evaluate('a?.b?.()') // returns undefined
jshiki.evaluate('a?.b()') // returns undefined
Readme
jshiki provides a safe and simple way to evaluate expressions without worrying about external data being overwritten or accessed in unexpected ways. jshiki only has one lightweight dependency, acorn, which it uses parse expressions.
const jshiki = require('jshiki')
let result = jshiki.evaluate('(5 + 7) / 3') // result => 4
// or
let expression = jshiki.parse('(5 + 7) / 3')
result = expression() // result => 4
const code = "`Hello! My name's ${name.trim()}`"
expression = jshiki.parse(code)
result = expression({ name: ' Azumi ' })
// result => "Hello! My name's Azumi"
// or
result = jshiki.evaluate(code, {
scope: { name: ' Azumi ' },
})
// result => "Hello! My name's Azumi"
const asyncCode = "`I'm ${await status()}...`"
expression = jshiki.parseAsync(asyncCode)
result = await expression({
status: async () => 'waiting',
})
// result => "I'm waiting..."
// or
result = await jshiki.evaluateAsync(asyncCode, {
scope: { status: async () => 'waiting' },
})
// result => "I'm waiting..."
For more examples, features, and information on how to use jshiki, see the documentation.
Discuss jshiki on GitHub discussions. Make sure to follow the code of conduct.
If you're looking for a way to contribute to jshiki, see the contribution guide.
FAQs
Lightweight expression evaluation library for Node.js
The npm package jshiki receives a total of 9 weekly downloads. As such, jshiki popularity was classified as not popular.
We found that jshiki 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.