diff --git a/.gitignore b/.gitignore index 3c3629e..ba2a97b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +coverage diff --git a/.travis.yml b/.travis.yml index 0fe294a..e5383d5 100644 --- a/.travis.yml +++ b/.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 node_js: - "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 diff --git a/README.md b/README.md index 6a4d75a..7050b5a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # json-query-chain -[![Build Status](https://travis-ci.org/sharpshark28/json-query-chain.svg?branch=master)](https://travis-ci.org/sharpshark28/json-query-chain) [![npm version](https://badge.fury.io/js/json-query-chain.svg)](https://badge.fury.io/js/json-query-chain) +[![Build Status](https://travis-ci.org/sharpshark28/json-query-chain.svg?branch=master)](https://travis-ci.org/sharpshark28/json-query-chain) [![npm version](https://badge.fury.io/js/json-query-chain.svg)](https://badge.fury.io/js/json-query-chain) [![Code Climate](https://img.shields.io/codeclimate/github/sharpshark28/json-query-chain.svg)](https://codeclimate.com/github/sharpshark28/json-query-chain) Chain queries onto POJOs to return precise results. diff --git a/index.js b/index.js index fc10490..1f4f2a7 100644 --- a/index.js +++ b/index.js @@ -4,21 +4,21 @@ module.exports = class Query { item.sortScore = 0; return item; }); - }; + } get results () { return this.data; - }; + } filter (func) { this.data = this.data.filter(func); return this; - }; + } filterBy (key, func) { this.data = this.data.filter(item => func(item[key])); return this; - }; + } search (key, term, score = 0) { switch (typeof term) { @@ -35,7 +35,7 @@ module.exports = class Query { break; } return this; - }; + } sort (key = 'sortScore') { this.data = this.data.sort((a, b) => { @@ -44,12 +44,12 @@ module.exports = class Query { return 0; }); return this; - }; + } paginate (page = 1, perPage = 10) { let min = page * perPage - perPage; let max = min + perPage; this.data = this.data.slice(min, max); return this; - }; + } }; diff --git a/package.json b/package.json index 834ea27..f76bcf7 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Chain queries onto POJOs to return precise results.", "main": "index.js", "scripts": { - "test": "jest" + "test": "jest --coverage" }, "repository": { "type": "git",