qs 6.3.3 → 6.5.1

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.
package/.editorconfig CHANGED
@@ -7,14 +7,12 @@ end_of_line = lf
7
7
  charset = utf-8
8
8
  trim_trailing_whitespace = true
9
9
  insert_final_newline = true
10
- max_line_length = 160
11
- quote_type = single
10
+ max_line_length = 140
12
11
 
13
12
  [test/*]
14
13
  max_line_length = off
15
14
 
16
15
  [*.md]
17
- indent_size = off
18
16
  max_line_length = off
19
17
 
20
18
  [*.json]
@@ -30,15 +28,3 @@ indent_size = 2
30
28
  [LICENSE]
31
29
  indent_size = 2
32
30
  max_line_length = off
33
-
34
- [coverage/**/*]
35
- indent_size = off
36
- indent_style = off
37
- indent = off
38
- max_line_length = off
39
-
40
- [dist/*]
41
- max_line_length = off
42
-
43
- [.nycrc]
44
- indent_style = tab
package/.eslintignore ADDED
@@ -0,0 +1 @@
1
+ dist
package/.eslintrc CHANGED
@@ -3,35 +3,17 @@
3
3
 
4
4
  "extends": "@ljharb",
5
5
 
6
- "ignorePatterns": [
7
- "dist/",
8
- ],
9
-
10
6
  "rules": {
11
- "complexity": [2, 29],
7
+ "complexity": [2, 28],
12
8
  "consistent-return": 1,
13
- "func-name-matching": 0,
9
+ "func-name-matching": 0,
14
10
  "id-length": [2, { "min": 1, "max": 25, "properties": "never" }],
15
11
  "indent": [2, 4],
16
- "max-lines-per-function": 0,
17
12
  "max-params": [2, 12],
18
13
  "max-statements": [2, 45],
19
- "multiline-comment-style": 0,
20
14
  "no-continue": 1,
21
15
  "no-magic-numbers": 0,
22
- "no-param-reassign": 1,
23
16
  "no-restricted-syntax": [2, "BreakStatement", "DebuggerStatement", "ForInStatement", "LabeledStatement", "WithStatement"],
24
- },
25
-
26
- "overrides": [
27
- {
28
- "files": "test/**",
29
- "rules": {
30
- "max-lines-per-function": 0,
31
- "max-statements": 0,
32
- "no-extend-native": 0,
33
- "function-paren-newline": 0,
34
- },
35
- },
36
- ],
17
+ "operator-linebreak": [2, "before"],
18
+ }
37
19
  }
package/CHANGELOG.md CHANGED
@@ -1,22 +1,32 @@
1
- ## **6.3.3**
2
- - [Fix] `parse`: ignore `__proto__` keys (#428)
3
- - [Fix] fix for an impossible situation: when the formatter is called with a non-string value
4
- - [Fix] `utils.merge`: avoid a crash with a null target and an array source
5
- - [Fix]` `utils.merge`: avoid a crash with a null target and a truthy non-array source
6
- - [Fix] `stringify`: fix a crash with `strictNullHandling` and a custom `filter`/`serializeDate` (#279)
7
- - [Fix] `utils`: `merge`: fix crash when `source` is a truthy primitive & no options are provided
8
- - [Fix] when `parseArrays` is false, properly handle keys ending in `[]`
9
- - [Robustness] `stringify`: avoid relying on a global `undefined` (#427)
10
- - [Refactor] use cached `Array.isArray`
11
- - [Refactor] `stringify`: Avoid arr = arr.concat(...), push to the existing instance (#269)
12
- - [Docs] Clarify the need for "arrayLimit" option
13
- - [meta] fix README.md (#399)
14
- - [meta] Clean up license text so it’s properly detected as BSD-3-Clause
15
- - [meta] add FUNDING.yml
16
- - [actions] backport actions from main
17
- - [Tests] use `safer-buffer` instead of `Buffer` constructor
18
- - [Tests] remove nonexistent tape option
19
- - [Dev Deps] backport from main
1
+ ## **6.5.1**
2
+ - [Fix] Fix parsing & compacting very deep objects (#224)
3
+ - [Refactor] name utils functions
4
+ - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape`
5
+ - [Tests] up to `node` `v8.4`; use `nvm install-latest-npm` so newer npm doesn’t break older node
6
+ - [Tests] Use precise dist for Node.js 0.6 runtime (#225)
7
+ - [Tests] make 0.6 required, now that it’s passing
8
+ - [Tests] on `node` `v8.2`; fix npm on node 0.6
9
+
10
+ ## **6.5.0**
11
+ - [New] add `utils.assign`
12
+ - [New] pass default encoder/decoder to custom encoder/decoder functions (#206)
13
+ - [New] `parse`/`stringify`: add `ignoreQueryPrefix`/`addQueryPrefix` options, respectively (#213)
14
+ - [Fix] Handle stringifying empty objects with addQueryPrefix (#217)
15
+ - [Fix] do not mutate `options` argument (#207)
16
+ - [Refactor] `parse`: cache index to reuse in else statement (#182)
17
+ - [Docs] add various badges to readme (#208)
18
+ - [Dev Deps] update `eslint`, `browserify`, `iconv-lite`, `tape`
19
+ - [Tests] up to `node` `v8.1`, `v7.10`, `v6.11`; npm v4.6 breaks on node < v1; npm v5+ breaks on node < v4
20
+ - [Tests] add `editorconfig-tools`
21
+
22
+ ## **6.4.0**
23
+ - [New] `qs.stringify`: add `encodeValuesOnly` option
24
+ - [Fix] follow `allowPrototypes` option during merge (#201, #201)
25
+ - [Fix] support keys starting with brackets (#202, #200)
26
+ - [Fix] chmod a-x
27
+ - [Dev Deps] update `eslint`
28
+ - [Tests] up to `node` `v7.7`, `v6.10`,` v4.8`; disable osx builds since they block linux builds
29
+ - [eslint] reduce warnings
20
30
 
21
31
  ## **6.3.2**
22
32
  - [Fix] follow `allowPrototypes` option during merge (#201, #200)
@@ -51,6 +61,15 @@
51
61
  - [Tests] skip Object.create tests when null objects are not available
52
62
  - [Tests] Turn on eslint for test files (#175)
53
63
 
64
+ ## **6.2.3**
65
+ - [Fix] follow `allowPrototypes` option during merge (#201, #200)
66
+ - [Fix] chmod a-x
67
+ - [Fix] support keys starting with brackets (#202, #200)
68
+ - [Tests] up to `node` `v7.7`, `v6.10`,` v4.8`; disable osx builds since they block linux builds
69
+
70
+ ## **6.2.2**
71
+ - [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties
72
+
54
73
  ## **6.2.1**
55
74
  - [Fix] ensure `key[]=x&key[]&key[]=y` results in 3, not 2, values
56
75
  - [Refactor] Be explicit and use `Object.prototype.hasOwnProperty.call`
@@ -63,11 +82,30 @@
63
82
  - [New] add "encoder" and "decoder" options, for custom param encoding/decoding (#160)
64
83
  - [Fix] fix compacting of nested sparse arrays (#150)
65
84
 
85
+ ## **6.1.2
86
+ - [Fix] follow `allowPrototypes` option during merge (#201, #200)
87
+ - [Fix] chmod a-x
88
+ - [Fix] support keys starting with brackets (#202, #200)
89
+ - [Tests] up to `node` `v7.7`, `v6.10`,` v4.8`; disable osx builds since they block linux builds
90
+
91
+ ## **6.1.1**
92
+ - [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties
93
+
66
94
  ## [**6.1.0**](https://github.com/ljharb/qs/issues?milestone=35&state=closed)
67
95
  - [New] allowDots option for `stringify` (#151)
68
96
  - [Fix] "sort" option should work at a depth of 3 or more (#151)
69
97
  - [Fix] Restore `dist` directory; will be removed in v7 (#148)
70
98
 
99
+ ## **6.0.4**
100
+ - [Fix] follow `allowPrototypes` option during merge (#201, #200)
101
+ - [Fix] chmod a-x
102
+ - [Fix] support keys starting with brackets (#202, #200)
103
+ - [Tests] up to `node` `v7.7`, `v6.10`,` v4.8`; disable osx builds since they block linux builds
104
+
105
+ ## **6.0.3**
106
+ - [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties
107
+ - [Fix] Restore `dist` directory; will be removed in v7 (#148)
108
+
71
109
  ## [**6.0.2**](https://github.com/ljharb/qs/issues?milestone=33&state=closed)
72
110
  - Revert ES6 requirement and restore support for node down to v0.8.
73
111
 
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ Copyright (c) 2014 Nathan LaFreniere and other contributors.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * The names of any contributors may not be used to endorse or promote
12
+ products derived from this software without specific prior written
13
+ permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+
26
+ * * *
27
+
28
+ The complete list of contributors can be found at: https://github.com/hapijs/qs/graphs/contributors
package/README.md CHANGED
@@ -1,8 +1,14 @@
1
- # qs
1
+ # qs <sup>[![Version Badge][2]][1]</sup>
2
2
 
3
- A querystring parsing and stringifying library with some added security.
3
+ [![Build Status][3]][4]
4
+ [![dependency status][5]][6]
5
+ [![dev dependency status][7]][8]
6
+ [![License][license-image]][license-url]
7
+ [![Downloads][downloads-image]][downloads-url]
8
+
9
+ [![npm badge][11]][1]
4
10
 
5
- [![Build Status](https://api.travis-ci.org/ljharb/qs.svg)](http://travis-ci.org/ljharb/qs)
11
+ A querystring parsing and stringifying library with some added security.
6
12
 
7
13
  Lead Maintainer: [Jordan Harband](https://github.com/ljharb)
8
14
 
@@ -33,9 +39,9 @@ For example, the string `'foo[bar]=baz'` converts to:
33
39
 
34
40
  ```javascript
35
41
  assert.deepEqual(qs.parse('foo[bar]=baz'), {
36
- foo: {
37
- bar: 'baz'
38
- }
42
+ foo: {
43
+ bar: 'baz'
44
+ }
39
45
  });
40
46
  ```
41
47
 
@@ -57,7 +63,7 @@ URI encoded strings work too:
57
63
 
58
64
  ```javascript
59
65
  assert.deepEqual(qs.parse('a%5Bb%5D=c'), {
60
- a: { b: 'c' }
66
+ a: { b: 'c' }
61
67
  });
62
68
  ```
63
69
 
@@ -65,11 +71,11 @@ You can also nest your objects, like `'foo[bar][baz]=foobarbaz'`:
65
71
 
66
72
  ```javascript
67
73
  assert.deepEqual(qs.parse('foo[bar][baz]=foobarbaz'), {
68
- foo: {
69
- bar: {
70
- baz: 'foobarbaz'
74
+ foo: {
75
+ bar: {
76
+ baz: 'foobarbaz'
77
+ }
71
78
  }
72
- }
73
79
  });
74
80
  ```
75
81
 
@@ -78,19 +84,19 @@ By default, when nesting objects **qs** will only parse up to 5 children deep. T
78
84
 
79
85
  ```javascript
80
86
  var expected = {
81
- a: {
82
- b: {
83
- c: {
84
- d: {
85
- e: {
86
- f: {
87
- '[g][h][i]': 'j'
87
+ a: {
88
+ b: {
89
+ c: {
90
+ d: {
91
+ e: {
92
+ f: {
93
+ '[g][h][i]': 'j'
94
+ }
95
+ }
96
+ }
88
97
  }
89
- }
90
98
  }
91
- }
92
99
  }
93
- }
94
100
  };
95
101
  var string = 'a[b][c][d][e][f][g][h][i]=j';
96
102
  assert.deepEqual(qs.parse(string), expected);
@@ -112,6 +118,13 @@ var limited = qs.parse('a=b&c=d', { parameterLimit: 1 });
112
118
  assert.deepEqual(limited, { a: 'b' });
113
119
  ```
114
120
 
121
+ To bypass the leading question mark, use `ignoreQueryPrefix`:
122
+
123
+ ```javascript
124
+ var prefixed = qs.parse('?a=b&c=d', { ignoreQueryPrefix: true });
125
+ assert.deepEqual(prefixed, { a: 'b', c: 'd' });
126
+ ```
127
+
115
128
  An optional delimiter can also be passed:
116
129
 
117
130
  ```javascript
@@ -169,7 +182,7 @@ assert.deepEqual(withIndexedEmptyString, { a: ['b', '', 'c'] });
169
182
  ```
170
183
 
171
184
  **qs** will also limit specifying indices in an array to a maximum index of `20`. Any array members with an index of greater than `20` will
172
- instead be converted to an object with the index as the key. This is needed to handle cases when someone sent, for example, `a[999999999]` and it will take significant time to iterate over this huge array.
185
+ instead be converted to an object with the index as the key:
173
186
 
174
187
  ```javascript
175
188
  var withMaxIndex = qs.parse('a[100]=b');
@@ -225,12 +238,21 @@ var unencoded = qs.stringify({ a: { b: 'c' } }, { encode: false });
225
238
  assert.equal(unencoded, 'a[b]=c');
226
239
  ```
227
240
 
241
+ Encoding can be disabled for keys by setting the `encodeValuesOnly` option to `true`:
242
+ ```javascript
243
+ var encodedValues = qs.stringify(
244
+ { a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
245
+ { encodeValuesOnly: true }
246
+ );
247
+ assert.equal(encodedValues,'a=b&c[0]=d&c[1]=e%3Df&f[0][0]=g&f[1][0]=h');
248
+ ```
249
+
228
250
  This encoding can also be replaced by a custom encoding method set as `encoder` option:
229
251
 
230
252
  ```javascript
231
253
  var encoded = qs.stringify({ a: { b: 'c' } }, { encoder: function (str) {
232
- // Passed in values `a`, `b`, `c`
233
- return // Return encoded string
254
+ // Passed in values `a`, `b`, `c`
255
+ return // Return encoded string
234
256
  }})
235
257
  ```
236
258
 
@@ -240,32 +262,8 @@ Analogue to the `encoder` there is a `decoder` option for `parse` to override de
240
262
 
241
263
  ```javascript
242
264
  var decoded = qs.parse('x=z', { decoder: function (str) {
243
- // Passed in values `x`, `z`
244
- return // Return decoded string
245
- }})
246
- ```
247
-
248
- You can encode keys and values using different logic by using the type argument provided to the encoder:
249
-
250
- ```javascript
251
- var encoded = qs.stringify({ a: { b: 'c' } }, { encoder: function (str, defaultEncoder, charset, type) {
252
- if (type === 'key') {
253
- return // Encoded key
254
- } else if (type === 'value') {
255
- return // Encoded value
256
- }
257
- }})
258
- ```
259
-
260
- The type argument is also provided to the decoder:
261
-
262
- ```javascript
263
- var decoded = qs.parse('x=z', { decoder: function (str, defaultDecoder, charset, type) {
264
- if (type === 'key') {
265
- return // Decoded key
266
- } else if (type === 'value') {
267
- return // Decoded value
268
- }
265
+ // Passed in values `x`, `z`
266
+ return // Return decoded string
269
267
  }})
270
268
  ```
271
269
 
@@ -332,6 +330,12 @@ Properties that are set to `undefined` will be omitted entirely:
332
330
  assert.equal(qs.stringify({ a: null, b: undefined }), 'a=');
333
331
  ```
334
332
 
333
+ The query string may optionally be prepended with a question mark:
334
+
335
+ ```javascript
336
+ assert.equal(qs.stringify({ a: 'b', c: 'd' }, { addQueryPrefix: true }), '?a=b&c=d');
337
+ ```
338
+
335
339
  The delimiter may be overridden with stringify as well:
336
340
 
337
341
  ```javascript
@@ -353,7 +357,7 @@ You may use the `sort` option to affect the order of parameter keys:
353
357
 
354
358
  ```javascript
355
359
  function alphabeticalSort(a, b) {
356
- return a.localeCompare(b);
360
+ return a.localeCompare(b);
357
361
  }
358
362
  assert.equal(qs.stringify({ a: 'c', z: 'y', b : 'f' }, { sort: alphabeticalSort }), 'a=c&b=f&z=y');
359
363
  ```
@@ -364,17 +368,17 @@ pass an array, it will be used to select properties and array indices for string
364
368
 
365
369
  ```javascript
366
370
  function filterFunc(prefix, value) {
367
- if (prefix == 'b') {
368
- // Return an `undefined` value to omit a property.
369
- return;
370
- }
371
- if (prefix == 'e[f]') {
372
- return value.getTime();
373
- }
374
- if (prefix == 'e[g][0]') {
375
- return value * 2;
376
- }
377
- return value;
371
+ if (prefix == 'b') {
372
+ // Return an `undefined` value to omit a property.
373
+ return;
374
+ }
375
+ if (prefix == 'e[f]') {
376
+ return value.getTime();
377
+ }
378
+ if (prefix == 'e[g][0]') {
379
+ return value * 2;
380
+ }
381
+ return value;
378
382
  }
379
383
  qs.stringify({ a: 'b', c: 'd', e: { f: new Date(123), g: [2] } }, { filter: filterFunc });
380
384
  // 'a=b&c=d&e[f]=123&e[g][0]=4'
@@ -453,3 +457,19 @@ assert.equal(qs.stringify({ a: 'b c' }), 'a=b%20c');
453
457
  assert.equal(qs.stringify({ a: 'b c' }, { format : 'RFC3986' }), 'a=b%20c');
454
458
  assert.equal(qs.stringify({ a: 'b c' }, { format : 'RFC1738' }), 'a=b+c');
455
459
  ```
460
+
461
+ [1]: https://npmjs.org/package/qs
462
+ [2]: http://versionbadg.es/ljharb/qs.svg
463
+ [3]: https://api.travis-ci.org/ljharb/qs.svg
464
+ [4]: https://travis-ci.org/ljharb/qs
465
+ [5]: https://david-dm.org/ljharb/qs.svg
466
+ [6]: https://david-dm.org/ljharb/qs
467
+ [7]: https://david-dm.org/ljharb/qs/dev-status.svg
468
+ [8]: https://david-dm.org/ljharb/qs?type=dev
469
+ [9]: https://ci.testling.com/ljharb/qs.png
470
+ [10]: https://ci.testling.com/ljharb/qs
471
+ [11]: https://nodei.co/npm/qs.png?downloads=true&stars=true
472
+ [license-image]: http://img.shields.io/npm/l/qs.svg
473
+ [license-url]: LICENSE
474
+ [downloads-image]: http://img.shields.io/npm/dm/qs.svg
475
+ [downloads-url]: http://npm-stat.com/charts.html?package=qs