query-string 4.3.1 → 5.0.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 (4) hide show
  1. package/index.js +11 -8
  2. package/license +4 -16
  3. package/package.json +2 -1
  4. package/readme.md +19 -1
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
  var strictUriEncode = require('strict-uri-encode');
3
3
  var objectAssign = require('object-assign');
4
+ var decodeComponent = require('decode-uri-component');
4
5
 
5
6
  function encoderForArrayFormat(opts) {
6
7
  switch (opts.arrayFormat) {
@@ -46,9 +47,9 @@ function parserForArrayFormat(opts) {
46
47
  switch (opts.arrayFormat) {
47
48
  case 'index':
48
49
  return function (key, value, accumulator) {
49
- result = /\[(\d*)]$/.exec(key);
50
+ result = /\[(\d*)\]$/.exec(key);
50
51
 
51
- key = key.replace(/\[\d*]$/, '');
52
+ key = key.replace(/\[\d*\]$/, '');
52
53
 
53
54
  if (!result) {
54
55
  accumulator[key] = value;
@@ -64,13 +65,15 @@ function parserForArrayFormat(opts) {
64
65
 
65
66
  case 'bracket':
66
67
  return function (key, value, accumulator) {
67
- result = /(\[])$/.exec(key);
68
+ result = /(\[\])$/.exec(key);
69
+ key = key.replace(/\[\]$/, '');
68
70
 
69
- key = key.replace(/\[]$/, '');
70
-
71
- if (!result || accumulator[key] === undefined) {
71
+ if (!result) {
72
72
  accumulator[key] = value;
73
73
  return;
74
+ } else if (accumulator[key] === undefined) {
75
+ accumulator[key] = [value];
76
+ return;
74
77
  }
75
78
 
76
79
  accumulator[key] = [].concat(accumulator[key], value);
@@ -142,9 +145,9 @@ exports.parse = function (str, opts) {
142
145
 
143
146
  // missing `=` should be `null`:
144
147
  // http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
145
- val = val === undefined ? null : decodeURIComponent(val);
148
+ val = val === undefined ? null : decodeComponent(val);
146
149
 
147
- formatter(decodeURIComponent(key), val, ret);
150
+ formatter(decodeComponent(key), val, ret);
148
151
  });
149
152
 
150
153
  return Object.keys(ret).sort().reduce(function (result, key) {
package/license CHANGED
@@ -1,21 +1,9 @@
1
- The MIT License (MIT)
1
+ MIT License
2
2
 
3
3
  Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11
6
 
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14
8
 
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "query-string",
3
- "version": "4.3.1",
3
+ "version": "5.0.0",
4
4
  "description": "Parse and stringify URL query strings",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/query-string",
@@ -34,6 +34,7 @@
34
34
  "decode"
35
35
  ],
36
36
  "dependencies": {
37
+ "decode-uri-component": "^0.2.0",
37
38
  "object-assign": "^4.1.0",
38
39
  "strict-uri-encode": "^1.0.0"
39
40
  },
package/readme.md CHANGED
@@ -12,7 +12,7 @@
12
12
  ## Install
13
13
 
14
14
  ```
15
- $ npm install --save query-string
15
+ $ npm install query-string
16
16
  ```
17
17
 
18
18
 
@@ -56,6 +56,8 @@ Parse a query string into an object. Leading `?` or `#` are ignored, so you can
56
56
 
57
57
  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`.
58
58
 
59
+ URI components are decoded with [`decode-uri-component`](https://github.com/SamVerschueren/decode-uri-component).
60
+
59
61
  #### arrayFormat
60
62
 
61
63
  Type: `string`<br>
@@ -163,6 +165,22 @@ queryString.stringify({color: ['taupe', 'chartreuse'], id: '515'});
163
165
  ```
164
166
 
165
167
 
168
+ ## Falsy values
169
+
170
+ Sometimes you want to unset a key, or maybe just make it present without assigning a value to it. Here is how falsy values are stringified:
171
+
172
+ ```js
173
+ queryString.stringify({foo: false});
174
+ //=> 'foo=false'
175
+
176
+ queryString.stringify({foo: null});
177
+ //=> 'foo'
178
+
179
+ queryString.stringify({foo: undefined});
180
+ //=> ''
181
+ ```
182
+
183
+
166
184
  ## License
167
185
 
168
186
  MIT © [Sindre Sorhus](https://sindresorhus.com)