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

mm_maths

v1.2.0

Published

这是一个可以将数学公式推导变形,并转成js和计算的模块。

Readme

mm_maths

这是一个可以将数学公式推导变形,并转成js和计算的模块。

安装

npm install mm_maths

基本使用

1. 初始化模块

const Maths = require('mm_maths');

// 创建实例并指定模块路径
const maths = new Maths(__dirname);

2. 载入公式

// 载入基础数学公式
maths.update(__dirname, "base");

// 也可以分别载入不同类型的公式
maths.load_identities(__dirname, "base");  // 载入恒等式
maths.load_convert(__dirname, "base");     // 载入转换函数
maths.load_symbol(__dirname, "base");      // 载入符号处理函数
maths.load_math(__dirname, "base");        // 载入计算函数

3. 设置常量和变量

// 设置常量
const consts = {
    a: 10,
    b: 3
};
maths.set_const(consts);

// 设置变量
const vars = {
    ma5: "MA(CLOSE, 5)",  // 可以设置公式作为变量
    price: null
};
maths.set_var(vars);

4. 公式转换和计算

// 转换公式
const expression = "y = abc * ab * 3c * 2";
const express = maths.convertTo(expression);
console.log('转换后的公式:', express);

// 运行代码
const result = maths.run_code("return " + express);
console.log('计算结果:', result);

API 说明

主要类

Maths

数学公式计算的主类,提供公式转换、计算等功能。

构造函数参数:

  • dir {String} 模块路径,默认为 __dirname

主要方法

update(path, type)

更新并载入指定类型的所有公式。

  • path {String} 检索路径
  • type {String} 公式类型,如 "base"(基础数学)、"stock"(股票)

set_const(constant)

设置常量。

  • constant {Object} 常量集合,如 { a: 10, b: 15 }

set_var(vars)

设置变量。

  • vars {Object} 变量集合,如 { ma5: "MA(CLOSE, 5)", price: null }

convertTo(express)

转换公式。

  • express {String} 要转换的表达式
  • 返回 {String} 转换后的表达式

run_code(express)

运行代码。

  • express {String} 要执行的表达式
  • 返回 {Object} 执行结果

支持的公式类型

  • 基础数学 (base)
    • 四则运算
    • 指数运算
    • 对数运算
    • 三角函数
  • 数组运算 (array)
    • 求和
    • 平均值
    • 最大/最小值
    • 中位数
  • 股票技术指标 (stock)
    • MA (移动平均线)
    • MACD
    • RSI
    • BBANDS (布林带)

注意事项

  1. 在使用前请确保已正确载入所需的公式类型
  2. 设置常量和变量时注意避免名称冲突
  3. 公式转换时注意检查语法正确性

许可证

ISC License