Socket
Socket
Sign inDemoInstall

jshiki

Package Overview
Dependencies
1
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jshiki

Lightweight expression evaluation library for Node.js


Version published
Weekly downloads
9
decreased by-30.77%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

v3.4.0 (2021-09-10)

Additions

  • Asynchronous expressions are now supported!
    • 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
      

Fixes

  • 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
    

Development changes

  • Unit tests are now run before functional tests.
  • Updated yarn to 3.0.2

Full Changelog

Readme

Source

j式 — jshiki

Safe and Easy Expression Evaluation for Node.js

Build Status Codecov Coverage Status npm Version

Documentation | Change Log


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.

Basic Usage

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

Accessing data

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"

Asynchronous evaluation

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.

Discussion

Discuss jshiki on GitHub discussions. Make sure to follow the code of conduct.

Contributing

If you're looking for a way to contribute to jshiki, see the contribution guide.

Licence

MIT

Keywords

FAQs

Last updated on 10 Sep 2021

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc