Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "jsexp", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "scripts": { |
'use strict'; | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
} | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} | ||
var rulesMap = require('./rulesMap'); | ||
@@ -10,14 +30,15 @@ | ||
AND: '$and', | ||
OR: '$or', | ||
empty: '$empty', | ||
"in": '$in', | ||
match: '$match' | ||
OR: '$or' | ||
}); | ||
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'; | ||
var SUPPORT_EXP = [UNARY_EXP, LOGICAL_EXP, BINARY_EXP]; | ||
@@ -37,4 +58,12 @@ function isValidate(value) { | ||
if (Array.isArray(expr) && (rulesMap[expr[0]] || rulesMapReverse[expr[0]])) { | ||
return expr; | ||
if (Array.isArray(expr)) { | ||
var operator = expr[0]; | ||
if (rulesMap[operator]) { | ||
return [rulesMap[operator].operator].concat(_toConsumableArray(expr.slice(1))); | ||
} | ||
if (rulesMapReverse[operator]) { | ||
return expr; | ||
} | ||
} | ||
@@ -62,16 +91,16 @@ } | ||
} else { | ||
var operator = rulesMapReverse[originOperator]; | ||
var _operator = rulesMapReverse[originOperator]; | ||
if (operator) { | ||
if (_operator && SUPPORT_EXP.includes(type)) { | ||
if (type === UNARY_EXP) { | ||
var _argument = transform(expression.argument, callback); | ||
return isValidate(_argument) ? [operator, _argument] : []; | ||
return isValidate(_argument) ? [_operator, _argument] : []; | ||
} else if (type === LOGICAL_EXP || type === BINARY_EXP) { | ||
var left = transform(expression.left, callback); | ||
var right = transform(expression.right, callback); | ||
return isValidate(left) && isValidate(right) ? [operator, left, right] : []; | ||
return isValidate(left) && isValidate(right) ? [_operator, left, right] : []; | ||
} | ||
} else { | ||
throw new Error("no support operator `".concat(operator, "`")); | ||
throw new Error("no support operator `".concat(type, "`")); | ||
} | ||
@@ -78,0 +107,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34665
1085