Comparing version 6.4.0 to 6.5.0
@@ -0,1 +1,13 @@ | ||
## **6.5.0** | ||
- [New] add `utils.assign` | ||
- [New] pass default encoder/decoder to custom encoder/decoder functions (#206) | ||
- [New] `parse`/`stringify`: add `ignoreQueryPrefix`/`addQueryPrefix` options, respectively (#213) | ||
- [Fix] Handle stringifying empty objects with addQueryPrefix (#217) | ||
- [Fix] do not mutate `options` argument (#207) | ||
- [Refactor] `parse`: cache index to reuse in else statement (#182) | ||
- [Docs] add various badges to readme (#208) | ||
- [Dev Deps] update `eslint`, `browserify`, `iconv-lite`, `tape` | ||
- [Tests] up to `node` `v8.1`, `v7.10`, `v6.11`; npm v4.6 breaks on node < v1; npm v5+ breaks on node < v4 | ||
- [Tests] add `editorconfig-tools` | ||
## **6.4.0** | ||
@@ -10,2 +22,9 @@ - [New] `qs.stringify`: add `encodeValuesOnly` option | ||
## **6.3.2** | ||
- [Fix] follow `allowPrototypes` option during merge (#201, #200) | ||
- [Dev Deps] update `eslint` | ||
- [Fix] chmod a-x | ||
- [Fix] support keys starting with brackets (#202, #200) | ||
- [Tests] up to `node` `v7.7`, `v6.10`,` v4.8`; disable osx builds since they block linux builds | ||
## **6.3.1** | ||
@@ -37,2 +56,8 @@ - [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties (thanks, @snyk!) | ||
## **6.2.3** | ||
- [Fix] follow `allowPrototypes` option during merge (#201, #200) | ||
- [Fix] chmod a-x | ||
- [Fix] support keys starting with brackets (#202, #200) | ||
- [Tests] up to `node` `v7.7`, `v6.10`,` v4.8`; disable osx builds since they block linux builds | ||
## **6.2.2** | ||
@@ -53,2 +78,8 @@ - [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties | ||
## **6.1.2 | ||
- [Fix] follow `allowPrototypes` option during merge (#201, #200) | ||
- [Fix] chmod a-x | ||
- [Fix] support keys starting with brackets (#202, #200) | ||
- [Tests] up to `node` `v7.7`, `v6.10`,` v4.8`; disable osx builds since they block linux builds | ||
## **6.1.1** | ||
@@ -62,2 +93,8 @@ - [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties | ||
## **6.0.4** | ||
- [Fix] follow `allowPrototypes` option during merge (#201, #200) | ||
- [Fix] chmod a-x | ||
- [Fix] support keys starting with brackets (#202, #200) | ||
- [Tests] up to `node` `v7.7`, `v6.10`,` v4.8`; disable osx builds since they block linux builds | ||
## **6.0.3** | ||
@@ -64,0 +101,0 @@ - [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties |
@@ -55,15 +55,19 @@ (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){ | ||
var obj = {}; | ||
var parts = str.split(options.delimiter, options.parameterLimit === Infinity ? undefined : options.parameterLimit); | ||
var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str; | ||
var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit; | ||
var parts = cleanStr.split(options.delimiter, limit); | ||
for (var i = 0; i < parts.length; ++i) { | ||
var part = parts[i]; | ||
var pos = part.indexOf(']=') === -1 ? part.indexOf('=') : part.indexOf(']=') + 1; | ||
var bracketEqualsPos = part.indexOf(']='); | ||
var pos = bracketEqualsPos === -1 ? part.indexOf('=') : bracketEqualsPos + 1; | ||
var key, val; | ||
if (pos === -1) { | ||
key = options.decoder(part); | ||
key = options.decoder(part, defaults.decoder); | ||
val = options.strictNullHandling ? null : ''; | ||
} else { | ||
key = options.decoder(part.slice(0, pos)); | ||
val = options.decoder(part.slice(pos + 1)); | ||
key = options.decoder(part.slice(0, pos), defaults.decoder); | ||
val = options.decoder(part.slice(pos + 1), defaults.decoder); | ||
} | ||
@@ -96,7 +100,7 @@ if (has.call(obj, key)) { | ||
if ( | ||
!isNaN(index) && | ||
root !== cleanRoot && | ||
String(index) === cleanRoot && | ||
index >= 0 && | ||
(options.parseArrays && index <= options.arrayLimit) | ||
!isNaN(index) | ||
&& root !== cleanRoot | ||
&& String(index) === cleanRoot | ||
&& index >= 0 | ||
&& (options.parseArrays && index <= options.arrayLimit) | ||
) { | ||
@@ -169,3 +173,3 @@ obj = []; | ||
module.exports = function (str, opts) { | ||
var options = opts || {}; | ||
var options = opts ? utils.assign({}, opts) : {}; | ||
@@ -176,2 +180,3 @@ if (options.decoder !== null && options.decoder !== undefined && typeof options.decoder !== 'function') { | ||
options.ignoreQueryPrefix = options.ignoreQueryPrefix === true; | ||
options.delimiter = typeof options.delimiter === 'string' || utils.isRegExp(options.delimiter) ? options.delimiter : defaults.delimiter; | ||
@@ -260,3 +265,3 @@ options.depth = typeof options.depth === 'number' ? options.depth : defaults.depth; | ||
if (strictNullHandling) { | ||
return encoder && !encodeValuesOnly ? encoder(prefix) : prefix; | ||
return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder) : prefix; | ||
} | ||
@@ -269,4 +274,4 @@ | ||
if (encoder) { | ||
var keyValue = encodeValuesOnly ? prefix : encoder(prefix); | ||
return [formatter(keyValue) + '=' + formatter(encoder(obj))]; | ||
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder); | ||
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder))]; | ||
} | ||
@@ -335,3 +340,3 @@ return [formatter(prefix) + '=' + formatter(String(obj))]; | ||
var obj = object; | ||
var options = opts || {}; | ||
var options = opts ? utils.assign({}, opts) : {}; | ||
@@ -416,3 +421,6 @@ if (options.encoder !== null && options.encoder !== undefined && typeof options.encoder !== 'function') { | ||
return keys.join(delimiter); | ||
var joined = keys.join(delimiter); | ||
var prefix = options.addQueryPrefix === true ? '?' : ''; | ||
return joined.length > 0 ? prefix + joined : ''; | ||
}; | ||
@@ -491,3 +499,3 @@ | ||
if (Object.prototype.hasOwnProperty.call(acc, key)) { | ||
if (has.call(acc, key)) { | ||
acc[key] = exports.merge(acc[key], value, options); | ||
@@ -501,2 +509,9 @@ } else { | ||
exports.assign = function assignSingleSource(target, source) { | ||
return Object.keys(source).reduce(function (acc, key) { | ||
acc[key] = source[key]; | ||
return acc; | ||
}, target); | ||
}; | ||
exports.decode = function (str) { | ||
@@ -524,9 +539,9 @@ try { | ||
if ( | ||
c === 0x2D || // - | ||
c === 0x2E || // . | ||
c === 0x5F || // _ | ||
c === 0x7E || // ~ | ||
(c >= 0x30 && c <= 0x39) || // 0-9 | ||
(c >= 0x41 && c <= 0x5A) || // a-z | ||
(c >= 0x61 && c <= 0x7A) // A-Z | ||
c === 0x2D // - | ||
|| c === 0x2E // . | ||
|| c === 0x5F // _ | ||
|| c === 0x7E // ~ | ||
|| (c >= 0x30 && c <= 0x39) // 0-9 | ||
|| (c >= 0x41 && c <= 0x5A) // a-z | ||
|| (c >= 0x61 && c <= 0x7A) // A-Z | ||
) { | ||
@@ -554,3 +569,6 @@ out += string.charAt(i); | ||
c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF)); | ||
out += hexTable[0xF0 | (c >> 18)] + hexTable[0x80 | ((c >> 12) & 0x3F)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]; // eslint-disable-line max-len | ||
out += hexTable[0xF0 | (c >> 18)] | ||
+ hexTable[0x80 | ((c >> 12) & 0x3F)] | ||
+ hexTable[0x80 | ((c >> 6) & 0x3F)] | ||
+ hexTable[0x80 | (c & 0x3F)]; | ||
} | ||
@@ -557,0 +575,0 @@ |
@@ -21,15 +21,19 @@ 'use strict'; | ||
var obj = {}; | ||
var parts = str.split(options.delimiter, options.parameterLimit === Infinity ? undefined : options.parameterLimit); | ||
var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str; | ||
var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit; | ||
var parts = cleanStr.split(options.delimiter, limit); | ||
for (var i = 0; i < parts.length; ++i) { | ||
var part = parts[i]; | ||
var pos = part.indexOf(']=') === -1 ? part.indexOf('=') : part.indexOf(']=') + 1; | ||
var bracketEqualsPos = part.indexOf(']='); | ||
var pos = bracketEqualsPos === -1 ? part.indexOf('=') : bracketEqualsPos + 1; | ||
var key, val; | ||
if (pos === -1) { | ||
key = options.decoder(part); | ||
key = options.decoder(part, defaults.decoder); | ||
val = options.strictNullHandling ? null : ''; | ||
} else { | ||
key = options.decoder(part.slice(0, pos)); | ||
val = options.decoder(part.slice(pos + 1)); | ||
key = options.decoder(part.slice(0, pos), defaults.decoder); | ||
val = options.decoder(part.slice(pos + 1), defaults.decoder); | ||
} | ||
@@ -62,7 +66,7 @@ if (has.call(obj, key)) { | ||
if ( | ||
!isNaN(index) && | ||
root !== cleanRoot && | ||
String(index) === cleanRoot && | ||
index >= 0 && | ||
(options.parseArrays && index <= options.arrayLimit) | ||
!isNaN(index) | ||
&& root !== cleanRoot | ||
&& String(index) === cleanRoot | ||
&& index >= 0 | ||
&& (options.parseArrays && index <= options.arrayLimit) | ||
) { | ||
@@ -135,3 +139,3 @@ obj = []; | ||
module.exports = function (str, opts) { | ||
var options = opts || {}; | ||
var options = opts ? utils.assign({}, opts) : {}; | ||
@@ -142,2 +146,3 @@ if (options.decoder !== null && options.decoder !== undefined && typeof options.decoder !== 'function') { | ||
options.ignoreQueryPrefix = options.ignoreQueryPrefix === true; | ||
options.delimiter = typeof options.delimiter === 'string' || utils.isRegExp(options.delimiter) ? options.delimiter : defaults.delimiter; | ||
@@ -144,0 +149,0 @@ options.depth = typeof options.depth === 'number' ? options.depth : defaults.depth; |
@@ -53,3 +53,3 @@ 'use strict'; | ||
if (strictNullHandling) { | ||
return encoder && !encodeValuesOnly ? encoder(prefix) : prefix; | ||
return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder) : prefix; | ||
} | ||
@@ -62,4 +62,4 @@ | ||
if (encoder) { | ||
var keyValue = encodeValuesOnly ? prefix : encoder(prefix); | ||
return [formatter(keyValue) + '=' + formatter(encoder(obj))]; | ||
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder); | ||
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder))]; | ||
} | ||
@@ -128,3 +128,3 @@ return [formatter(prefix) + '=' + formatter(String(obj))]; | ||
var obj = object; | ||
var options = opts || {}; | ||
var options = opts ? utils.assign({}, opts) : {}; | ||
@@ -209,3 +209,6 @@ if (options.encoder !== null && options.encoder !== undefined && typeof options.encoder !== 'function') { | ||
return keys.join(delimiter); | ||
var joined = keys.join(delimiter); | ||
var prefix = options.addQueryPrefix === true ? '?' : ''; | ||
return joined.length > 0 ? prefix + joined : ''; | ||
}; |
@@ -71,3 +71,3 @@ 'use strict'; | ||
if (Object.prototype.hasOwnProperty.call(acc, key)) { | ||
if (has.call(acc, key)) { | ||
acc[key] = exports.merge(acc[key], value, options); | ||
@@ -81,2 +81,9 @@ } else { | ||
exports.assign = function assignSingleSource(target, source) { | ||
return Object.keys(source).reduce(function (acc, key) { | ||
acc[key] = source[key]; | ||
return acc; | ||
}, target); | ||
}; | ||
exports.decode = function (str) { | ||
@@ -104,9 +111,9 @@ try { | ||
if ( | ||
c === 0x2D || // - | ||
c === 0x2E || // . | ||
c === 0x5F || // _ | ||
c === 0x7E || // ~ | ||
(c >= 0x30 && c <= 0x39) || // 0-9 | ||
(c >= 0x41 && c <= 0x5A) || // a-z | ||
(c >= 0x61 && c <= 0x7A) // A-Z | ||
c === 0x2D // - | ||
|| c === 0x2E // . | ||
|| c === 0x5F // _ | ||
|| c === 0x7E // ~ | ||
|| (c >= 0x30 && c <= 0x39) // 0-9 | ||
|| (c >= 0x41 && c <= 0x5A) // a-z | ||
|| (c >= 0x61 && c <= 0x7A) // A-Z | ||
) { | ||
@@ -134,3 +141,6 @@ out += string.charAt(i); | ||
c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF)); | ||
out += hexTable[0xF0 | (c >> 18)] + hexTable[0x80 | ((c >> 12) & 0x3F)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]; // eslint-disable-line max-len | ||
out += hexTable[0xF0 | (c >> 18)] | ||
+ hexTable[0x80 | ((c >> 12) & 0x3F)] | ||
+ hexTable[0x80 | ((c >> 6) & 0x3F)] | ||
+ hexTable[0x80 | (c & 0x3F)]; | ||
} | ||
@@ -137,0 +147,0 @@ |
{ | ||
"name": "qs", | ||
"description": "A querystring parser that supports nesting and arrays, with a depth limit", | ||
"homepage": "https://github.com/ljharb/qs", | ||
"version": "6.4.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ljharb/qs.git" | ||
}, | ||
"main": "lib/index.js", | ||
"contributors": [ | ||
{ | ||
"name": "Jordan Harband", | ||
"email": "ljharb@gmail.com", | ||
"url": "http://ljharb.codes" | ||
} | ||
], | ||
"keywords": [ | ||
"querystring", | ||
"qs" | ||
], | ||
"engines": { | ||
"node": ">=0.6" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@ljharb/eslint-config": "^11.0.0", | ||
"browserify": "^14.1.0", | ||
"covert": "^1.1.0", | ||
"eslint": "^3.17.0", | ||
"evalmd": "^0.0.17", | ||
"iconv-lite": "^0.4.15", | ||
"mkdirp": "^0.5.1", | ||
"parallelshell": "^2.0.0", | ||
"qs-iconv": "^1.0.4", | ||
"safe-publish-latest": "^1.1.1", | ||
"tape": "^4.6.3" | ||
}, | ||
"scripts": { | ||
"prepublish": "safe-publish-latest && npm run dist", | ||
"pretest": "npm run --silent readme && npm run --silent lint", | ||
"test": "npm run --silent coverage", | ||
"tests-only": "node test", | ||
"readme": "evalmd README.md", | ||
"lint": "eslint lib/*.js test/*.js", | ||
"coverage": "covert test", | ||
"dist": "mkdirp dist && browserify --standalone Qs lib/index.js > dist/qs.js" | ||
}, | ||
"license": "BSD-3-Clause" | ||
"name": "qs", | ||
"description": "A querystring parser that supports nesting and arrays, with a depth limit", | ||
"homepage": "https://github.com/ljharb/qs", | ||
"version": "6.5.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ljharb/qs.git" | ||
}, | ||
"main": "lib/index.js", | ||
"contributors": [ | ||
{ | ||
"name": "Jordan Harband", | ||
"email": "ljharb@gmail.com", | ||
"url": "http://ljharb.codes" | ||
} | ||
], | ||
"keywords": [ | ||
"querystring", | ||
"qs" | ||
], | ||
"engines": { | ||
"node": ">=0.6" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@ljharb/eslint-config": "^11.0.0", | ||
"browserify": "^14.4.0", | ||
"covert": "^1.1.0", | ||
"editorconfig-tools": "^0.1.1", | ||
"eslint": "^3.19.0", | ||
"evalmd": "^0.0.17", | ||
"iconv-lite": "^0.4.18", | ||
"mkdirp": "^0.5.1", | ||
"qs-iconv": "^1.0.4", | ||
"safe-publish-latest": "^1.1.1", | ||
"tape": "^4.7.0" | ||
}, | ||
"scripts": { | ||
"prepublish": "safe-publish-latest && npm run dist", | ||
"pretest": "npm run --silent readme && npm run --silent lint", | ||
"test": "npm run --silent coverage", | ||
"tests-only": "node test", | ||
"readme": "evalmd README.md", | ||
"prelint": "editorconfig-tools check * lib/* test/*", | ||
"lint": "eslint lib/*.js test/*.js", | ||
"coverage": "covert test", | ||
"dist": "mkdirp dist && browserify --standalone Qs lib/index.js > dist/qs.js" | ||
}, | ||
"license": "BSD-3-Clause" | ||
} |
117
README.md
@@ -1,7 +0,13 @@ | ||
# qs | ||
# qs <sup>[![Version Badge][2]][1]</sup> | ||
[![Build Status][3]][4] | ||
[![dependency status][5]][6] | ||
[![dev dependency status][7]][8] | ||
[![License][license-image]][license-url] | ||
[![Downloads][downloads-image]][downloads-url] | ||
[![npm badge][11]][1] | ||
A querystring parsing and stringifying library with some added security. | ||
[![Build Status](https://api.travis-ci.org/ljharb/qs.svg)](http://travis-ci.org/ljharb/qs) | ||
Lead Maintainer: [Jordan Harband](https://github.com/ljharb) | ||
@@ -36,5 +42,5 @@ | ||
assert.deepEqual(qs.parse('foo[bar]=baz'), { | ||
foo: { | ||
bar: 'baz' | ||
} | ||
foo: { | ||
bar: 'baz' | ||
} | ||
}); | ||
@@ -61,3 +67,3 @@ ``` | ||
assert.deepEqual(qs.parse('a%5Bb%5D=c'), { | ||
a: { b: 'c' } | ||
a: { b: 'c' } | ||
}); | ||
@@ -70,7 +76,7 @@ ``` | ||
assert.deepEqual(qs.parse('foo[bar][baz]=foobarbaz'), { | ||
foo: { | ||
bar: { | ||
baz: 'foobarbaz' | ||
foo: { | ||
bar: { | ||
baz: 'foobarbaz' | ||
} | ||
} | ||
} | ||
}); | ||
@@ -84,15 +90,15 @@ ``` | ||
var expected = { | ||
a: { | ||
b: { | ||
c: { | ||
d: { | ||
e: { | ||
f: { | ||
'[g][h][i]': 'j' | ||
a: { | ||
b: { | ||
c: { | ||
d: { | ||
e: { | ||
f: { | ||
'[g][h][i]': 'j' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
@@ -119,2 +125,9 @@ var string = 'a[b][c][d][e][f][g][h][i]=j'; | ||
To bypass the leading question mark, use `ignoreQueryPrefix`: | ||
```javascript | ||
var prefixed = qs.parse('?a=b&c=d', { ignoreQueryPrefix: true }); | ||
assert.deepEqual(prefixed, { a: 'b', c: 'd' }); | ||
``` | ||
An optional delimiter can also be passed: | ||
@@ -235,6 +248,6 @@ | ||
```javascript | ||
var encodedValues = qs.stringify( | ||
{ a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] }, | ||
{ encodeValuesOnly: true } | ||
) | ||
var encodedValues = qs.stringify( | ||
{ a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] }, | ||
{ encodeValuesOnly: true } | ||
); | ||
assert.equal(encodedValues,'a=b&c[0]=d&c[1]=e%3Df&f[0][0]=g&f[1][0]=h'); | ||
@@ -247,4 +260,4 @@ ``` | ||
var encoded = qs.stringify({ a: { b: 'c' } }, { encoder: function (str) { | ||
// Passed in values `a`, `b`, `c` | ||
return // Return encoded string | ||
// Passed in values `a`, `b`, `c` | ||
return // Return encoded string | ||
}}) | ||
@@ -259,4 +272,4 @@ ``` | ||
var decoded = qs.parse('x=z', { decoder: function (str) { | ||
// Passed in values `x`, `z` | ||
return // Return decoded string | ||
// Passed in values `x`, `z` | ||
return // Return decoded string | ||
}}) | ||
@@ -328,2 +341,8 @@ ``` | ||
The query string may optionally be prepended with a question mark: | ||
```javascript | ||
assert.equal(qs.stringify({ a: 'b', c: 'd' }, { addQueryPrefix: true }), '?a=b&c=d'); | ||
``` | ||
The delimiter may be overridden with stringify as well: | ||
@@ -350,3 +369,3 @@ | ||
function alphabeticalSort(a, b) { | ||
return a.localeCompare(b); | ||
return a.localeCompare(b); | ||
} | ||
@@ -362,13 +381,13 @@ assert.equal(qs.stringify({ a: 'c', z: 'y', b : 'f' }, { sort: alphabeticalSort }), 'a=c&b=f&z=y'); | ||
function filterFunc(prefix, value) { | ||
if (prefix == 'b') { | ||
// Return an `undefined` value to omit a property. | ||
return; | ||
} | ||
if (prefix == 'e[f]') { | ||
return value.getTime(); | ||
} | ||
if (prefix == 'e[g][0]') { | ||
return value * 2; | ||
} | ||
return value; | ||
if (prefix == 'b') { | ||
// Return an `undefined` value to omit a property. | ||
return; | ||
} | ||
if (prefix == 'e[f]') { | ||
return value.getTime(); | ||
} | ||
if (prefix == 'e[g][0]') { | ||
return value * 2; | ||
} | ||
return value; | ||
} | ||
@@ -452,1 +471,17 @@ qs.stringify({ a: 'b', c: 'd', e: { f: new Date(123), g: [2] } }, { filter: filterFunc }); | ||
``` | ||
[1]: https://npmjs.org/package/qs | ||
[2]: http://versionbadg.es/ljharb/qs.svg | ||
[3]: https://api.travis-ci.org/ljharb/qs.svg | ||
[4]: https://travis-ci.org/ljharb/qs | ||
[5]: https://david-dm.org/ljharb/qs.svg | ||
[6]: https://david-dm.org/ljharb/qs | ||
[7]: https://david-dm.org/ljharb/qs/dev-status.svg | ||
[8]: https://david-dm.org/ljharb/qs?type=dev | ||
[9]: https://ci.testling.com/ljharb/qs.png | ||
[10]: https://ci.testling.com/ljharb/qs | ||
[11]: https://nodei.co/npm/qs.png?downloads=true&stars=true | ||
[license-image]: http://img.shields.io/npm/l/qs.svg | ||
[license-url]: LICENSE | ||
[downloads-image]: http://img.shields.io/npm/dm/qs.svg | ||
[downloads-url]: http://npm-stat.com/charts.html?package=qs |
@@ -5,2 +5,3 @@ 'use strict'; | ||
var qs = require('../'); | ||
var utils = require('../lib/utils'); | ||
var iconv = require('iconv-lite'); | ||
@@ -308,2 +309,9 @@ | ||
t.test('allows for query string prefix', function (st) { | ||
st.deepEqual(qs.parse('?foo=bar', { ignoreQueryPrefix: true }), { foo: 'bar' }); | ||
st.deepEqual(qs.parse('foo=bar', { ignoreQueryPrefix: true }), { foo: 'bar' }); | ||
st.deepEqual(qs.parse('?foo=bar', { ignoreQueryPrefix: false }), { '?foo': 'bar' }); | ||
st.end(); | ||
}); | ||
t.test('parses an object', function (st) { | ||
@@ -515,2 +523,12 @@ var input = { | ||
t.test('receives the default decoder as a second argument', function (st) { | ||
st.plan(1); | ||
qs.parse('a', { | ||
decoder: function (str, defaultDecoder) { | ||
st.equal(defaultDecoder, utils.decode); | ||
} | ||
}); | ||
st.end(); | ||
}); | ||
t.test('throws error with wrong decoder', function (st) { | ||
@@ -522,2 +540,11 @@ st.throws(function () { | ||
}); | ||
t.test('does not mutate the options argument', function (st) { | ||
var options = {}; | ||
qs.parse('a[b]=true', options); | ||
st.deepEqual(options, {}); | ||
st.end(); | ||
}); | ||
t.end(); | ||
}); |
@@ -5,2 +5,3 @@ 'use strict'; | ||
var qs = require('../'); | ||
var utils = require('../lib/utils'); | ||
var iconv = require('iconv-lite'); | ||
@@ -21,2 +22,12 @@ | ||
t.test('adds query prefix', function (st) { | ||
st.equal(qs.stringify({ a: 'b' }, { addQueryPrefix: true }), '?a=b'); | ||
st.end(); | ||
}); | ||
t.test('with query prefix, outputs blank string given an empty object', function (st) { | ||
st.equal(qs.stringify({}, { addQueryPrefix: true }), ''); | ||
st.end(); | ||
}); | ||
t.test('stringifies a nested object', function (st) { | ||
@@ -457,2 +468,12 @@ st.equal(qs.stringify({ a: { b: 'c' } }), 'a%5Bb%5D=c'); | ||
t.test('receives the default encoder as a second argument', function (st) { | ||
st.plan(2); | ||
qs.stringify({ a: 1 }, { | ||
encoder: function (str, defaultEncoder) { | ||
st.equal(defaultEncoder, utils.encode); | ||
} | ||
}); | ||
st.end(); | ||
}); | ||
t.test('throws error with wrong encoder', function (st) { | ||
@@ -570,2 +591,10 @@ st.throws(function () { | ||
t.test('does not mutate the options argument', function (st) { | ||
var options = {}; | ||
qs.stringify({}, options); | ||
st.deepEqual(options, {}); | ||
st.end(); | ||
}); | ||
t.end(); | ||
}); |
@@ -23,1 +23,13 @@ 'use strict'; | ||
}); | ||
test('assign()', function (t) { | ||
var target = { a: 1, b: 2 }; | ||
var source = { b: 3, c: 4 }; | ||
var result = utils.assign(target, source); | ||
t.equal(result, target, 'returns the target'); | ||
t.deepEqual(target, { a: 1, b: 3, c: 4 }, 'target and source are merged'); | ||
t.deepEqual(source, { b: 3, c: 4 }, 'source is untouched'); | ||
t.end(); | ||
}); |
Sorry, the diff of this file is not supported yet
111472
476
2023