query-string
Advanced tools
Comparing version 5.0.1 to 5.1.0
13
index.js
@@ -179,5 +179,9 @@ 'use strict'; | ||
if (opts.sort === false) { | ||
opts.sort = function () {}; | ||
} | ||
var formatter = encoderForArrayFormat(opts); | ||
return obj ? Object.keys(obj).sort().map(function (key) { | ||
return obj ? Object.keys(obj).sort(opts.sort).map(function (key) { | ||
var val = obj[key]; | ||
@@ -212,1 +216,8 @@ | ||
}; | ||
exports.parseUrl = function (str, opts) { | ||
return { | ||
url: str.split('?')[0] || '', | ||
query: this.parse(this.extract(str), opts) | ||
}; | ||
}; |
{ | ||
"name": "query-string", | ||
"version": "5.0.1", | ||
"description": "Parse and stringify URL query strings", | ||
"license": "MIT", | ||
"repository": "sindresorhus/query-string", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"browser", | ||
"querystring", | ||
"query", | ||
"string", | ||
"qs", | ||
"param", | ||
"parameter", | ||
"url", | ||
"uri", | ||
"parse", | ||
"stringify", | ||
"encode", | ||
"decode" | ||
], | ||
"dependencies": { | ||
"decode-uri-component": "^0.2.0", | ||
"object-assign": "^4.1.0", | ||
"strict-uri-encode": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.17.0", | ||
"xo": "^0.16.0" | ||
} | ||
"name": "query-string", | ||
"version": "5.1.0", | ||
"description": "Parse and stringify URL query strings", | ||
"license": "MIT", | ||
"repository": "sindresorhus/query-string", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"browser", | ||
"querystring", | ||
"query", | ||
"string", | ||
"qs", | ||
"param", | ||
"parameter", | ||
"url", | ||
"uri", | ||
"parse", | ||
"stringify", | ||
"encode", | ||
"decode" | ||
], | ||
"dependencies": { | ||
"decode-uri-component": "^0.2.0", | ||
"object-assign": "^4.1.0", | ||
"strict-uri-encode": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.17.0", | ||
"xo": "^0.16.0" | ||
} | ||
} |
# query-string [![Build Status](https://travis-ci.org/sindresorhus/query-string.svg?branch=master)](https://travis-ci.org/sindresorhus/query-string) | ||
> Parse and stringify URL [query strings](http://en.wikipedia.org/wiki/Query_string) | ||
> Parse and stringify URL [query strings](https://en.wikipedia.org/wiki/Query_string) | ||
--- | ||
<p align="center"><b>🔥 Want to strengthen your core JavaScript skills and master ES6?</b><br>I would personally recommend this awesome <a href="https://ES6.io/friend/AWESOME">ES6 course</a> by Wes Bos. You might also like his <a href="https://ReactForBeginners.com/friend/AWESOME">React course</a>.</p> | ||
<p align="center"><b>🔥 Want to strengthen your core JavaScript skills and master ES6?</b><br>I would personally recommend this awesome <a href="https://ES6.io/friend/AWESOME">ES6 course</a> by Wes Bos.<br>Also check out his <a href="https://LearnNode.com/friend/AWESOME">Node.js</a>, <a href="https://ReactForBeginners.com/friend/AWESOME">React</a>, <a href="https://SublimeTextBook.com/friend/AWESOME">Sublime</a> courses.</p> | ||
@@ -18,3 +18,7 @@ --- | ||
<a href="https://www.patreon.com/sindresorhus"> | ||
<img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" width="160"> | ||
</a> | ||
## Usage | ||
@@ -137,2 +141,23 @@ | ||
#### sort | ||
Type: `Function` `boolean` | ||
Supports both `Function` as a custom sorting function or `false` to disable sorting. | ||
```js | ||
const order = ['c', 'a', 'b']; | ||
queryString.stringify({ a: 1, b: 2, c: 3}, { | ||
sort: (m, n) => order.indexOf(m) >= order.indexOf(n) | ||
}); | ||
// => 'c=3&a=1&b=2' | ||
``` | ||
```js | ||
queryString.stringify({ b: 1, c: 2, a: 3}, {sort: false}); | ||
// => 'c=3&a=1&b=2' | ||
``` | ||
If omitted, keys are sorted using `Array#sort`, which means, converting them to strings and comparing strings in Unicode code point order. | ||
### .extract(*string*) | ||
@@ -142,3 +167,16 @@ | ||
### .parseUrl(*string*, *[options]*) | ||
Extract the URL and the query string as an object. | ||
The `options` are the same as for `.parse()`. | ||
Returns an object with a `url` and `query` property. | ||
```js | ||
queryString.parseUrl('https://foo.bar?foo=bar'); | ||
//=> {url: 'https://foo.bar', query: {foo: 'bar'}} | ||
``` | ||
## Nesting | ||
@@ -145,0 +183,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12649
178
225