Skip to content

Commit 4b9fbc3

Browse files
authored
Merge pull request Avocarrot#2 from gadget69/feat/not-equals
feat(operators) add not equals operator
2 parents 9971328 + 2895706 commit 4b9fbc3

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ A utility library which filters objects from an array of objects based on a set
6060

6161
```npm install filter-objects```
6262

63-
## Usage
63+
## Usage
6464

6565
1. Create a query object by using `query(arr)` where `arr` is the array of objects you want to query.
6666

6767
```javascript
6868
const q = query(arr)
6969
```
7070

71-
2. Finally get the result array using:
71+
2. Finally get the result array using:
7272

7373
```javascript
7474
q.every(filters); //returns an array of all objects in `arr` that satisfy EVERY filter
@@ -82,11 +82,11 @@ q.some(filters); //returns an array of all objects in `arr` that satisfy SOME of
8282

8383
`value` - The value of the property we will filter on
8484

85-
`operator` - The filter operator. Supported operators `equals`, `contains`, `gt`, `gte`, `lt`, `lte`
85+
`operator` - The filter operator. Supported operators `equals`, `contains`, `gt`, `gte`, `lt`, `lte`, `ne`
8686

8787
## Contributing
8888

89-
This project is work in progress and we'd love more people contributing to it.
89+
This project is work in progress and we'd love more people contributing to it.
9090

9191
1. Fork the repo
9292
2. Apply your changes

lib/operators.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const contains = (val1, val2) => {
66
};
77

88
const equals = (val1, val2) => val1 === val2;
9+
const ne = (val1, val2) => val1 !== val2;
910
const gt = (val1, val2) => val1 > val2;
1011
const gte = (val1, val2) => val1 >= val2;
1112
const lt = (val1, val2) => val1 < val2;
@@ -14,8 +15,9 @@ const lte = (val1, val2) => val1 <= val2;
1415
module.exports = {
1516
contains,
1617
equals,
18+
ne,
1719
gt,
18-
gte,
20+
gte,
1921
lt,
2022
lte
21-
};
23+
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "query-objects",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "A utility library which filters objects from an array of objects based on a set of filter conditions",
55
"main": "index.js",
66
"scripts": {

test/lib/operators.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const should = require('chai').Should();
22
const contains = require('../../lib/operators').contains;
33
const equals = require('../../lib/operators').equals;
4+
const ne = require('../../lib/operators').ne;
45
const gt = require('../../lib/operators').gt;
56
const gte = require('../../lib/operators').gte;
67
const lt = require('../../lib/operators').lt;
@@ -24,6 +25,11 @@ describe('Operators module tests', () => {
2425
equals(1, 10).should.be.false;
2526
});
2627

28+
it('ne(val1, val2) should return true `val1` not equals `val2` otherwise false', () => {
29+
ne(1, 1).should.be.false;
30+
ne(1, 10).should.be.true;
31+
});
32+
2733
it('gt(val1, val2) should return true `val1` is greater than `val2` otherwise false', () => {
2834
gt(10, 1).should.be.true;
2935
gt(1, 10).should.be.false;

0 commit comments

Comments
 (0)