Socket
Socket
Sign inDemoInstall

ts-expression-evaluator

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-expression-evaluator - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

5

package.json
{
"name": "ts-expression-evaluator",
"version": "1.0.2",
"version": "1.1.0",
"description": "Context-based expression parse and evaluator.",

@@ -39,4 +39,3 @@ "main": "build/main/index.js",

"all": "run-s reset test cov:check doc:html",
"prepare-release": "run-s all version doc:publish",
"preinstall": "node -e \"if(process.env.npm_execpath.indexOf('yarn') === -1) throw new Error('expression must be installed with Yarn: https://yarnpkg.com/')\""
"prepare-release": "run-s all version doc:publish"
},

@@ -43,0 +42,0 @@ "scripts-info": {

61

README.md
# ts-expression-evaluator
expression
[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[npm-image]: https://img.shields.io/npm/v/ts-expression-evaluator.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/ts-expression-evaluator
[travis-image]: https://img.shields.io/travis/william-yz/ts-expression-evaluator.svg?style=flat-square
[travis-url]: https://travis-ci.org/william-yz/ts-expression-evaluator
Context-based expression parse and evaluator.
## install
- npm
`npm install ts-expression-evaluator`
- yarn
`yarn add ts-expression-evaluator`
## Quick start
```javascript
import evaluate, { registerFunction } from 'ts-expression-evaluator'
const context = {
id: 10,
name: 'FED',
count: 10,
staffs: [{
id: 1,
name: 'Tina'
}, {
id: 2,
name: 'James'
}],
}
// math
evaluate('1+2') // 3
// eval from context
evaluate('name', context) // 'FED'
evaluate('staffs[0].name', context) // 'Tina'
evaluate('count + 10', context) // 20
// ===
evaluate('count === 11', context) // false
// register custom function
registerFunction('IF', (condition, ifTrue, ifFalse) => {
return condition ? ifTrue : ifFalse;
})
evaluate('IF(name === 'FED', 'It\'s FED.', 'It\'s not FED.')') // It's FED.
```
## API
### `evaluate(exp: string, context: object): any`
### `registerFunction(name: string, func: Function): void`
### `registerFunctions(funcs: {[key: string]: Function}): void`
## License
MIT
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc