Skip to content

Commit 740af9b

Browse files
authored
refactor(api) Changes exposed function names for clarity (Avocarrot#3)
1 parent 4b9fbc3 commit 740af9b

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
A utility library which filters objects from an array of objects based on a set of filter conditions.
88

99
```javascript
10-
const query = require('query-objects');
10+
const queryable = require('query-objects');
1111

1212
const users = [
1313
{
@@ -41,10 +41,10 @@ A utility library which filters objects from an array of objects based on a set
4141
];
4242

4343
// Filter all users that are less than 30 years old AND their first name is Erica
44-
const res = query(users).every(filters);
44+
const res = queryable(users).and(filters);
4545

4646
// Filter all users that are less than 30 years old OR their first name is Erica
47-
const res = query(users).some(filters);
47+
const res = queryable(users).or(filters);
4848

4949
```
5050

@@ -62,18 +62,18 @@ A utility library which filters objects from an array of objects based on a set
6262

6363
## Usage
6464

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

6767
```javascript
68-
const q = query(arr)
68+
const q = queryable(arr);
6969
```
7070

7171
2. Finally get the result array using:
7272

7373
```javascript
74-
q.every(filters); //returns an array of all objects in `arr` that satisfy EVERY filter
74+
q.and(filters); //returns an array of all objects in `arr` that satisfy EVERY filter
7575

76-
q.some(filters); //returns an array of all objects in `arr` that satisfy SOME of the filters
76+
q.or(filters); //returns an array of all objects in `arr` that satisfy SOME of the filters
7777
```
7878

7979
## Filters

lib/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = (arr) => {
55
throw new Error('`arr` must be an array of objects');
66
}
77
return {
8-
every: filters => filterArr(arr, filters, 'every'),
9-
some: filters => filterArr(arr, filters, 'some'),
8+
and: filters => filterArr(arr, filters, 'every'),
9+
or: filters => filterArr(arr, filters, 'some'),
1010
};
11-
}
11+
};

test/lib/index.spec.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const should = require('chai').Should();
2-
const query = require('../../lib');
2+
const queryable = require('../../lib');
33

44
describe('Module Tests', () => {
55

@@ -26,26 +26,26 @@ describe('Module Tests', () => {
2626
}
2727
];
2828

29-
it('query(arr) should return a query object', () => {
30-
query([]).should.have.property('every');
31-
query([]).should.have.property('some');
29+
it('queryable(arr) should return a queryable object', () => {
30+
queryable([]).should.have.property('and');
31+
queryable([]).should.have.property('or');
3232
});
3333

3434
it('throw an error if `arr` is not an array', () => {
3535
(() => {
36-
query();
36+
queryable();
3737
}).should.throw('`arr` must be an array of objects');
3838

3939
(() => {
40-
query('this is a string');
40+
queryable('this is a string');
4141
}).should.throw('`arr` must be an array of objects');
4242

4343
(() => {
44-
query(1234);
44+
queryable(1234);
4545
}).should.throw('`arr` must be an array of objects');
4646
});
4747

48-
it('query(arr).every(filters) should return all results that satisfy all filters', () => {
48+
it('queryable(arr).and(filters) should return all results that satisfy all filters', () => {
4949
const filters = [
5050
{
5151
field: 'name',
@@ -59,10 +59,10 @@ describe('Module Tests', () => {
5959
}
6060
];
6161
const expected = [people[0]];
62-
query(people).every(filters).should.eql(expected);
62+
queryable(people).and(filters).should.eql(expected);
6363
});
6464

65-
it('query(arr).some(filters) should return all results that satisfy at least one of the filters', () => {
65+
it('queryable(arr).or(filters) should return all results that satisfy at least one of the filters', () => {
6666
const filters = [
6767
{
6868
field: 'name',
@@ -76,7 +76,7 @@ describe('Module Tests', () => {
7676
}
7777
];
7878
const expected = [people[0], people[1], people[2]];
79-
query(people).some(filters).should.eql(expected);
79+
queryable(people).or(filters).should.eql(expected);
8080
});
8181

8282
});

0 commit comments

Comments
 (0)