From 9195b9af89d05ac7738400517a60ea84083f3d1f Mon Sep 17 00:00:00 2001 From: 3imed-jaberi Date: Wed, 6 May 2020 17:16:06 +0200 Subject: [PATCH 1/9] =?UTF-8?q?=20update=20.gitignore=20file=20?= =?UTF-8?q?=F0=9F=90=9E=20..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.gitignore b/.gitignore index ba2a97b..336c347 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,25 @@ +# OS # +################### +.DS_Store +.idea +Thumbs.db +tmp/ +temp/ + + +# Node.js # +################### node_modules +package-lock.json +yarn.lock +npm-debug.log +yarn-debug.log +yarn-error.log +dist + + +# NYC # +################### coverage +*.lcov +.nyc_output \ No newline at end of file From 8f7c5f1de0e1353baa221f52c3066bee60e2586b Mon Sep 17 00:00:00 2001 From: 3imed-jaberi Date: Wed, 6 May 2020 17:16:35 +0200 Subject: [PATCH 2/9] =?UTF-8?q?=20avoid=20generating=20pkg-lock.json=20?= =?UTF-8?q?=E2=98=94=EF=B8=8F=20..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .npmrc | 1 + 1 file changed, 1 insertion(+) create mode 100644 .npmrc diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..9cf9495 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false \ No newline at end of file From 1b86ba9697e4f769c82bfe578c6f072f6e33c53b Mon Sep 17 00:00:00 2001 From: 3imed-jaberi Date: Wed, 6 May 2020 17:18:59 +0200 Subject: [PATCH 3/9] =?UTF-8?q?=20add=20mocha=20config.=20=E2=98=95?= =?UTF-8?q?=EF=B8=8F=20..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .mocharc.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .mocharc.json diff --git a/.mocharc.json b/.mocharc.json new file mode 100644 index 0000000..aadfa57 --- /dev/null +++ b/.mocharc.json @@ -0,0 +1,8 @@ +{ + "extension": ["js"], + "require": "should", + "reporter": "spec", + "timeout": "2000", + "watch-files": ["test/**/*.js"], + "exit": "true" +} \ No newline at end of file From 974540f3b1f1069317fb5adab53141839d3acb63 Mon Sep 17 00:00:00 2001 From: 3imed-jaberi Date: Wed, 6 May 2020 17:19:48 +0200 Subject: [PATCH 4/9] =?UTF-8?q?=20fix=20test=20--pass=20=F0=9F=A7=AA?= =?UTF-8?q?=E2=9C=94=EF=B8=8F=20..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/{test.js => test.spec.js} | 52 +++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) rename test/{test.js => test.spec.js} (68%) diff --git a/test/test.js b/test/test.spec.js similarity index 68% rename from test/test.js rename to test/test.spec.js index 08203ae..68adbe7 100644 --- a/test/test.js +++ b/test/test.spec.js @@ -1,38 +1,38 @@ -var request = require('supertest') -var koa = require('koa') -var urllib = require('urllib') - -var qs = require('..') +const request = require('supertest') +const Koa = require('koa') +const urllib = require('urllib') +const convert = require('koa-convert') +const qs = require('..') describe('Koa Querystring', function () { it('should work with extended mode by default', function (done) { - var app = qs(koa()) + let app = qs(new Koa()) - app.use(function* (next) { + app.use(convert(function* (next) { try { yield* next } catch (err) { console.error(err.stack) } - }) + })) - app.use(function* () { + app.use(convert(function* () { this.query.should.eql({ - a: [1, 2, 3] + a: ['1', '2', '3'] }) this.query = { - a: [1, 2] + a: ['1', '2'] } this.query.should.eql({ - a: [1, 2] + a: ['1', '2'] }) this.querystring = 'a[0]=1&a[1]=2&a[2]=3' this.query.should.eql({ - a: [1, 2, 3] + a: ['1', '2', '3'] }) this.status = 204 - }) + })) request(app.listen()) .get('/?a[0]=1&a[1]=2&a[2]=3') @@ -40,22 +40,22 @@ describe('Koa Querystring', function () { }) describe('strict mode: array item', function () { - var app = qs(koa(), 'strict') + let app = qs(new Koa(), 'strict') - app.use(function* () { + app.use(convert(function* () { this.body = this.query; - }) + })) - var host + let host before(function (done) { app.listen(0, function () { - host = 'http://localhost:' + this.address().port + host = `http://localhost:${this.address().port}` done() }) }) it('should return the query params array', function (done) { - urllib.request(host + '/foo?p=a,b&p=b,c&empty=&empty=&empty=&n=1&n=2&n=1&ok=true', { + urllib.request(`${host}/foo?p=a,b&p=b,c&empty=&empty=&empty=&n=1&n=2&n=1&ok=true`, { dataType: 'json' }, function (err, body, res) { res.statusCode.should.equal(200) @@ -83,22 +83,22 @@ describe('Koa Querystring', function () { }) describe('first mode: first string item', function () { - var app = qs(koa(), 'first') + let app = qs(new Koa(), 'first') - app.use(function* () { + app.use(convert(function* () { this.body = this.query; - }) + })) - var host + let host before(function (done) { app.listen(0, function () { - host = 'http://localhost:' + this.address().port + host = `http://localhost:${this.address().port}` done() }) }) it('should return the first query params string', function (done) { - urllib.request(host + '/foo?p=a,b&p=b,c&empty=&empty=&empty=&n=1&n=2&n=1&ok=true', { + urllib.request(`${host}/foo?p=a,b&p=b,c&empty=&empty=&empty=&n=1&n=2&n=1&ok=true`, { dataType: 'json' }, function (err, body, res) { res.statusCode.should.equal(200) From 25c767e140e38ad539eee7447b5dc6d3261856bf Mon Sep 17 00:00:00 2001 From: 3imed-jaberi Date: Wed, 6 May 2020 17:21:11 +0200 Subject: [PATCH 5/9] =?UTF-8?q?=20better=20code=20=F0=9F=9A=80=20..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/index.js b/index.js index 9f98222..76e63bd 100644 --- a/index.js +++ b/index.js @@ -1,27 +1,14 @@ -var merge = require('merge-descriptors'); +const merge = require('merge-descriptors'); module.exports = function (app, mode) { mode = mode || 'extended'; - var qs = require('querystring'); - if (mode === 'extended') { - qs = require('qs'); - } - var converter = null; - if (mode === 'strict') { - converter = function (value) { - if (!Array.isArray(value)) { - return [value]; - } - return value; - }; - } else if (mode === 'first') { - converter = function (value) { - if (Array.isArray(value)) { - return value[0]; - } - return value; - }; - } + const qs = (mode === 'extended') ? require('qs') : require('querystring'); + + const converter = ( + mode === 'strict' && function (value) { return !Array.isArray(value) ? [value] : value } + || + mode === 'first' && function (value) { return Array.isArray(value) ? value[0] : value } + ); merge(app.request, { @@ -31,17 +18,16 @@ module.exports = function (app, mode) { * @return {Object} * @api public */ - get query() { - var str = this.querystring; + let str = this.querystring; if (!str) return {}; - var c = this._querycache = this._querycache || {}; - var query = c[str]; + let c = this._querycache = this._querycache || {}; + let query = c[str]; if (!query) { c[str] = query = qs.parse(str); if (converter) { - for (var key in query) { + for (let key in query) { query[key] = converter(query[key]); } } @@ -55,11 +41,10 @@ module.exports = function (app, mode) { * @param {Object} obj * @api public */ - set query(obj) { this.querystring = qs.stringify(obj); }, }); return app; -}; +}; \ No newline at end of file From 362b10529ad5983c7543c43274d27e02a8111e61 Mon Sep 17 00:00:00 2001 From: 3imed-jaberi Date: Wed, 6 May 2020 17:22:34 +0200 Subject: [PATCH 6/9] =?UTF-8?q?=20update=20the=20CI=20pipeline=20?= =?UTF-8?q?=F0=9F=8E=B2=20..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3388456..c316ece 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,11 @@ language: node_js node_js: - - 7 - 8 - - 9 - 10 + - 12 + - stable script: - - npm run test-travis + - npm run ci after_script: - npm install coveralls@2 - cat ./coverage/lcov.info | coveralls From 0b788e2b684ff995f98bd76cd3ee9b6f3696379d Mon Sep 17 00:00:00 2001 From: 3imed-jaberi Date: Wed, 6 May 2020 17:27:07 +0200 Subject: [PATCH 7/9] =?UTF-8?q?=20update=20README.md=20=F0=9F=93=8B=20..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f4bc99f..5de314b 100644 --- a/README.md +++ b/README.md @@ -16,22 +16,25 @@ [coveralls-url]: https://coveralls.io/r/koajs/qs?branch=master [david-image]: https://img.shields.io/david/koajs/qs.svg?style=flat-square [david-url]: https://david-dm.org/koajs/qs -[iojs-image]: https://img.shields.io/badge/io.js-%3E=_1.0-yellow.svg?style=flat-square -[iojs-url]: http://iojs.org/ -[node-image]: https://img.shields.io/badge/node.js-%3E=_0.11-green.svg?style=flat-square +[node-image]: https://img.shields.io/badge/node.js-%3E=_8-green.svg?style=flat-square [node-url]: http://nodejs.org/download/ [download-image]: https://img.shields.io/npm/dm/koa-qs.svg?style=flat-square [download-url]: https://npmjs.org/package/koa-qs By default, Koa uses the native `querystring` module which does not provide nesting support. -This patches a koa app with nesting support via the [qs] support, +This patches a koa app with nesting support via the [qs](https://github.com/ljharb/qs) support, which is also used by Connect and Express. Simply wrap a koa app with this module: ```js -var koa = require('koa') -var app = koa() +// Koa 1.x.x +const koa = require('koa') +const app = koa() +require('koa-qs')(app) +// Koa 2.x.x +const Koa = require('koa') +const app = new Koa() require('koa-qs')(app) ``` @@ -119,7 +122,4 @@ console.log('%j', this.query.p); ## License -[MIT](LICENSE) - - -[qs]: https://github.com/hapijs/qs +[MIT](LICENSE) \ No newline at end of file From 44a5fa6d0b1ca26218592ca44956b62616b736f2 Mon Sep 17 00:00:00 2001 From: 3imed-jaberi Date: Wed, 6 May 2020 17:28:20 +0200 Subject: [PATCH 8/9] =?UTF-8?q?=20update=20pkg.json=20=F0=9F=8E=97=20..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 62803c1..68ad442 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,9 @@ "name": "koa-qs", "description": "qs for koa", "version": "2.0.0", + "files": [ + "index.js" + ], "author": { "name": "Jonathan Ong", "email": "me@jongleberry.com", @@ -11,27 +14,27 @@ "license": "MIT", "repository": "koajs/qs", "dependencies": { - "merge-descriptors": "~0.0.2", - "qs": "~2.3.3" + "merge-descriptors": "^1.0.1", + "qs": "^6.9.4" }, "devDependencies": { - "istanbul-harmony": "*", - "koa": "0", - "mocha": "2", - "should": "3", - "supertest": "0", - "urllib": "2" + "koa": "^2.11.0", + "koa-convert": "^1.2.0", + "mocha": "^7.1.2", + "nyc": "^15.0.1", + "rimraf": "^3.0.2", + "should": "^13.2.3", + "supertest": "^4.0.2", + "urllib": "^2.34.2" }, "scripts": { - "test": "NODE_ENV=test mocha --harmony --require should --reporter spec", - "test-cov": "NODE_ENV=test node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --require should", - "test-travis": "NODE_ENV=test node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- --require should" + "test": "mocha", + "precoverage": "rimraf .nyc_output coverage", + "coverage": "nyc --reporter=lcov --reporter=text-lcov npm test", + "postcoverage":"nyc report", + "ci": "npm run coverage" }, "engines": { - "node": ">= 0.11", - "iojs": ">= 1.0.0" - }, - "files": [ - "index.js" - ] -} + "node": ">= 8" + } +} \ No newline at end of file From e22ef885414582867d54c38a670a1b9dbe9bb587 Mon Sep 17 00:00:00 2001 From: imed jaberi Date: Wed, 27 May 2020 03:58:39 +0200 Subject: [PATCH 9/9] =?UTF-8?q?update=20README.md=20--io=20=F0=9F=93=8B=20?= =?UTF-8?q?..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 5de314b..f89901b 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ [![build status][travis-image]][travis-url] [![Test coverage][coveralls-image]][coveralls-url] [![David deps][david-image]][david-url] -[![iojs version][iojs-image]][iojs-url] [![node version][node-image]][node-url] [![npm download][download-image]][download-url] @@ -122,4 +121,4 @@ console.log('%j', this.query.p); ## License -[MIT](LICENSE) \ No newline at end of file +[MIT](LICENSE)