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

@ambassify/aql-condition

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ambassify/aql-condition - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

.nyc_output/f3cc28aa-479f-490d-b658-053db4f57a05.json

93

lib/index.js

@@ -5,33 +5,4 @@ 'use strict';

var KEYLESS = ['and', 'or', 'not'];
var normalize = require('./normalize');
function normalize(condition) {
var _ref = condition || {},
operator = _ref.operator;
var _ref2 = condition || {},
value = _ref2.value;
if (!operator) return null;
if (!KEYLESS.includes(operator)) return condition;
if (operator == 'and' || operator == 'or') {
value = value.map(normalize).filter(Boolean);
if (!value.length) return null;
value = value.reduce(function (r, subCondition) {
if (subCondition.operator === operator) return r.concat(subCondition.value);else return r.concat(subCondition);
}, []);
if (value.length === 1) return value[0];
} else if (operator === 'not') {
value = normalize(value);
if (!value) return null;
if (value.operator === operator) return value.value;
}
return {
operator: operator,
value: value
};
}
function parse(str) {

@@ -42,61 +13,7 @@ var condition = aqlParser.condition(str) || (aqlParser.url(str) || {}).condition;

function filter(condition, predicate) {
if (!condition || !condition.operator) return null;
if (KEYLESS.includes(condition.operator)) {
var value = condition.value;
value = condition.operator === 'not' ? filter(value, predicate) : value.map(function (c) {
return filter(c, predicate);
});
return normalize(Object.assign({}, condition, {
value: value
}));
}
if (!predicate(condition)) return null;
return condition;
}
function and() {
for (var _len = arguments.length, conditions = new Array(_len), _key = 0; _key < _len; _key++) {
conditions[_key] = arguments[_key];
}
conditions = conditions.map(normalize).filter(Boolean);
if (!conditions.length) return null;
if (conditions.length === 1) return conditions[0];
return normalize({
operator: 'and',
value: conditions
});
}
function or() {
for (var _len2 = arguments.length, conditions = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
conditions[_key2] = arguments[_key2];
}
conditions = conditions.map(normalize).filter(Boolean);
if (!conditions.length) return null;
if (conditions.length === 1) return conditions[0];
return normalize({
operator: 'or',
value: conditions
});
}
function not(condition) {
return normalize({
operator: 'not',
value: condition
});
}
module.exports = {
module.exports = Object.assign({
OPERATORS: require('./operators'),
parse: parse,
normalize: normalize,
filter: filter,
and: and,
or: or,
not: not
};
isValid: require('./validate')
}, require('./builders'), require('./iterators'));
{
"name": "@ambassify/aql-condition",
"version": "0.2.0",
"version": "0.3.0",
"description": "AQL condition tool",

@@ -29,3 +29,3 @@ "main": "src/index.js",

"dependencies": {
"@ambassify/aql-parser": "^0.2.0"
"@ambassify/aql-parser": "^0.3.0"
},

@@ -45,3 +45,3 @@ "devDependencies": {

},
"gitHead": "2e1a16efd3886d0a6bc40b62335549da55dc288d"
"gitHead": "c3c64213038c02c85e95082e842d0ad88f164187"
}

@@ -5,42 +5,4 @@ 'use strict';

const KEYLESS = [ 'and', 'or', 'not' ];
const normalize = require('./normalize');
function normalize(condition) {
const { operator } = condition || {};
let { value } = condition || {};
if (!operator)
return null;
if (!KEYLESS.includes(operator))
return condition;
if (operator == 'and' || operator == 'or') {
value = value.map(normalize).filter(Boolean);
if (!value.length)
return null;
value = value.reduce((r, subCondition) => {
if (subCondition.operator === operator)
return r.concat(subCondition.value);
else
return r.concat(subCondition);
}, []);
if (value.length === 1)
return value[0];
} else if (operator === 'not') {
value = normalize(value);
if (!value)
return null;
if (value.operator === operator)
return value.value;
}
return { operator, value };
}
function parse(str) {

@@ -53,55 +15,11 @@ const condition = aqlParser.condition(str) ||

function filter(condition, predicate) {
if (!condition || !condition.operator)
return null;
if (KEYLESS.includes(condition.operator)) {
let { value } = condition;
value = condition.operator === 'not' ?
filter(value, predicate) :
value.map(c => filter(c, predicate));
return normalize(Object.assign({}, condition, { value }));
}
if (!predicate(condition))
return null;
return condition;
}
function and(...conditions) {
conditions = conditions.map(normalize).filter(Boolean);
if (!conditions.length)
return null;
if (conditions.length === 1)
return conditions[0];
return normalize({ operator: 'and', value: conditions });
}
function or(...conditions) {
conditions = conditions.map(normalize).filter(Boolean);
if (!conditions.length)
return null;
if (conditions.length === 1)
return conditions[0];
return normalize({ operator: 'or', value: conditions });
}
function not(condition) {
return normalize({ operator: 'not', value: condition });
}
module.exports = {
parse,
normalize,
filter,
and, or, not
};
module.exports = Object.assign(
{
OPERATORS: require('./operators'),
parse,
normalize,
isValid: require('./validate'),
},
require('./builders'),
require('./iterators')
);
{
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
},
"extends": [

@@ -3,0 +8,0 @@ "eslint-config-ambassify/mocha"

@@ -6,3 +6,3 @@ 'use strict';

describe('# paese', function () {
describe('# parse', function () {

@@ -9,0 +9,0 @@ it('should expose the AQL condition parser', () => {

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