# condition-parser

> 条件解析执行器

Latest version **1.0.1** (published 2022-11-11) · 0 weekly downloads

## Install

```sh
npm install condition-parser
pnpm add condition-parser
yarn add condition-parser
bun add condition-parser
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-11-11 |
| First published | 2022-11-11 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 22 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | mayuxian |
| Keywords | condition, expression, condition-parser, 条件, 表达式 |

## Links

- npm: https://www.npmjs.com/package/condition-parser
- npm.io page: https://npm.io/package/condition-parser

## Dependencies (3)

- [vue](https://npm.io/package/vue.md) ^3.2.44
- [element-plus](https://npm.io/package/element-plus.md) ^2.2.20
- [vue3-ace-editor](https://npm.io/package/vue3-ace-editor.md) ^2.2.2

## Recent versions

- 1.0.1 (latest) — 2022-11-11
- 1.0.0 — 2022-11-11

## README

# condition-parser
用于执行表达式的js库

## Installing

Using npm:

```bash
$ npm install condition-parser
```

Using bower:

```bash
$ bower install condition-parser
```

Using yarn:

```bash
$ yarn add condition-parser
```


 ##  Demo

 [Demo链接](https://mayuxian.github.io/condition-parser/)
 [源码](https://github.com/mayuxian/condition-parser)
 ###  init data  (Vue3)  初始数据
 ``` javascript
 const conditions: Ref<Condition[] | undefined> = ref()
 function init() {
  const cond1 = new Condition()
  cond1.expressions = [
    new Expression({
      key: '1',
      label: '',
      relation: '&&',
    }),
    new Expression({ key: '2', label: '' }),
  ]
  const cond2 = new Condition()
  cond2.expressions = [
    new Expression({
      key: '3',
      label: '',
      relation: '||',
    }),
    new Expression({ label: '', key: '4' }),
  ]
  conditions.value = [cond1, cond2]
}
init()
 ``` 
### generate json    生成json数据
``` javascript
  const condiParser = new ConditionParser(conditions.value || [])
  const jsonStr = condiParser.generate()
  console.log('condiParser.generate ', jsonStr)
```

### reload and invert   加载反显
``` javascript
 const jsonStr=''; //条件json字符串
 const invertConditions: Ref<Condition[] | undefined> = ref();
 const conditionArray = condiParser.parse(jsonStr)
  invertConditions.value = conditionArray

```

### execute and check  执行校验
``` javascript
 const jsonStr=''; //条件json字符串
 const conditions = condiParser.parse(jsonStr)

 const condiParser = new ConditionParser(conditions|| [])
  const result = condiParser.execute((expr: Expression) => {
    return jsonData.find((x: any) => x.id === expr.sourceValue)?.realValue
  })
  console.log('condiParser.execute ', result)
  //每项condition.pass 来判断是会通过
```

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