Comparing version 6.8.0 to 6.9.0
@@ -0,1 +1,9 @@ | ||
## **6.9.0** | ||
- [New] `parse`/`stringify`: Pass extra key/value argument to `decoder` (#333) | ||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `evalmd` | ||
- [Tests] `parse`: add passing `arrayFormat` tests | ||
- [Tests] add `posttest` using `npx aud` to run `npm audit` without a lockfile | ||
- [Tests] up to `node` `v12.10`, `v11.15`, `v10.16`, `v8.16` | ||
- [Tests] `Buffer.from` in node v5.0-v5.9 and v4.0-v4.4 requires a TypedArray | ||
## **6.8.0** | ||
@@ -2,0 +10,0 @@ - [New] add `depth=false` to preserve the original key; [Fix] `depth=0` should preserve the original key (#326) |
@@ -117,7 +117,7 @@ (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(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
if (pos === -1) { | ||
key = options.decoder(part, defaults.decoder, charset); | ||
key = options.decoder(part, defaults.decoder, charset, 'key'); | ||
val = options.strictNullHandling ? null : ''; | ||
} else { | ||
key = options.decoder(part.slice(0, pos), defaults.decoder, charset); | ||
val = options.decoder(part.slice(pos + 1), defaults.decoder, charset); | ||
key = options.decoder(part.slice(0, pos), defaults.decoder, charset, 'key'); | ||
val = options.decoder(part.slice(pos + 1), defaults.decoder, charset, 'value'); | ||
} | ||
@@ -296,10 +296,10 @@ | ||
var arrayPrefixGenerators = { | ||
brackets: function brackets(prefix) { // eslint-disable-line func-name-matching | ||
brackets: function brackets(prefix) { | ||
return prefix + '[]'; | ||
}, | ||
comma: 'comma', | ||
indices: function indices(prefix, key) { // eslint-disable-line func-name-matching | ||
indices: function indices(prefix, key) { | ||
return prefix + '[' + key + ']'; | ||
}, | ||
repeat: function repeat(prefix) { // eslint-disable-line func-name-matching | ||
repeat: function repeat(prefix) { | ||
return prefix; | ||
@@ -331,3 +331,3 @@ } | ||
indices: false, | ||
serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching | ||
serializeDate: function serializeDate(date) { | ||
return toISO.call(date); | ||
@@ -339,3 +339,3 @@ }, | ||
var isNonNullishPrimitive = function isNonNullishPrimitive(v) { // eslint-disable-line func-name-matching | ||
var isNonNullishPrimitive = function isNonNullishPrimitive(v) { | ||
return typeof v === 'string' | ||
@@ -345,6 +345,6 @@ || typeof v === 'number' | ||
|| typeof v === 'symbol' | ||
|| typeof v === 'bigint'; // eslint-disable-line valid-typeof | ||
|| typeof v === 'bigint'; | ||
}; | ||
var stringify = function stringify( // eslint-disable-line func-name-matching | ||
var stringify = function stringify( | ||
object, | ||
@@ -375,3 +375,3 @@ prefix, | ||
if (strictNullHandling) { | ||
return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset) : prefix; | ||
return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset, 'key') : prefix; | ||
} | ||
@@ -384,4 +384,4 @@ | ||
if (encoder) { | ||
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset); | ||
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset))]; | ||
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset, 'key'); | ||
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset, 'value'))]; | ||
} | ||
@@ -388,0 +388,0 @@ return [formatter(prefix) + '=' + formatter(String(obj))]; |
@@ -75,7 +75,7 @@ 'use strict'; | ||
if (pos === -1) { | ||
key = options.decoder(part, defaults.decoder, charset); | ||
key = options.decoder(part, defaults.decoder, charset, 'key'); | ||
val = options.strictNullHandling ? null : ''; | ||
} else { | ||
key = options.decoder(part.slice(0, pos), defaults.decoder, charset); | ||
val = options.decoder(part.slice(pos + 1), defaults.decoder, charset); | ||
key = options.decoder(part.slice(0, pos), defaults.decoder, charset, 'key'); | ||
val = options.decoder(part.slice(pos + 1), defaults.decoder, charset, 'value'); | ||
} | ||
@@ -82,0 +82,0 @@ |
@@ -8,10 +8,10 @@ 'use strict'; | ||
var arrayPrefixGenerators = { | ||
brackets: function brackets(prefix) { // eslint-disable-line func-name-matching | ||
brackets: function brackets(prefix) { | ||
return prefix + '[]'; | ||
}, | ||
comma: 'comma', | ||
indices: function indices(prefix, key) { // eslint-disable-line func-name-matching | ||
indices: function indices(prefix, key) { | ||
return prefix + '[' + key + ']'; | ||
}, | ||
repeat: function repeat(prefix) { // eslint-disable-line func-name-matching | ||
repeat: function repeat(prefix) { | ||
return prefix; | ||
@@ -43,3 +43,3 @@ } | ||
indices: false, | ||
serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching | ||
serializeDate: function serializeDate(date) { | ||
return toISO.call(date); | ||
@@ -51,3 +51,3 @@ }, | ||
var isNonNullishPrimitive = function isNonNullishPrimitive(v) { // eslint-disable-line func-name-matching | ||
var isNonNullishPrimitive = function isNonNullishPrimitive(v) { | ||
return typeof v === 'string' | ||
@@ -57,6 +57,6 @@ || typeof v === 'number' | ||
|| typeof v === 'symbol' | ||
|| typeof v === 'bigint'; // eslint-disable-line valid-typeof | ||
|| typeof v === 'bigint'; | ||
}; | ||
var stringify = function stringify( // eslint-disable-line func-name-matching | ||
var stringify = function stringify( | ||
object, | ||
@@ -87,3 +87,3 @@ prefix, | ||
if (strictNullHandling) { | ||
return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset) : prefix; | ||
return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset, 'key') : prefix; | ||
} | ||
@@ -96,4 +96,4 @@ | ||
if (encoder) { | ||
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset); | ||
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset))]; | ||
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset, 'key'); | ||
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset, 'value'))]; | ||
} | ||
@@ -100,0 +100,0 @@ return [formatter(prefix) + '=' + formatter(String(obj))]; |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/ljharb/qs", | ||
"version": "6.8.0", | ||
"version": "6.9.0", | ||
"repository": { | ||
@@ -32,8 +32,8 @@ "type": "git", | ||
"devDependencies": { | ||
"@ljharb/eslint-config": "^14.0.2", | ||
"@ljharb/eslint-config": "^14.1.0", | ||
"browserify": "^16.5.0", | ||
"covert": "^1.1.1", | ||
"eclint": "^2.8.1", | ||
"eslint": "^6.1.0", | ||
"evalmd": "^0.0.17", | ||
"eslint": "^6.4.0", | ||
"evalmd": "^0.0.19", | ||
"for-each": "^0.3.3", | ||
@@ -54,2 +54,3 @@ "has-symbols": "^1.0.0", | ||
"tests-only": "node test", | ||
"posttest": "npx aud", | ||
"readme": "evalmd README.md", | ||
@@ -56,0 +57,0 @@ "postlint": "eclint check * lib/* test/*", |
@@ -333,2 +333,26 @@ # qs <sup>[![Version Badge][2]][1]</sup> | ||
You can encode keys and values using different logic by using the type argument provided to the encoder: | ||
```javascript | ||
var encoded = qs.stringify({ a: { b: 'c' } }, { encoder: function (str, defaultEncoder, charset, type) { | ||
if (type === 'key') { | ||
return // Encoded key | ||
} else if (type === 'value') { | ||
return // Encoded value | ||
} | ||
}}) | ||
``` | ||
The type argument is also provided to the decoder: | ||
```javascript | ||
var decoded = qs.parse('x=z', { decoder: function (str, defaultEncoder, charset, type) { | ||
if (type === 'key') { | ||
return // Decoded key | ||
} else if (type === 'value') { | ||
return // Decoded value | ||
} | ||
}}) | ||
``` | ||
Examples beyond this point will be shown as though the output is not URI encoded for clarity. Please note that the return values in these cases *will* be URI encoded during real usage. | ||
@@ -335,0 +359,0 @@ |
@@ -35,2 +35,34 @@ 'use strict'; | ||
t.test('arrayFormat: brackets allows only explicit arrays', function (st) { | ||
st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'brackets' }), { a: ['b', 'c'] }); | ||
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'brackets' }), { a: ['b', 'c'] }); | ||
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'brackets' }), { a: 'b,c' }); | ||
st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'brackets' }), { a: ['b', 'c'] }); | ||
st.end(); | ||
}); | ||
t.test('arrayFormat: indices allows only indexed arrays', function (st) { | ||
st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'indices' }), { a: ['b', 'c'] }); | ||
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'indices' }), { a: ['b', 'c'] }); | ||
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'indices' }), { a: 'b,c' }); | ||
st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'indices' }), { a: ['b', 'c'] }); | ||
st.end(); | ||
}); | ||
t.test('arrayFormat: comma allows only comma-separated arrays', function (st) { | ||
st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'comma' }), { a: ['b', 'c'] }); | ||
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'comma' }), { a: ['b', 'c'] }); | ||
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'comma' }), { a: 'b,c' }); | ||
st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'comma' }), { a: ['b', 'c'] }); | ||
st.end(); | ||
}); | ||
t.test('arrayFormat: repeat allows only repeated values', function (st) { | ||
st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'repeat' }), { a: ['b', 'c'] }); | ||
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'repeat' }), { a: ['b', 'c'] }); | ||
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'repeat' }), { a: 'b,c' }); | ||
st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'repeat' }), { a: ['b', 'c'] }); | ||
st.end(); | ||
}); | ||
t.test('allows enabling dot notation', function (st) { | ||
@@ -633,3 +665,2 @@ st.deepEqual(qs.parse('a.b=c'), { 'a.b': 'c' }); | ||
t.test('prefers an iso-8859-1 charset specified by the utf8 sentinel to a default charset of utf-8', function (st) { | ||
// eslint-disable-next-line quote-props | ||
st.deepEqual(qs.parse('utf8=' + urlEncodedNumCheckmark + '&' + urlEncodedOSlashInUtf8 + '=' + urlEncodedOSlashInUtf8, { charsetSentinel: true, charset: 'utf-8' }), { 'ø': 'ø' }); | ||
@@ -655,3 +686,2 @@ st.end(); | ||
t.test('uses the utf8 sentinel to switch to iso-8859-1 when no default charset is given', function (st) { | ||
// eslint-disable-next-line quote-props | ||
st.deepEqual(qs.parse('utf8=' + urlEncodedNumCheckmark + '&' + urlEncodedOSlashInUtf8 + '=' + urlEncodedOSlashInUtf8, { charsetSentinel: true }), { 'ø': 'ø' }); | ||
@@ -692,3 +722,18 @@ st.end(); | ||
t.test('allows for decoding keys and values differently', function (st) { | ||
var decoder = function (str, defaultDecoder, charset, type) { | ||
if (type === 'key') { | ||
return defaultDecoder(str, defaultDecoder, charset, type).toLowerCase(); | ||
} | ||
if (type === 'value') { | ||
return defaultDecoder(str, defaultDecoder, charset, type).toUpperCase(); | ||
} | ||
throw 'this should never happen! type: ' + type; | ||
}; | ||
st.deepEqual(qs.parse('KeY=vAlUe', { decoder: decoder }), { key: 'VALUE' }); | ||
st.end(); | ||
}); | ||
t.end(); | ||
}); |
@@ -45,6 +45,6 @@ 'use strict'; | ||
t.test('stringifies bigints', { skip: !hasBigInt }, function (st) { | ||
var three = BigInt(3); // eslint-disable-line new-cap | ||
var three = BigInt(3); | ||
var encodeWithN = function (value, defaultEncoder, charset) { | ||
var result = defaultEncoder(value, defaultEncoder, charset); | ||
return typeof value === 'bigint' ? result + 'n' : result; // eslint-disable-line valid-typeof | ||
return typeof value === 'bigint' ? result + 'n' : result; | ||
}; | ||
@@ -723,3 +723,18 @@ st.equal(qs.stringify(three), ''); | ||
t.test('allows for encoding keys and values differently', function (st) { | ||
var encoder = function (str, defaultEncoder, charset, type) { | ||
if (type === 'key') { | ||
return defaultEncoder(str, defaultEncoder, charset, type).toLowerCase(); | ||
} | ||
if (type === 'value') { | ||
return defaultEncoder(str, defaultEncoder, charset, type).toUpperCase(); | ||
} | ||
throw 'this should never happen! type: ' + type; | ||
}; | ||
st.deepEqual(qs.stringify({ KeY: 'vAlUe' }, { encoder: encoder }), 'key=VALUE'); | ||
st.end(); | ||
}); | ||
t.end(); | ||
}); |
@@ -133,5 +133,5 @@ 'use strict'; | ||
var buffer = Buffer.from ? Buffer.from('abc') : new Buffer('abc'); | ||
var buffer = Buffer.from && Buffer.alloc ? Buffer.from('abc') : new Buffer('abc'); | ||
t.equal(utils.isBuffer(buffer), true, 'real Buffer instance is a buffer'); | ||
t.end(); | ||
}); |
Sorry, the diff of this file is not supported yet
152366
2723
599