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

jsexp

Package Overview
Dependencies
Maintainers
4
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsexp - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

transform.js

2

package.json
{
"name": "jsexp",
"version": "0.0.6",
"version": "0.0.7",
"license": "MIT",

@@ -5,0 +5,0 @@ "scripts": {

'use strict';
var rulesMap = require('./rulesMap');
var transform = require('./transform');
var withScope = require('./withScope');
var rulesMapReverse = Object.keys(rulesMap).reduce(function (map, rule) {
map[rulesMap[rule].operator] = rule;
return map;
}, {
AND: '$and',
OR: '$or',
empty: '$empty',
"in": '$in',
match: '$match'
});
var IDENTIFIER = 'Identifier';
var MEMBER_EXP = 'MemberExpression';
var LITERAL = 'Literal';
var UNARY_EXP = 'UnaryExpression';
var BINARY_EXP = 'BinaryExpression';
var LOGICAL_EXP = 'LogicalExpression';
var ARRAY_EXP = 'ArrayExpression';
function isValidate(value) {
if (Array.isArray(value)) {
return !!value.length;
}
return value !== undefined;
}
function transform(expression) {
if (expression) {
var type = expression.type;
var originOperator = expression.operator;
if (originOperator === '@') {
var argument = transform(expression.argument);
return isValidate(argument) ? "@".concat(argument) : undefined;
} else if (type === LITERAL) {
return expression.value;
} else if (type === IDENTIFIER) {
return expression.name;
} else if (type === MEMBER_EXP) {
var object = transform(expression.object);
var property = transform(expression.property);
return isValidate(object) && isValidate(property) ? "".concat(object, ".").concat(property) : undefined;
} else if (type === ARRAY_EXP) {
return expression.elements.map(function (item) {
return transform(item);
});
} else {
var operator = rulesMapReverse[originOperator];
if (operator) {
if (type === UNARY_EXP) {
var _argument = transform(expression.argument);
return isValidate(_argument) ? [operator, _argument] : [];
} else if (type === LOGICAL_EXP || type === BINARY_EXP) {
var left = transform(expression.left);
var right = transform(expression.right);
return isValidate(left) && isValidate(right) ? [operator, left, right] : [];
}
} else {
throw new Error("no support operator `".concat(operator, "`"));
}
}
}
return [];
}
function parse(expression) {

@@ -76,0 +8,0 @@ return withScope(function (exec) {

@@ -5,5 +5,10 @@ 'use strict';

function validate(expression) {
function validate(expression, callback) {
return withScope(function (exec) {
var result = exec(expression);
if (callback) {
return callback(result);
}
return Array.isArray(result) ? !!result.length : !!result;

@@ -10,0 +15,0 @@ }, false);

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