matches-where-query
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -10,3 +10,3 @@ "use strict"; | ||
if (_underscore["default"].isObject(queryAttribute) && queryAttribute.comparator) { | ||
if (_underscore["default"].isUndefined(queryAttribute.value)) throw new Error('Value must be supplied for comparator queries'); | ||
if (_underscore["default"].isUndefined(queryAttribute.value) && !['isNull', 'isNotNull'].includes(queryAttribute.comparator)) throw new Error('Value must be supplied for comparator queries'); | ||
switch (queryAttribute.comparator) { | ||
@@ -46,2 +46,8 @@ case 'doesNotEqual': | ||
break; | ||
case 'isNull': | ||
if (!_underscore["default"].isNull(objectAttribute)) return false; | ||
break; | ||
case 'isNotNull': | ||
if (_underscore["default"].isNull(objectAttribute)) return false; | ||
break; | ||
default: | ||
@@ -48,0 +54,0 @@ throw new Error('Invalid comparator ' + queryAttribute.comparator); |
{ | ||
"name": "matches-where-query", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"main": "lib/matchesWhereQuery.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -12,2 +12,3 @@ # matchesWhereQuery( object, whereQuery ) | ||
<attribute> : [ <value1>, ..., <valueN> ] | ||
<attribute> : { comparator : <comparator> } | ||
<attribute> : { comparator : <comparator>, value : <value> } | ||
@@ -18,3 +19,3 @@ } | ||
# Comparisons | ||
For each clause in `whereQuery`, an attribute of `object` is compared to a value (primitive or object.) | ||
For each clause in `whereQuery`, an attribute of `object` is compared to a value (primitive or object.) except in the cases of the `isNull` and `isNotNull` comparators, which do not require for a value to be provided. | ||
@@ -109,1 +110,19 @@ ## equals (default) | ||
``` | ||
## isNull | ||
The compared attribute must be null to result in a match (no value needs to be provided). | ||
``` | ||
{ | ||
<attribute> : { comparator : 'isNull' } | ||
} | ||
``` | ||
## isNotNull | ||
The compared attribute must not be null to result in a match (no value needs to be provided). | ||
``` | ||
{ | ||
<attribute> : { comparator : 'isNotNull' } | ||
} | ||
``` |
@@ -14,3 +14,4 @@ var _ = require( 'underscore' ); | ||
height : 172, | ||
city : 'Buenos Aires' | ||
city : 'Buenos Aires', | ||
age : null | ||
}; | ||
@@ -209,2 +210,30 @@ } ); | ||
} ); | ||
describe( 'isNull', function() { | ||
it( 'Match', function() { | ||
var comparator = { age : { comparator : 'isNull' } }; | ||
expect( matchesWhereQuery( person, comparator ) ).to.be.true; | ||
} ); | ||
it( 'Not Match', function() { | ||
var comparator = { firstName : { comparator : 'isNull' } }; | ||
expect( matchesWhereQuery( person, comparator ) ).to.be.false; | ||
} ); | ||
} ); | ||
describe( 'isNotNull', function() { | ||
it( 'Match', function() { | ||
var comparator = { firstName : { comparator : 'isNotNull' } }; | ||
expect( matchesWhereQuery( person, comparator ) ).to.be.true; | ||
} ); | ||
it( 'Not Match', function() { | ||
var comparator = { age : { comparator : 'isNotNull' } }; | ||
expect( matchesWhereQuery( person, comparator ) ).to.be.false; | ||
} ); | ||
} ); | ||
} ); |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
17746
256
125
1