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

boolean-parser

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

boolean-parser - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

48

index.js

@@ -8,2 +8,21 @@ // Boolean-parser.js

// Return true if arrays are equal
function _arraysAreEqual(arrA, arrB) {
if (!Array.isArray(arrA) || !Array.isArray(arrB))
{
throw new TypeError("both parameters have to be an array");
}
if (arrA.length !== arrB.length)
{
return false;
}
for (var i = 0; i < arrA.length; i++) {
// No deep equal necessary
if (arrA[i] !== arrB[i]){
return false;
}
}
return true;
}
// This function converts a boolean query to a 2 dimensional array.

@@ -125,9 +144,27 @@ // a AND (b OR c)

// TODO
// Removes duplicate and paths within an or path
// in:
// [ [ a, b ], [ c ], [ a, b ] ]
// [ [ a, b ], [ c ], [ b, a ] ]
// out:
// [ [ a, b ], [ c ] ]
function deduplicateOr(orPath) {
//
// with order matters
// in:
// [ [ a, b ], [ c ], [ b, a ] ]
// out:
// [ [ a, b ], [ c ], [ b, a ] ]
function deduplicateOr(orPath, orderMatters) {
var path = orderMatters ?
orPath :
orPath.map(function(item) { return item.sort() });
return path.reduce(function(memo, current){
for (var i = 0; i < memo.length; i++) {
if (_arraysAreEqual(memo[i], current)) {
return memo;
}
}
memo.push(current);
return memo;
}, []);
}

@@ -183,3 +220,2 @@

if (counter === 0) {
console.log('counter is at 0');

@@ -189,3 +225,2 @@ // If we are not at the end of the sentence, Return the

if (i !== phrase.length - 1) {
console.log('closing bracket is not at the end, ', phrase);
return phrase;

@@ -196,3 +231,2 @@ }

else {
console.log('closing bracket IS at the end, ', phrase);
return phrase.substring(1, phrase.length - 1);

@@ -204,3 +238,2 @@ }

}
console.log('returning the phrase as is.');

@@ -269,2 +302,3 @@ return phrase;

module.exports = {
deduplicateOr: deduplicateOr,
andAndMerge: andAndMerge,

@@ -271,0 +305,0 @@ orAndOrMerge: orAndOrMerge,

2

package.json
{
"name": "boolean-parser",
"version": "0.0.1",
"version": "0.0.2",
"description": "Script that parses a boolean query to an array with all the possibilities. IE: (a AND (b OR c)) -> [[a, b],[a, c]]",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -157,2 +157,22 @@ var assert = require('assert');

});
describe('deduplicateOr()', function() {
it('Should remove duplicate and-paths within an or-path', function() {
assert.deepEqual(
[ [ 'a', 'b' ], [ 'c' ] ],
bparser.deduplicateOr(
[ [ 'a', 'b' ], [ 'c' ], [ 'a', 'b' ], [ 'b', 'a' ] ]
)
);
});
it('Should remove duplicate and-paths within an or-path (order matters)', function() {
assert.deepEqual(
[ [ 'a', 'b' ], [ 'c' ], [ 'b', 'a' ] ],
bparser.deduplicateOr(
[ [ 'a', 'b' ], [ 'c' ], [ 'a', 'b' ], [ 'b', 'a' ] ],
true
)
);
});
});
});

@@ -205,3 +225,2 @@

// TODO create test for detecting duplicates
});
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