# scriptexecutor

> A simple dynamic script executor based on JavaScript new function

Latest version **1.0.1** (published 2021-04-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install scriptexecutor
pnpm add scriptexecutor
yarn add scriptexecutor
bun add scriptexecutor
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-04-12 |
| First published | 2021-04-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | guobinhaopro@gmail.com |
| Maintainers | guobh |
| Keywords | rule, script, scriptexecutor, JavaScript |

## Links

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

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2021-04-12
- 1.0.0 — 2021-04-12

## README

### A simple dynamic script executor based on JavaScript new function
```
for example:
context: {a: 1, b: 2}
   express: 'contenx.a && contenx.b'  booleanMatch output true
   express: 'contenx.a && contenx.b > 5'  booleanMatch output false
   express: 'matchCounts(context,"a","b") > 1'  booleanMatch output true
   express: 'context.a'  calculation output 1
```

### when the executor is executed, express will be converted to JavaScript code

1. express: context.QN006AC0001 || context.QN006AC0003 || context.QN006AC0004
```javascript
function booleanMatch(context) {
  return context.QN006AC0001 || context.QN006AC0003 || context.QN006AC0004 ? true : false
}
```

2. express: matchCounts(context,"QN006AC0138","QN006AC0139","QN006AC0140","QN006AC0141") > 1
```javascript
function booleanMatch(context, matchCounts) {
  return matchCounts(context, "QN006AC0138", "QN006AC0139", "QN006AC0140", "QN006AC0141") > 1 ? true : false
}
```

### quick start

```
npm i scriptexecutor
```

```javascript

import scriptExecutor from 'scriptExecutor'

let context = {
  name: "张三",
  age: 12
}

console.log(scriptExecutor.match(context, 'context.name === \'张三\'', new Map()))
console.log(scriptExecutor.match(context, 'context.age === 12 && context.name === \'张三\''))
console.log(scriptExecutor.calculation(context, 'context.age + 10'))
console.log(scriptExecutor.calculation(context, '(context.age + 10) > 10'))
console.log(scriptExecutor.match(context, 'context.parent'))

// custom function
let funcMap = new Map()
funcMap.set('subTen', (context, arg) => {
  return context[arg] - 10
})

console.log(scriptExecutor.match(context, 'subTen(context,\'age\') === 2', funcMap))
console.log(scriptExecutor.match(context, 'subTen(context,\'age\') === 3', funcMap))
```

### update info
1. update time 2021/04/12
2. support dynamic script execution
3. support custom function
4. fixed readme

### feature
There is nothing for the time being

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