From eff92ba52a497fa8a8c6fd5767b0e3dfa2b32a18 Mon Sep 17 00:00:00 2001 From: Ed Moore Date: Thu, 12 May 2016 13:19:13 +0800 Subject: [PATCH 1/5] Updated dependencies --- package.json | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 10cc0b6..ce803e8 100644 --- a/package.json +++ b/package.json @@ -22,16 +22,19 @@ ], "license": "MIT", "devDependencies": { - "karma-script-launcher": "~0.1.0", - "karma-chrome-launcher": "~0.1.1", - "karma-html2js-preprocessor": "~0.1.0", - "karma-firefox-launcher": "~0.1.2", - "karma-jasmine": "~0.1.3", - "karma-coffee-preprocessor": "~0.1.1", - "requirejs": "~2.1.9", - "karma-requirejs": "~0.2.0", - "karma-phantomjs-launcher": "~0.1.1", - "karma": "~0.10.7", - "karma-browserify": "0.0.6" + "browserify": "^13.0.1", + "jasmine-core": "^2.4.1", + "karma": "~0.13.22", + "karma-browserify": "5.0.5", + "karma-chrome-launcher": "~1.0.1", + "karma-coffee-preprocessor": "~1.0.0", + "karma-firefox-launcher": "~1.0.0", + "karma-html2js-preprocessor": "~1.0.0", + "karma-jasmine": "~1.0.2", + "karma-phantomjs-launcher": "~1.0.0", + "karma-requirejs": "~1.0.0", + "karma-script-launcher": "~1.0.0", + "phantomjs-prebuilt": "^2.1.7", + "requirejs": "~2.2.0" } } From d7780c9eeb7561899dde97d44e4117b5d1af54d2 Mon Sep 17 00:00:00 2001 From: Ed Moore Date: Thu, 12 May 2016 13:19:46 +0800 Subject: [PATCH 2/5] Tests to ignore null, functions, and objects --- query-params.test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/query-params.test.js b/query-params.test.js index 66a48ff..fd09daf 100644 --- a/query-params.test.js +++ b/query-params.test.js @@ -10,6 +10,9 @@ describe('query-params', function() { expect(params.encode({a: 'æ'})).toEqual('a=%C3%A6'); expect(params.encode({a: 1})).toEqual('a=1'); expect(params.encode({a: URL})).toEqual('a=' + encodeURIComponent(URL)); + expect(params.encode({a: 'a', b: function () { return 1; }})).toEqual('a=a'); + expect(params.encode({a: 'a', b: null})).toEqual('a=a'); + expect(params.encode({a: 'a', b: { c: 'c' }})).toEqual('a=a'); }); it('should encode with custom separator', function () { @@ -38,4 +41,4 @@ describe('query-params', function() { expect(params.decode('a=1;b=2', ';')).toEqual({a: '1', b: '2'}); }); -}); \ No newline at end of file +}); From 82e4a882eeab174c8929220f3745d9f0ffed1cba Mon Sep 17 00:00:00 2001 From: Ed Moore Date: Thu, 12 May 2016 13:20:11 +0800 Subject: [PATCH 3/5] Updating encode to use a more functional approach --- index.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index f5b6518..67e1705 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,11 @@ function encode (o, sep) { - var list = []; - var key; - for (key in o) { - if (o[key] != null && typeof o[key] != 'object' && - typeof o[key] != 'function') { - list.push(encodeURIComponent(key) + '=' + encodeURIComponent(o[key])); - } - } - return list.join(sep || '&'); + return ( + Object.keys(o).filter(function (key) { + return o[key] != null && typeof o[key] != 'object' && typeof o[key] != 'function' + }) + .map(function (key) { return encodeURIComponent(key) + '=' + encodeURIComponent(o[key]); }) + .join(sep || '&') + ) } var REXP_SPLIT = /&|&|;/gmi; @@ -30,4 +28,4 @@ function decode (str, sep) { module.exports = { encode: encode, decode: decode -}; \ No newline at end of file +}; From f702c6a562ea8b9f831d73850f264ebf0724b114 Mon Sep 17 00:00:00 2001 From: Ed Moore Date: Thu, 12 May 2016 13:34:40 +0800 Subject: [PATCH 4/5] Adding more node versions to test against --- .travis.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 87f8cd9..180134b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,7 @@ language: node_js node_js: - - "0.10" \ No newline at end of file + - "0.10" + - "0.12" + - "4" + - "5" + - "6" From a49aed2a401322d2b39a83141d91eb2c98b2ef21 Mon Sep 17 00:00:00 2001 From: Ed Moore Date: Thu, 12 May 2016 13:34:52 +0800 Subject: [PATCH 5/5] Updating readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 49dbbab..b97bc58 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Very simple CommonJS-module to encode/decode query parameters [![Build Status](https://api.travis-ci.org/finn-no/query-params.png)](https://travis-ci.org/finn-no/query-params) [![NPM](https://nodei.co/npm/query-params.png?stars=true&downloads=true)](https://npmjs.org/package/query-params) -Convert object to query string or opposite. You need Browserify or similar to use this in a browser. It doesn't use ES5, so it should work in older browsers. +Convert object to query string or opposite. You need Browserify or similar to use this in a browser. Will work in IE9+ ## Installation