npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

js_formula_engine

v2.0.4

Published

JS 公式引擎

Readme

BI 公式引擎

运行环境

编译后支持兼容 es5 的浏览器、JavaScript 引擎。

开发环境 node 版本为 v16.18.0

主要功能

  • 表达式解析
  • 可扩展预定义函数
  • 输出sql语句
    • 支持 mysql
    • 支持 pgsql
    • 支持指定字段别名
  • 直接执行表达式
  • 兼容常用全角字符
  • 允许限制可用函数
  • 功能测试

安装 npm 包

npm i js_formula_engine

Java 或 .net 使用,直接加载 index.js 内容,相当于 import 'js_formula_engine'

使用简介

先创建公式引擎实例,然后调用 parse 函数解析表达式。解析结果中的 data 字段是执行表达式或生成SQL语句的参数。

使用示例

import 'js_formula_engine'

// 创建引擎对象
const engine = new FormulaEngine();

// 解析表达式, 格式 engine.parse(表达式字符串, 表达式字段名称, 【可选】可用字段信息数组)
const data = engine.parse('"4" + "5" + if(false, 5, "888") + if (true, "aaa" + 666 + 999, "bbb") + 1 + "2" + "3"+1+2+3+4;', 'test', fields);

// 执行表达式,格式 engine.execute(解析结果data,【可选】数据字段的值,需要保证值类型和字段名称与解析时类型一致)
let value = engine.execute(data.data)
console.log(value.data)

// 生成SQL语句, 格式 engine.generateSQL(解析结果data, 【可选】字段别名信息)
let value = engine.generateSQL(data.data)
console.log(value.data)

V2.0 开始支持 mysql (默认), pgsql。指定生成的 SQL类型

// 创建引擎时指定默认SQL类型
const engine = new FormulaEngine(undefined, 'pgsql');

// 解析时指定类型
const data = engine.parse('1+2+3+4', 'test', fields, 'pgsql');

// 同时输出两种类型
const data = engine.parse('1+2+3+4', 'test', fields, ['mysql', 'pgsql']);

// 生成SQL时指定类型
// 需要注意的是,如果解析时的SQL类型不包含或引擎默认的SQL类型与 generateSQL 时的类型不一致,会自动重新解析,性能较差
engine.generateSQL(data.data, 'mysql');