Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
language: node_js
node_js:
- "0.10"
- "0.10"
- "0.12"
- "4"
- "5"
- "6"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 8 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -30,4 +28,4 @@ function decode (str, sep) {
module.exports = {
encode: encode,
decode: decode
};
};
25 changes: 14 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
5 changes: 4 additions & 1 deletion query-params.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -38,4 +41,4 @@ describe('query-params', function() {
expect(params.decode('a=1;b=2', ';')).toEqual({a: '1', b: '2'});
});

});
});