Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eval-estree-expression

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eval-estree-expression - npm Package Compare versions

Comparing version 0.0.1 to 1.0.0

2

package.json
{
"name": "eval-estree-expression",
"description": "Safely evaluate JavaScript (estree) expressions, sync and async.",
"version": "0.0.1",
"version": "1.0.0",
"license": "MIT",

@@ -6,0 +6,0 @@ "homepage": "https://github.com/jonschlinkert/eval-estree-expression",

@@ -11,4 +11,6 @@ # eval-estree-expression [![NPM version](https://img.shields.io/npm/v/eval-estree-expression.svg?style=flat)](https://www.npmjs.com/package/eval-estree-expression) [![NPM monthly downloads](https://img.shields.io/npm/dm/eval-estree-expression.svg?style=flat)](https://npmjs.org/package/eval-estree-expression) [![NPM total downloads](https://img.shields.io/npm/dt/eval-estree-expression.svg?style=flat)](https://npmjs.org/package/eval-estree-expression)

* [Usage with Esprima](#usage-with-esprima)
* [async usage](#async-usage)
* [sync usage](#sync-usage)
- [API](#api)
* [.evaluate](#evaluate)
* [.evaluate.sync](#evaluatesync)
* [.variables](#variables)
- [Options](#options)

@@ -21,2 +23,4 @@ * [booleanLogicalOperators](#booleanlogicaloperators)

* [withMembers](#withmembers)
- [Examples](#examples)
* [Operators](#operators)
- [About](#about)

@@ -36,2 +40,4 @@

Requires [Node.js](https://nodejs.org/en/download/) version 14 or greater.
Evaluates an [estree](https://github.com/estree/estree) expression from [@babel/parser][], [esprima](http://esprima.org), [acorn](https://github.com/acornjs/acorn), or any other library that parses and returns a valid `estree` expression.

@@ -89,4 +95,6 @@

### async usage
## API
### .evaluate
Evaluate expresssions asynchronously.

@@ -104,3 +112,3 @@

### sync usage
### .evaluate.sync

@@ -119,2 +127,15 @@ Evaluate expresssions synchronously.

### .variables
Get an array of variables from an expression:
```js
const { parseExpression } = require('@babel/parser');
const { variables } = require('eval-estree-expression');
console.log(variables(parseExpression('x * (y * 3) + z.y.x'))); //=> ['x', 'y', 'z']
console.log(variables(parseExpression('(a || b) ? c + d : e * f'))); //=> ['a', 'b', 'c', 'd', 'e', 'f']
```
## Options

@@ -187,6 +208,10 @@

Enable the `=~` regex operator to support testing values without using functions (example `name =~ /^a.*c$/`).
**Why is this needed?**
In expressions, if you wish to test a value using a regular expression, you have two options:
1. Enable function support so that you can use methods like `.test()` and `.match()`, or
2. Use this option, which enables support for a special syntax for matching against regular expressions, _without the need to enable support for evaluating functions_.
2. Use this option, which uses a special syntax to match against regular expressions _without evaluating an functions_.

@@ -218,2 +243,48 @@ In other words, instead of having to do this:

Used with the [variables](#variables) method to return nested variables (e.g. variables with dot notation, like `foo.bar.baz`).
## Examples
### Operators
Supports all JavaScript operators with the exception of assignment operators (`=`, `+=`, etc):
```js
// Arithmetic operators
evaluate('a + b');
evaluate('a - b');
evaluate('a / b');
evaluate('a * b');
evaluate('a % b');
evaluate('a ** b');
// Relational operators
evaluate('a instanceof b');
evaluate('a < b');
evaluate('a > b');
evaluate('a <= b');
evaluate('a >= b');
// Equality operators
evaluate('a !== b');
evaluate('a === b');
evaluate('a != b');
evaluate('a == b');
// Bitwise shift operators
evaluate('a << b');
evaluate('a >> b');
evaluate('a >>> b');
// Binary bitwise operators
evaluate('a & b');
evaluate('a | b');
evaluate('a ^ b');
// Binary logical operators
evaluate('a && b'); // Logical AND.
evaluate('a || b'); // Logical OR.
evaluate('a ?? b'); // Nullish Coalescing Operator.
```
## About

@@ -271,2 +342,2 @@

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on September 05, 2021._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on September 06, 2021._
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