Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adalinesimonian/jshiki
Lightweight expression parsing and execution library for Node.js
https://github.com/adalinesimonian/jshiki
acorn expression-evaluator expression-parser expressions javascript nodejs npm typescript
Last synced: 3 days ago
JSON representation
Lightweight expression parsing and execution library for Node.js
- Host: GitHub
- URL: https://github.com/adalinesimonian/jshiki
- Owner: adalinesimonian
- License: mit
- Created: 2015-09-07T03:18:13.000Z (about 9 years ago)
- Default Branch: main
- Last Pushed: 2024-11-01T18:48:06.000Z (12 days ago)
- Last Synced: 2024-11-01T19:29:33.120Z (12 days ago)
- Topics: acorn, expression-evaluator, expression-parser, expressions, javascript, nodejs, npm, typescript
- Language: TypeScript
- Homepage: https://jshiki.io
- Size: 4.94 MB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
![j式 — jshiki](assets/logo/jshiki-readme-banner.svg)
Safe and Easy Expression Evaluation for Node.js
---
jshiki provides a safe and easy 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 to parse expressions.
> **IMPORTANT!** jshiki is not a true sandbox. If you need to be able to evaluate arbitrary code of unknown origin, you may want to consider using [vm2] or a similar library.
### Basic Usage
```js
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
```js
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
```js
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](LICENCE)
[acorn]: https://github.com/acornjs/acorn
[vm2]: https://github.com/patriksimek/vm2
[documentation]: https://jshiki.io/latest/user-guide/
[github discussions]: https://github.com/adalinesimonian/jshiki/discussions
[code of conduct]: CODE_OF_CONDUCT.md
[contribution guide]: CONTRIBUTING.md