Code climate fixes, travis config, badge
This commit is contained in:
parent
9616a5b783
commit
a45271da5a
5 changed files with 26 additions and 9 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
node_modules
|
node_modules
|
||||||
|
coverage
|
||||||
|
|
16
.travis.yml
16
.travis.yml
|
@ -1,3 +1,19 @@
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- CC_TEST_REPORTER_ID=e1449b0f2e8eba8f08c56a292243145925aeb4f521e5682667ac6d704829ba4c
|
||||||
|
- GIT_COMMITTED_AT=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then git log -1 --pretty=format:%ct; else git log -1 --skip 1 --pretty=format:%ct; fi)
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- "7"
|
- "7"
|
||||||
|
before_script:
|
||||||
|
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
||||||
|
- chmod +x ./cc-test-reporter
|
||||||
|
script:
|
||||||
|
- npm run test
|
||||||
|
# Preferably you will run test-reporter on branch update events. But
|
||||||
|
# if you setup travis to build PR updates only, you don't need to run
|
||||||
|
# the line below
|
||||||
|
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi
|
||||||
|
# In the case where travis is setup to build PR updates only,
|
||||||
|
# uncomment the line below
|
||||||
|
# - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# json-query-chain
|
# json-query-chain
|
||||||
|
|
||||||
[](https://travis-ci.org/sharpshark28/json-query-chain) [](https://badge.fury.io/js/json-query-chain)
|
[](https://travis-ci.org/sharpshark28/json-query-chain) [](https://badge.fury.io/js/json-query-chain) [](https://codeclimate.com/github/sharpshark28/json-query-chain)
|
||||||
|
|
||||||
Chain queries onto POJOs to return precise results.
|
Chain queries onto POJOs to return precise results.
|
||||||
|
|
||||||
|
|
14
index.js
14
index.js
|
@ -4,21 +4,21 @@ module.exports = class Query {
|
||||||
item.sortScore = 0;
|
item.sortScore = 0;
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
get results () {
|
get results () {
|
||||||
return this.data;
|
return this.data;
|
||||||
};
|
}
|
||||||
|
|
||||||
filter (func) {
|
filter (func) {
|
||||||
this.data = this.data.filter(func);
|
this.data = this.data.filter(func);
|
||||||
return this;
|
return this;
|
||||||
};
|
}
|
||||||
|
|
||||||
filterBy (key, func) {
|
filterBy (key, func) {
|
||||||
this.data = this.data.filter(item => func(item[key]));
|
this.data = this.data.filter(item => func(item[key]));
|
||||||
return this;
|
return this;
|
||||||
};
|
}
|
||||||
|
|
||||||
search (key, term, score = 0) {
|
search (key, term, score = 0) {
|
||||||
switch (typeof term) {
|
switch (typeof term) {
|
||||||
|
@ -35,7 +35,7 @@ module.exports = class Query {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
}
|
||||||
|
|
||||||
sort (key = 'sortScore') {
|
sort (key = 'sortScore') {
|
||||||
this.data = this.data.sort((a, b) => {
|
this.data = this.data.sort((a, b) => {
|
||||||
|
@ -44,12 +44,12 @@ module.exports = class Query {
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
};
|
}
|
||||||
|
|
||||||
paginate (page = 1, perPage = 10) {
|
paginate (page = 1, perPage = 10) {
|
||||||
let min = page * perPage - perPage;
|
let min = page * perPage - perPage;
|
||||||
let max = min + perPage;
|
let max = min + perPage;
|
||||||
this.data = this.data.slice(min, max);
|
this.data = this.data.slice(min, max);
|
||||||
return this;
|
return this;
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"description": "Chain queries onto POJOs to return precise results.",
|
"description": "Chain queries onto POJOs to return precise results.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest"
|
"test": "jest --coverage"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
Loading…
Add table
Reference in a new issue