Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
ts-expression-evaluator
Advanced tools
Context-based expression evaluator.
npm install ts-expression-evaluator
yarn add ts-expression-evaluator
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.
// array filter
evaluate('staffs[this.id === 1]', context) // [{id: 1, name: 'Tina'}]
Operation | Symbol |
---|---|
Negate | ! |
Operation | Symbol |
---|---|
Add, Concat | + |
Subtract | - |
Multiply | * |
Divide | / |
Operation | Symbol |
---|---|
Logical AND | && |
Logical OR | || |
Comparison | Symbol |
---|---|
Equal | == |
Not equal | != |
Greater than | > |
Greater than or equal | >= |
Less than | < |
Less than or equal | <= |
Type | Examples |
---|---|
Booleans | true , false |
Strings | "Hello "user"", 'Hey there!' |
Numerics | 6, -7.2, 5, -3.14159 |
Arrays | ['hello', 'world!'] |
evaluate(exp: string, context: object): any
registerFunction(name: string, func: Function): void
registerFunctions(funcs: {[key: string]: Function}): void
MIT
FAQs
Context-based expression parse and evaluator.
The npm package ts-expression-evaluator receives a total of 2,562 weekly downloads. As such, ts-expression-evaluator popularity was classified as popular.
We found that ts-expression-evaluator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.