Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lydanne/ctxexp-parser
In the dynamic execution of JS language environment (wechat applet) to execute JS class calling function.
https://github.com/lydanne/ctxexp-parser
ast eval javascript jsonpath parser
Last synced: about 2 months ago
JSON representation
In the dynamic execution of JS language environment (wechat applet) to execute JS class calling function.
- Host: GitHub
- URL: https://github.com/lydanne/ctxexp-parser
- Owner: Lydanne
- License: mit
- Created: 2021-09-23T09:22:42.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-11-04T02:59:10.000Z (about 3 years ago)
- Last Synced: 2024-08-10T07:48:15.117Z (5 months ago)
- Topics: ast, eval, javascript, jsonpath, parser
- Language: JavaScript
- Homepage:
- Size: 691 KB
- Stars: 20
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Ctxexp Parser
> 上下文表达式解析器
在不能动态执行 JS 语言的环境(微信小程序)里执行类 JS 的调用函数。
## Feature
- [x] 轻量包,未压缩 16k,压缩 4k
- [x] 单元测试 >85% 的代码覆盖
- [x] 使用状态机编写词法分析
- [x] 动态执行表达式
- [x] 调用方法支持传入 Number `+1 -1 1.1`
- [x] 调用方法支持传入 String
- [x] 调用方法支持传入 Callback `([参数])=><上下文表达式>`
- [x] 支持传入多个参数
- [x] 支持嵌套调用
- [x] 语法错误检查
- [x] 支持链式调用、链式访问
- [x] 支持数组的访问## Tip
- 不支持在表达式中使用空格 如 `$.fn(1, 2)`
- 回调函数只支持简单的箭头函数## Install
```
npm i ctxexp-parser
# yarn add ctxexp-parser
```## Uses
```js
const { CtxexpParser } = require("ctxexp-parser");
// import { CtxexpParser } from "ctxexp-parser";const $ = {
a: "hello",
fn(str, str2) {
return str + str2;
},
runs(...cbs) {
return cbs.map((cb, index) => cb(index));
},
Type(i) {
return ["A", "D", "C"][i];
},
};const exp = `$.a`;
const res = new CtxexpParser($, exp).exec();
console.log(res); // helloconst exp1 = `$.fn($.a," cxtexp")`;
const res1 = new CtxexpParser($, exp1).exec();
console.log(res1); // hello cxtexpconst exp2 = `$.runs((i)=>$.Type(i)).join("")`;
const res2 = new CtxexpParser($, exp2).exec();
console.log(res2); // A
```[查看更多例子](https://github.com/WumaCoder/ctxexp-parser/blob/main/test/index.spec.ts)
## State
![state](./status.png)
## About
MIT License