query-string 6.0.0 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +12 -4
  2. package/package.json +44 -42
  3. package/readme.md +7 -2
package/index.js CHANGED
@@ -21,7 +21,7 @@ function encoderForArrayFormat(options) {
21
21
  };
22
22
  case 'bracket':
23
23
  return (key, value) => {
24
- return value === null ? encode(key, options) : [
24
+ return value === null ? [encode(key, options), '[]'].join('') : [
25
25
  encode(key, options),
26
26
  '[]=',
27
27
  encode(value, options)
@@ -96,6 +96,14 @@ function encode(value, options) {
96
96
  return value;
97
97
  }
98
98
 
99
+ function decode(value, options) {
100
+ if (options.decode) {
101
+ return decodeComponent(value);
102
+ }
103
+
104
+ return value;
105
+ }
106
+
99
107
  function keysSorter(input) {
100
108
  if (Array.isArray(input)) {
101
109
  return input.sort();
@@ -119,7 +127,7 @@ function extract(input) {
119
127
  }
120
128
 
121
129
  function parse(input, options) {
122
- options = Object.assign({arrayFormat: 'none'}, options);
130
+ options = Object.assign({decode: true, arrayFormat: 'none'}, options);
123
131
 
124
132
  const formatter = parserForArrayFormat(options);
125
133
 
@@ -141,9 +149,9 @@ function parse(input, options) {
141
149
 
142
150
  // Missing `=` should be `null`:
143
151
  // http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
144
- value = value === undefined ? null : decodeComponent(value);
152
+ value = value === undefined ? null : decode(value, options);
145
153
 
146
- formatter(decodeComponent(key), value, ret);
154
+ formatter(decode(key, options), value, ret);
147
155
  }
148
156
 
149
157
  return Object.keys(ret).sort().reduce((result, key) => {
package/package.json CHANGED
@@ -1,44 +1,46 @@
1
1
  {
2
- "name": "query-string",
3
- "version": "6.0.0",
4
- "description": "Parse and stringify URL query strings",
5
- "license": "MIT",
6
- "repository": "sindresorhus/query-string",
7
- "author": {
8
- "name": "Sindre Sorhus",
9
- "email": "sindresorhus@gmail.com",
10
- "url": "sindresorhus.com"
11
- },
12
- "engines": {
13
- "node": ">=6"
14
- },
15
- "scripts": {
16
- "test": "xo && ava"
17
- },
18
- "files": [
19
- "index.js"
20
- ],
21
- "keywords": [
22
- "browser",
23
- "querystring",
24
- "query",
25
- "string",
26
- "qs",
27
- "param",
28
- "parameter",
29
- "url",
30
- "parse",
31
- "stringify",
32
- "encode",
33
- "decode",
34
- "searchparams"
35
- ],
36
- "dependencies": {
37
- "decode-uri-component": "^0.2.0",
38
- "strict-uri-encode": "^2.0.0"
39
- },
40
- "devDependencies": {
41
- "ava": "*",
42
- "xo": "*"
43
- }
2
+ "name": "query-string",
3
+ "version": "6.1.0",
4
+ "description": "Parse and stringify URL query strings",
5
+ "license": "MIT",
6
+ "repository": "sindresorhus/query-string",
7
+ "author": {
8
+ "name": "Sindre Sorhus",
9
+ "email": "sindresorhus@gmail.com",
10
+ "url": "sindresorhus.com"
11
+ },
12
+ "engines": {
13
+ "node": ">=6"
14
+ },
15
+ "scripts": {
16
+ "test": "xo && ava"
17
+ },
18
+ "files": [
19
+ "index.js"
20
+ ],
21
+ "keywords": [
22
+ "browser",
23
+ "querystring",
24
+ "query",
25
+ "string",
26
+ "qs",
27
+ "param",
28
+ "parameter",
29
+ "url",
30
+ "parse",
31
+ "stringify",
32
+ "encode",
33
+ "decode",
34
+ "searchparams"
35
+ ],
36
+ "dependencies": {
37
+ "decode-uri-component": "^0.2.0",
38
+ "strict-uri-encode": "^2.0.0"
39
+ },
40
+ "devDependencies": {
41
+ "ava": "*",
42
+ "deep-equal": "^1.0.1",
43
+ "fast-check": "^1.0.1",
44
+ "xo": "*"
45
+ }
44
46
  }
package/readme.md CHANGED
@@ -15,7 +15,7 @@
15
15
  $ npm install query-string
16
16
  ```
17
17
 
18
- The latest version targets Node.js 6 or later and modern browsers. If you want support for older browsers, use version 5: `npm install query-string@5`.
18
+ This module targets Node.js 6 or later and the latest version of Chrome, Firefox, and Safari. If you want support for older browsers, use version 5: `npm install query-string@5`.
19
19
 
20
20
  <a href="https://www.patreon.com/sindresorhus">
21
21
  <img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" width="160">
@@ -62,7 +62,12 @@ Parse a query string into an object. Leading `?` or `#` are ignored, so you can
62
62
 
63
63
  The returned object is created with [`Object.create(null)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create) and thus does not have a `prototype`.
64
64
 
65
- URI components are decoded with [`decode-uri-component`](https://github.com/SamVerschueren/decode-uri-component).
65
+ #### decode
66
+
67
+ Type: `boolean`<br>
68
+ Default: `true`
69
+
70
+ Decode the keys and values. URI components are decoded with [`decode-uri-component`](https://github.com/SamVerschueren/decode-uri-component).
66
71
 
67
72
  #### arrayFormat
68
73