# formula-calculator-td

> A formula calculator

Latest version **0.1.0** (published 2024-11-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install formula-calculator-td
pnpm add formula-calculator-td
yarn add formula-calculator-td
bun add formula-calculator-td
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2024-11-17 |
| First published | 2023-11-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 143.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Qingflow |
| Maintainers | aiohnan |
| Keywords | node.js, autotesting |

## Links

- npm: https://www.npmjs.com/package/formula-calculator-td
- Repository: https://github.com/QingFlow/FormulaCalculator
- Issues: https://github.com/QingFlow/FormulaCalculator/issues
- npm.io page: https://npm.io/package/formula-calculator-td

## Dependencies (4)

- [dayjs](https://npm.io/package/dayjs.md) ^1.11.0
- [antlr4](https://npm.io/package/antlr4.md) 4.8.0
- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.26.0
- [@formulajs/formulajs](https://npm.io/package/@formulajs/formulajs.md) ^4.3.4

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2024-11-17
- 0.0.11 — 2024-11-17
- 0.0.10 — 2024-11-17
- 0.0.9 — 2024-06-12
- 0.0.8 — 2024-06-06
- 0.0.7 — 2024-06-06
- 0.0.5 — 2024-01-11
- 0.0.4 — 2024-01-10
- 0.0.3 — 2024-01-10
- 0.0.2 — 2023-11-09
- 0.0.1 — 2023-11-09

## README

# 需要安装依赖 @formjs/formjs3.1.1


1. 重新生成代码 antlr4 -Dlanguage=JavaScript -no-listener -visitor Formula.g4

### 使用方法

1. npm install formula-calculator --save

2. 需要使用的地方引入

  `import formula from 'formula-calculator-td';`

3. 调用计算方法

  `//console.log(formula.calculate('SUM(1,2,3)'));`

4. 本地调试

  `npm run calc "sum(1, 2)"`

5. 如果有其他需要，可以提交issue

### 支持的公式类型

- IF
- CONCAT
- LEFT
- RIGHT
- REPLACE
- MID
- TEXT
- NUM
- RMBUPPER
- SUM
- SUMIF
- AVERAGE
- COUNT
- COUNTIF
- MIN
- MAX
- ROUND
- ROUNDUP
- ROUNDDOWN
- INT
- MOD
- PRODUCT
- SUMPRODUCT
- POWER
- YEAR
- MONTH
- DAY
- HOUR
- MINUTE
- SECOND
- DATE
- CURDATE
- NOW
- RDID
- UPPER
- LOWER
- AND
- OR
- NOT
- XOR
- ISEMPTY
- SEARCH
- LEN
- DAYS
- DATEDELTA
- REGTEST
- LN
- IFS
- BASE64
- SQRT
- DATEDIFF
### 规则

1. 字符串要用双引号包裹
2. 字符串中如果需要包含双引号，进入公式前需要把 \ 替换成 \\，再把 " 替换成\"。公式计算出的结果，会自动去掉转义

### 错误码说明
抛出的错误结构为

参数类型错误：
```
{
  "errCode": 1,  // 错误码
  "funcName": "SUM",  // 发生错误方法/操作符名称
  "paramIdx": 1,  // 错误参数索引，从1开始
}
```

参数个数错误
```
{
  "errCode": 2,
  "funcName": "SUM",  // 参数个数错误方法名称
  "expectNum": 2,  // 正确情况下参数个数
  "actualNum": 3,  // 实际参数个数
}
```

错误码说明
- 1: 参数类型错误
- 2: 参数个数错误
- 3: 计算出的结果不正确

---
_Source: https://npm.io/package/formula-calculator-td · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
