Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

query-string

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

query-string - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

11

package.json
{
"name": "query-string",
"version": "0.1.1",
"version": "0.2.0",
"description": "Parse and stringify URL query strings",

@@ -29,7 +29,4 @@ "keywords": [

],
"main": "query-string",
"repository": {
"type": "git",
"url": "git://github.com/sindresorhus/query-string.git"
},
"main": "query-string.js",
"repository": "sindresorhus/query-string",
"scripts": {

@@ -39,3 +36,3 @@ "test": "mocha"

"devDependencies": {
"mocha": "~1.14.0"
"mocha": "*"
},

@@ -42,0 +39,0 @@ "engines": {

@@ -25,5 +25,18 @@ /*!

var parts = param.replace(/\+/g, ' ').split('=');
var key = parts[0];
var val = parts[1];
key = decodeURIComponent(key);
// missing `=` should be `null`:
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
ret[parts[0]] = parts[1] === undefined ? null : decodeURIComponent(parts[1]);
val = val === undefined ? null : decodeURIComponent(val);
if (!ret.hasOwnProperty(key)) {
ret[key] = val;
} else if (Array.isArray(ret[key])) {
ret[key].push(val);
} else {
ret[key] = [ret[key], val];
}
return ret;

@@ -35,3 +48,11 @@ }, {});

return obj ? Object.keys(obj).map(function (key) {
return encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]);
var val = obj[key];
if (Array.isArray(val)) {
return val.map(function (val2) {
return encodeURIComponent(key) + '=' + encodeURIComponent(val2);
}).join('&');
}
return encodeURIComponent(key) + '=' + encodeURIComponent(val);
}).join('&') : '';

@@ -38,0 +59,0 @@ };

@@ -29,27 +29,5 @@ # query-string [![Build Status](https://secure.travis-ci.org/sindresorhus/query-string.png?branch=master)](http://travis-ci.org/sindresorhus/query-string)

## Examples
## Example
### Node.js
```js
var queryString = require('query-string');
var url = 'http://sindresorhus.com?foo=bar'.split('?');
var parsed = queryString.parse(url[1]);
console.log(parsed);
// {foo: 'bar'}
parsed.foo = 'unicorn';
parsed.ilike = 'pizza';
console.log(url[0] + '?' + queryString.stringify(parsed));
// http://sindresorhus.com?foo=unicorn&ilike=pizza
```
### Bower
```html
<script src="bower_components/query-string/query-string.js"></script>
```
```js
console.log(location.search);

@@ -82,4 +60,21 @@ // ?foo=bar

## Nesting
This module intentionally doesn't support nesting as it's not specced and varies between implementations, which causes a lot of [edge cases](https://github.com/visionmedia/node-querystring/issues).
You're much better off just converting the object to a JSON string:
```js
queryString.stringify({
foo: 'bar',
nested: JSON.stringify({
unicorn: 'cake'
})
});
// foo=bar&nested=%7B%22unicorn%22%3A%22cake%22%7D
```
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc