Skip to content

Commit f1ff27c

Browse files
committed
Added general parser feature.
1 parent 614753c commit f1ff27c

File tree

4 files changed

+39
-23
lines changed

4 files changed

+39
-23
lines changed

.travis.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
language: node_js
22
node_js:
3-
- "6.14"
4-
- "7.10"
5-
- "8.11"
6-
- "9.11"
7-
- "10.2"
8-
- "10.13"
9-
- "11.0"
3+
- "6"
4+
- "7"
5+
- "8"
6+
- "9"
7+
- "10"
8+
- "11"
9+
- "12"
1010
sudo: false
1111
cache:
1212
directories:
1313
- node_modules
1414
before_script:
15-
- npm install && npm install coveralls mocha-lcov-reporter --save-dev
15+
- npm install && npm install coveralls mocha-lcov-reporter --save-dev
1616
script:
17-
- npm run test:travis
17+
- npm test
18+
after_success:
19+
- nyc report --reporter=text-lcov | coveralls
1820
notifications:
1921
email:
2022
on_success: never
21-
on_failure: always
23+
on_failure: always

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ exports = module.exports = function (params) {
77
return read.parser(params)
88
}
99

10+
exports = module.exports.parser = function (query, defaults) {
11+
return read.parseAll(query, defaults)
12+
}
13+
1014
exports = module.exports.parseFields = function (_query, _default) {
1115
return read.parseFields(_query, _default)
1216
}
@@ -25,4 +29,4 @@ exports = module.exports.parseFilter = function (_query, _default) {
2529

2630
exports = module.exports.parseDate = function (_query, _default) {
2731
return read.parseDate(_query, _default)
28-
}
32+
}

lib/read.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ exports = module.exports.parser = function (params) {
4141
}
4242
}
4343

44+
4445
function validate_options(params) {
4546
const options = init_default()
4647
if (typeof params === 'object' && Object.keys(params).length > 0) {
@@ -64,6 +65,16 @@ function validate_options(params) {
6465
return options
6566
}
6667

68+
exports = module.exports.parseAll = function (_query, _default) {
69+
return {
70+
fields: this.parseFields(_query, _default),
71+
sort: this.parseSort(_query),
72+
filters: this.parseFilter(_query, _default),
73+
pagination: this.parsePagination(_query, _default, true),
74+
original: _query
75+
}
76+
}
77+
6778
exports = module.exports.parseFields = function (query, fields_default) {
6879
const options = validate_options({'default': {'fields': fields_default}})
6980
return fields.fields(stringToJson(query), options)
@@ -95,4 +106,4 @@ exports = module.exports.parseDate = function (query, date_fields) {
95106
function stringToJson(query) {
96107
if (typeof query === 'string') return url.parse(query, true).query
97108
return query
98-
}
109+
}

package.json

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
{
22
"name": "query-strings-parser",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"description": "Middleware to transform query strings in a format that is recognized by the MongoDB, MySQL and other databases...",
55
"license": "MIT",
66
"main": "index.js",
77
"scripts": {
8-
"test": "nyc --clean --all --reporter=text mocha --opts test/mocha.opts test/**/*.spec.js",
9-
"test:unit": "mocha --opts test/mocha.opts test/unit/*.spec.js",
10-
"test:integration": "mocha --opts test/mocha.opts test/integration/*.spec.js",
11-
"test:cov": "nyc --clean --all --reporter=html --reporter=text mocha --opts test/mocha.opts test/**/*.spec.js",
12-
"test:travis": "nyc mocha --opts test/mocha.opts test/**/*.spec.js && nyc report --reporter=text-lcov | coveralls"
8+
"test": "nyc --clean --all --reporter=text-summary mocha --opts test/mocha.opts test/**/*.spec.js",
9+
"test:unit": "nyc --clean --all --reporter=text-summary mocha --opts test/mocha.opts test/unit/*.spec.js",
10+
"test:integration": "nyc --clean --all --reporter=text-summary mocha --opts test/mocha.opts test/integration/*.spec.js",
11+
"test:cov": "nyc --clean --all --reporter=html --reporter=text mocha --opts test/mocha.opts test/**/*.spec.js"
1312
},
1413
"directories": {
1514
"lib": "lib",
@@ -39,14 +38,14 @@
3938
"string"
4039
],
4140
"engines": {
42-
"node": ">= 6.14"
41+
"node": ">=6"
4342
},
4443
"dependencies": {},
4544
"devDependencies": {
4645
"chai": "^4.2.0",
47-
"express": "^4.16.4",
48-
"mocha": "^5.2.0",
49-
"nyc": "^13.1.0",
50-
"supertest": "^3.4.2"
46+
"express": "^4.17.1",
47+
"mocha": "^6.2.0",
48+
"nyc": "^14.1.1",
49+
"supertest": "^4.0.2"
5150
}
5251
}

0 commit comments

Comments
 (0)