extract = function (str) { return str.split('?')[1] || ''; }
...
- `none`: is the __default__ option and removes any bracket representation, such as:
```js
queryString.stringify({foo: [1,2,3]});
// => foo=1&foo=2&foo=3
```
### .extract(*string*)
Extract a query string from a URL that can be passed into `.parse()`.
## Nesting
This module intentionally doesn't support nesting as it's not spec'd and varies between implementations, which causes
a lot of [edge cases](https://github.com/visionmedia/node-querystring/issues).
...
parse = function (str, opts) { opts = objectAssign({arrayFormat: 'none'}, opts); var formatter = parserForArrayFormat(opts); // Create an object with no prototype // https://github.com/sindresorhus/query-string/issues/47 var ret = Object.create(null); if (typeof str !== 'string') { return ret; } str = str.trim().replace(/^(\?|#|&)/, ''); if (!str) { return ret; } str.split('&').forEach(function (param) { var parts = param.replace(/\+/g, ' ').split('='); // Firefox (pre 40) decodes `%3D` to `=` // https://github.com/sindresorhus/query-string/pull/37 var key = parts.shift(); var val = parts.length > 0 ? parts.join('=') : undefined; // missing `=` should be `null`: // http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters val = val === undefined ? null : decodeURIComponent(val); formatter(decodeURIComponent(key), val, ret); }); return Object.keys(ret).sort().reduce(function (result, key) { var val = ret[key]; if (Boolean(val) && typeof val === 'object' && !Array.isArray(val)) { // Sort object keys, not values result[key] = keysSorter(val); } else { result[key] = val; } return result; }, Object.create(null)); }
...
```js
const queryString = require('query-string');
console.log(location.search);
//=> '?foo=bar'
const parsed = queryString.parse(location.search);
console.log(parsed);
//=> {foo: 'bar'}
console.log(location.hash);
//=> '#token=bada55cafe'
const parsedHash = queryString.parse(location.hash);
...
stringify = function (obj, opts) { var defaults = { encode: true, strict: true, arrayFormat: 'none' }; opts = objectAssign(defaults, opts); var formatter = encoderForArrayFormat(opts); return obj ? Object.keys(obj).sort().map(function (key) { var val = obj[key]; if (val === undefined) { return ''; } if (val === null) { return encode(key, opts); } if (Array.isArray(val)) { var result = []; val.slice().forEach(function (val2) { if (val2 === undefined) { return; } result.push(formatter(key, val2, result.length)); }); return result.join('&'); } return encode(key, opts) + '=' + encode(val, opts); }).filter(function (x) { return x.length > 0; }).join('&') : ''; }
...
const parsedHash = queryString.parse(location.hash);
console.log(parsedHash);
//=> {token: 'bada55cafe'}
parsed.foo = 'unicorn';
parsed.ilike = 'pizza';
const stringified = queryString.stringify(parsed);
//=> 'foo=unicorn&ilike=pizza'
location.search = stringified;
// note that `location.search` automatically prepends a question mark
console.log(location.search);
//=> '?foo=unicorn&ilike=pizza'
```
...
extract = function (str) { return str.split('?')[1] || ''; }
...
- `none`: is the __default__ option and removes any bracket representation, such as:
```js
queryString.stringify({foo: [1,2,3]});
// => foo=1&foo=2&foo=3
```
### .extract(*string*)
Extract a query string from a URL that can be passed into `.parse()`.
## Nesting
This module intentionally doesn't support nesting as it's not spec'd and varies between implementations, which causes
a lot of [edge cases](https://github.com/visionmedia/node-querystring/issues).
...
parse = function (str, opts) { opts = objectAssign({arrayFormat: 'none'}, opts); var formatter = parserForArrayFormat(opts); // Create an object with no prototype // https://github.com/sindresorhus/query-string/issues/47 var ret = Object.create(null); if (typeof str !== 'string') { return ret; } str = str.trim().replace(/^(\?|#|&)/, ''); if (!str) { return ret; } str.split('&').forEach(function (param) { var parts = param.replace(/\+/g, ' ').split('='); // Firefox (pre 40) decodes `%3D` to `=` // https://github.com/sindresorhus/query-string/pull/37 var key = parts.shift(); var val = parts.length > 0 ? parts.join('=') : undefined; // missing `=` should be `null`: // http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters val = val === undefined ? null : decodeURIComponent(val); formatter(decodeURIComponent(key), val, ret); }); return Object.keys(ret).sort().reduce(function (result, key) { var val = ret[key]; if (Boolean(val) && typeof val === 'object' && !Array.isArray(val)) { // Sort object keys, not values result[key] = keysSorter(val); } else { result[key] = val; } return result; }, Object.create(null)); }
...
```js
const queryString = require('query-string');
console.log(location.search);
//=> '?foo=bar'
const parsed = queryString.parse(location.search);
console.log(parsed);
//=> {foo: 'bar'}
console.log(location.hash);
//=> '#token=bada55cafe'
const parsedHash = queryString.parse(location.hash);
...
stringify = function (obj, opts) { var defaults = { encode: true, strict: true, arrayFormat: 'none' }; opts = objectAssign(defaults, opts); var formatter = encoderForArrayFormat(opts); return obj ? Object.keys(obj).sort().map(function (key) { var val = obj[key]; if (val === undefined) { return ''; } if (val === null) { return encode(key, opts); } if (Array.isArray(val)) { var result = []; val.slice().forEach(function (val2) { if (val2 === undefined) { return; } result.push(formatter(key, val2, result.length)); }); return result.join('&'); } return encode(key, opts) + '=' + encode(val, opts); }).filter(function (x) { return x.length > 0; }).join('&') : ''; }
...
const parsedHash = queryString.parse(location.hash);
console.log(parsedHash);
//=> {token: 'bada55cafe'}
parsed.foo = 'unicorn';
parsed.ilike = 'pizza';
const stringified = queryString.stringify(parsed);
//=> 'foo=unicorn&ilike=pizza'
location.search = stringified;
// note that `location.search` automatically prepends a question mark
console.log(location.search);
//=> '?foo=unicorn&ilike=pizza'
```
...