Skip to content

Commit

Permalink
Adjust tests and add error to logical operators
Browse files Browse the repository at this point in the history
  • Loading branch information
torto committed Aug 26, 2019
1 parent 4db8adb commit 62ea73f
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 62 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ console.log('$or -', 'Have to be false:', easy.compare('13', {
}));

//$not
console.log('$not -', 'Have to be true:', compare.compare([35, 40, 50], { $not: { $in: 45 } }));
console.log('$not -', 'Have to be false:', compare.compare([35, 40, 50], {
console.log('$not -', 'Have to be true:', easy.compare([35, 40, 50], { $not: { $in: 45 } }));
console.log('$not -', 'Have to be false:', easy.compare([35, 40, 50], {
$not: {
$in: 35,
$and: {
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { compare } = require('./lib/compare')
const compare = require('./lib/compare')

module.exports = {
compare
Expand Down
5 changes: 2 additions & 3 deletions lib/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function interatorValues (value, operator, item) {
function executeLogicalOperator (funcLogical) {
return (value, operator, key) => {
const keys = Object.keys(operator)
if (!keys.length) throw new Error(`The operator ${key} need to be an object valid.`)
return funcLogical(keys, interatorValues, value, operator)
}
}
Expand All @@ -62,6 +63,4 @@ function compare (value, operator) {
return interatorValues(value, operator, keys[0])
}

module.exports = {
compare
}
module.exports = compare
1 change: 1 addition & 0 deletions lib/comparison.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function isNotSameSize (value, comparation) {
function isRegexMatch (value, comparation) {
return new RegExp(comparation).test(value)
}

function isNotRegexMatch (value, comparation) {
return !new RegExp(comparation).test(value)
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "easy-compare",
"version": "0.0.9",
"version": "0.0.10",
"description": "Compare values using opertaros like mongodb",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 12 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'user strict'

const expect = require('chai').expect

const easy = require('..')

describe('Index test case', () => {
it('Should call the compare function', () => {
expect(easy.compare(10, { $eq: 10 })).to.be.true
expect(easy.compare(10, { $eq: 11 })).to.be.false
})
})
Loading

0 comments on commit 62ea73f

Please sign in to comment.