ctxexp-parser 一个轻量级的可以在小程序动态执行JS调用的库
发布于 3 年前 作者 icai 2941 次浏览 来自 分享

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

回到顶部