Comparing version 5.0.0 to 5.1.0
{ | ||
"name": "qs", | ||
"main": "dist/qs.js", | ||
"version": "4.0.0", | ||
"version": "5.1.0", | ||
"homepage": "https://github.com/hapijs/qs", | ||
@@ -6,0 +6,0 @@ "authors": [ |
## [**4.0.1**](https://github.com/hapijs/qs/issues?milestone=27&state=open) | ||
## [**5.1.0**](https://github.com/hapijs/qs/issues?milestone=29&state=open) | ||
- [**#117**](https://github.com/hapijs/qs/issues/117) make URI encoding stringified results optional | ||
- [**#106**](https://github.com/hapijs/qs/issues/106) Add flag `skipNulls` to optionally skip null values in stringify | ||
## [**5.0.0**](https://github.com/hapijs/qs/issues?milestone=28&state=closed) | ||
- [**#114**](https://github.com/hapijs/qs/issues/114) default allowDots to false | ||
- [**#100**](https://github.com/hapijs/qs/issues/100) include dist to npm | ||
@@ -4,0 +9,0 @@ |
@@ -33,3 +33,4 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Qs = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
plainObjects: false, | ||
allowPrototypes: false | ||
allowPrototypes: false, | ||
allowDots: false | ||
}; | ||
@@ -179,3 +180,3 @@ | ||
options.parseArrays = options.parseArrays !== false; | ||
options.allowDots = options.allowDots !== false; | ||
options.allowDots = typeof options.allowDots === 'boolean' ? options.allowDots : internals.allowDots; | ||
options.plainObjects = typeof options.plainObjects === 'boolean' ? options.plainObjects : internals.plainObjects; | ||
@@ -182,0 +183,0 @@ options.allowPrototypes = typeof options.allowPrototypes === 'boolean' ? options.allowPrototypes : internals.allowPrototypes; |
@@ -24,7 +24,9 @@ // Load modules | ||
}, | ||
strictNullHandling: false | ||
strictNullHandling: false, | ||
skipNulls: false, | ||
encode: true | ||
}; | ||
internals.stringify = function (obj, prefix, generateArrayPrefix, strictNullHandling, filter) { | ||
internals.stringify = function (obj, prefix, generateArrayPrefix, strictNullHandling, skipNulls, encode, filter) { | ||
@@ -42,3 +44,3 @@ if (typeof filter === 'function') { | ||
if (strictNullHandling) { | ||
return Utils.encode(prefix); | ||
return encode ? Utils.encode(prefix) : prefix; | ||
} | ||
@@ -53,3 +55,6 @@ | ||
return [Utils.encode(prefix) + '=' + Utils.encode(obj)]; | ||
if (encode) { | ||
return [Utils.encode(prefix) + '=' + Utils.encode(obj)]; | ||
} | ||
return [prefix + '=' + obj]; | ||
} | ||
@@ -67,7 +72,13 @@ | ||
if (skipNulls && | ||
obj[key] === null) { | ||
continue; | ||
} | ||
if (Array.isArray(obj)) { | ||
values = values.concat(internals.stringify(obj[key], generateArrayPrefix(prefix, key), generateArrayPrefix, strictNullHandling, filter)); | ||
values = values.concat(internals.stringify(obj[key], generateArrayPrefix(prefix, key), generateArrayPrefix, strictNullHandling, skipNulls, encode, filter)); | ||
} | ||
else { | ||
values = values.concat(internals.stringify(obj[key], prefix + '[' + key + ']', generateArrayPrefix, strictNullHandling, filter)); | ||
values = values.concat(internals.stringify(obj[key], prefix + '[' + key + ']', generateArrayPrefix, strictNullHandling, skipNulls, encode, filter)); | ||
} | ||
@@ -85,2 +96,4 @@ } | ||
var strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : internals.strictNullHandling; | ||
var skipNulls = typeof options.skipNulls === 'boolean' ? options.skipNulls : internals.skipNulls; | ||
var encode = typeof options.encode === 'boolean' ? options.encode : internals.encode; | ||
var objKeys; | ||
@@ -120,5 +133,13 @@ var filter; | ||
} | ||
for (var i = 0, il = objKeys.length; i < il; ++i) { | ||
var key = objKeys[i]; | ||
keys = keys.concat(internals.stringify(obj[key], key, generateArrayPrefix, strictNullHandling, filter)); | ||
if (skipNulls && | ||
obj[key] === null) { | ||
continue; | ||
} | ||
keys = keys.concat(internals.stringify(obj[key], key, generateArrayPrefix, strictNullHandling, skipNulls, encode, filter)); | ||
} | ||
@@ -125,0 +146,0 @@ |
{ | ||
"name": "qs", | ||
"version": "5.0.0", | ||
"description": "A querystring parser that supports nesting and arrays, with a depth limit", | ||
"homepage": "https://github.com/hapijs/qs", | ||
"version": "5.1.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/hapijs/qs.git" | ||
}, | ||
"main": "lib/index.js", | ||
"keywords": [ | ||
"querystring", | ||
"qs" | ||
], | ||
"engines": ">=0.10.40", | ||
"dependencies": {}, | ||
@@ -15,14 +24,7 @@ "devDependencies": { | ||
"test": "lab -a code -t 100 -L", | ||
"test-tap": "lab -a code -r tap -o tests.tap", | ||
"test-cov-html": "lab -a code -r html -o coverage.html", | ||
"dist": "browserify --standalone Qs lib/index.js > dist/qs.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/hapijs/qs.git" | ||
}, | ||
"keywords": [ | ||
"querystring", | ||
"qs" | ||
], | ||
"license": "BSD-3-Clause" | ||
} |
@@ -26,3 +26,3 @@ # qs | ||
**qs** allows you to create nested objects within your query strings, by surrounding the name of sub-keys with square brackets `[]`, or prefixing the sub-key with a dot `.`. | ||
**qs** allows you to create nested objects within your query strings, by surrounding the name of sub-keys with square brackets `[]`. | ||
For example, the string `'foo[bar]=baz'` converts to: | ||
@@ -122,7 +122,7 @@ | ||
Option `allowDots` can be used to disable dot notation: | ||
Option `allowDots` can be used to enable dot notation: | ||
```javascript | ||
Qs.parse('a.b=c', { allowDots: false }); | ||
// { 'a.b': 'c' } } | ||
Qs.parse('a.b=c', { allowDots: true }); | ||
// { a: { b: 'c' } } | ||
``` | ||
@@ -320,1 +320,8 @@ | ||
``` | ||
To completely skip rendering keys with `null` values, use the `skipNulls` flag: | ||
```javascript | ||
qs.stringify({ a: 'b', c: null}, { skipNulls: true }) | ||
// 'a=b' | ||
``` |
@@ -50,2 +50,15 @@ /* eslint no-extend-native:0 */ | ||
it('omits nulls when asked', function (done) { | ||
expect(Qs.stringify({ a: 'b', c: null }, { skipNulls: true })).to.equal('a=b'); | ||
done(); | ||
}); | ||
it('omits nested nulls when asked', function (done) { | ||
expect(Qs.stringify({ a: { b: 'c', d: null } }, { skipNulls: true })).to.equal('a%5Bb%5D=c'); | ||
done(); | ||
}); | ||
it('omits array indices when asked', function (done) { | ||
@@ -261,2 +274,10 @@ | ||
}); | ||
it('can disable uri encoding', function (done) { | ||
expect(Qs.stringify({ a: 'b' }, { encode: false })).to.equal('a=b'); | ||
expect(Qs.stringify({ a: { b: 'c' } }, { encode: false })).to.equal('a[b]=c'); | ||
expect(Qs.stringify({ a: 'b', c: null }, { strictNullHandling: true, encode: false })).to.equal('a=b&c'); | ||
done(); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
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
72948
18
1391
325