ctxexp-parser 一个轻量级的可以在小程序动态执行JS调用的库

发布于 4 年前作者 icai3128 次浏览最后编辑 4 年前来自 share

Ctxexp Parser

上下文表达式解析器

在不能动态执行 JS 语言的环境(微信小程序)里执行类 JS 的调用函数。

Feature

Tip

  • 不支持在表达式中使用空格 如 $.fn(1, 2)

Install

npm i ctxexp-parser
# yarn add ctxexp-parser

Uses

import CtxexpParser from "ctxexp-parser";
// const CtxexpParser = require("ctxexp-parser");

const $ = {
  a: "hello",
  fn(str, str2) {
    return str + str2;
  },
};

const exp = `$.a`;

const res = new CtxexpParser($, exp).exec();

console.log(res); // hello

const exp1 = `$.fn($.a," cxtexp")`;

const res1 = new CtxexpParser($, exp1).exec();

console.log(res1); // hello cxtexp

查看更多例子

About

MIT License

0 回复
暂无回复