Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

qs-kit

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

qs-kit - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

45

bdd-spec.md

@@ -9,3 +9,3 @@ # TOC

# Parse
Scalar usage.
Scalar.

@@ -26,2 +26,43 @@ ```js

Array 'autoPush' option.
```js
options = { autoPush: true } ;
expect( qs.parse( "key=one&key=two&key=three" ) ).to.eql( { key: 'three' } ) ;
expect( qs.parse( "key=one&key=two&key=three" , options ) ).to.eql( { key: [ 'one' , 'two' , 'three' ] } ) ;
```
Array with the 'brackets' option.
```js
var options = { brackets: true } ;
expect( qs.parse( "key=[one,two,three]" ) ).to.eql( { key: "[one,two,three]" } ) ;
expect( qs.parse( "key=[one,two,three]" , options ) ).to.eql( { key: [ 'one' , 'two' , 'three' ] } ) ;
```
Array 'keyPath' option.
```js
options = { keyPath: true } ;
expect( qs.parse( "a[0]=val&a[1]=val2" ) ).to.eql( { "a[0]": 'val' , "a[1]": 'val2' } ) ;
expect( qs.parse( "a[0]=val&a[1]=val2" , options ) ).to.eql( { a: [ 'val' , 'val2' ] } ) ;
```
Object 'keyPath' option.
```js
options = { keyPath: true } ;
expect( qs.parse( "a.b=val" ) ).to.eql( { "a.b": 'val' } ) ;
expect( qs.parse( "a.b=val" , options ) ).to.eql( { a: { b: 'val' } } ) ;
```
'keyPath' and 'autoPush' option.
```js
expect( qs.parse( "a.b=val&a.b=val2" ) ).to.eql( { "a.b": "val2" } ) ;
expect( qs.parse( "a.b=val&a.b=val2" , { keyPath: true } ) ).to.eql( { a: { b: "val2" } } ) ;
expect( qs.parse( "a.b=val&a.b=val2" , { autoPush: true } ) ).to.eql( { "a.b": [ "val" , "val2" ] } ) ;
expect( qs.parse( "a.b=val&a.b=val2" , { keyPath: true , autoPush: true } ) ).to.eql( { a: { b: [ "val" , "val2" ] } } ) ;
```
<a name="stringify"></a>

@@ -31,3 +72,3 @@ # Stringify

# Historical bugs
Bad query string: =one=two.
Bad query string.

@@ -34,0 +75,0 @@ ```js

38

lib/qs.js

@@ -32,9 +32,12 @@ /*

This modification allow object notation and right-side array notation:
If option 'keyPath' is on, this modification allow object dot notation and left-hand-side array notation:
a.b=1&a.c=2 -> { a: { b: '1' , c: '2' } }
a[0]=one&a[1]=two -> { a: [ 'one' , 'two' ] }
If option 'rightHandSideBrackets' is on:
If option 'brackets' is on:
a=[b,c,d] -> { a: [ 'b' , 'c' , 'd' ] }
If option 'autoPush' is on:
a=b&a=c&a=d -> { a: [ 'b' , 'c' , 'd' ] }
Still, not everything is possible.

@@ -62,3 +65,3 @@ */

Modified from original 'querystring' core module: option 'maxKeys' -> 'maxItems'
Modified API from original 'querystring' core module: option 'maxKeys' -> 'maxItems'
*/

@@ -71,7 +74,7 @@ QueryString.parse = QueryString.decode = function( str , options )

var i , iMax , j , jMax , x , idx , k , v , count = 0 , obj = {} ;
var sep = options.separator || '&' ;
var eq = options.equal || '=' ;
var i , iMax , j , jMax , count = 0 , obj = {} ;
if ( typeof str !== 'string' || str.length === 0 ) { return obj ; }

@@ -93,8 +96,7 @@

}
for ( i = 0 ; i < iMax && count < maxItems ; i ++ , count ++ )
{
var x = str[ i ].replace( regexp , '%20' ) ,
idx = x.indexOf( eq ) ,
k, v ;
x = str[ i ].replace( regexp , '%20' ) ;
idx = x.indexOf( eq ) ;

@@ -107,5 +109,7 @@ if ( idx === -1 ) { continue ; }

//console.log( "k:",k ) ;
v = x.substring( idx + 1 ) ;
if ( options.rightHandSideBrackets && v[ 0 ] === '[' && v[ v.length - 1 ] === ']' )
if ( options.brackets && v[ 0 ] === '[' && v[ v.length - 1 ] === ']' )
{

@@ -134,3 +138,13 @@ if ( v.length === 2 )

//console.log( "tree.path.set( obj , k , v ):\nobj:" , obj , "\nk:" , k , "\nv:" , v ) ;
tree.path.set( obj , k , v ) ;
if ( options.keyPath )
{
if ( options.autoPush ) { tree.path.autoPush( obj , k , v ) ; }
else { tree.path.set( obj , k , v ) ; }
}
else
{
if ( obj[ k ] === undefined || ! options.autoPush ) { obj[ k ] = v ; }
else if ( Array.isArray( obj[ k ] ) ) { obj[ k ].push( v ) ; }
else { obj[ k ] = [ obj[ k ] , v ] ; }
}
}

@@ -172,3 +186,3 @@

{
if ( options.rightHandSideBrackets )
if ( options.brackets )
{

@@ -175,0 +189,0 @@ vLength = v.length ;

{
"name": "qs-kit",
"version": "0.3.0",
"version": "0.4.0",
"description": "A query string manipulation toolbox.",

@@ -10,8 +10,8 @@ "main": "lib/qs.js",

"dependencies": {
"tree-kit": "^0.5.6"
"tree-kit": "^0.5.19"
},
"devDependencies": {
"expect.js": "^0.3.1",
"jshint": "^2.5.6",
"mocha": "^2.2.4"
"jshint": "^2.9.1",
"mocha": "^2.4.5"
},

@@ -18,0 +18,0 @@ "scripts": {

@@ -22,3 +22,3 @@

# Parse
Scalar usage.
Scalar.

@@ -39,2 +39,43 @@ ```js

Array 'autoPush' option.
```js
options = { autoPush: true } ;
expect( qs.parse( "key=one&key=two&key=three" ) ).to.eql( { key: 'three' } ) ;
expect( qs.parse( "key=one&key=two&key=three" , options ) ).to.eql( { key: [ 'one' , 'two' , 'three' ] } ) ;
```
Array with the 'brackets' option.
```js
var options = { brackets: true } ;
expect( qs.parse( "key=[one,two,three]" ) ).to.eql( { key: "[one,two,three]" } ) ;
expect( qs.parse( "key=[one,two,three]" , options ) ).to.eql( { key: [ 'one' , 'two' , 'three' ] } ) ;
```
Array 'keyPath' option.
```js
options = { keyPath: true } ;
expect( qs.parse( "a[0]=val&a[1]=val2" ) ).to.eql( { "a[0]": 'val' , "a[1]": 'val2' } ) ;
expect( qs.parse( "a[0]=val&a[1]=val2" , options ) ).to.eql( { a: [ 'val' , 'val2' ] } ) ;
```
Object 'keyPath' option.
```js
options = { keyPath: true } ;
expect( qs.parse( "a.b=val" ) ).to.eql( { "a.b": 'val' } ) ;
expect( qs.parse( "a.b=val" , options ) ).to.eql( { a: { b: 'val' } } ) ;
```
'keyPath' and 'autoPush' option.
```js
expect( qs.parse( "a.b=val&a.b=val2" ) ).to.eql( { "a.b": "val2" } ) ;
expect( qs.parse( "a.b=val&a.b=val2" , { keyPath: true } ) ).to.eql( { a: { b: "val2" } } ) ;
expect( qs.parse( "a.b=val&a.b=val2" , { autoPush: true } ) ).to.eql( { "a.b": [ "val" , "val2" ] } ) ;
expect( qs.parse( "a.b=val&a.b=val2" , { keyPath: true , autoPush: true } ) ).to.eql( { a: { b: [ "val" , "val2" ] } } ) ;
```
<a name="stringify"></a>

@@ -44,3 +85,3 @@ # Stringify

# Historical bugs
Bad query string: =one=two.
Bad query string.

@@ -47,0 +88,0 @@ ```js

@@ -44,3 +44,3 @@ /*

it( "Scalar usage" , function() {
it( "Scalar" , function() {
expect( qs.parse( "k=v" ) ).to.eql( { k: "v" } ) ;

@@ -56,2 +56,33 @@ expect( qs.parse( "key=value" ) ).to.eql( { key: "value" } ) ;

} ) ;
it( "Array 'autoPush' option" , function() {
options = { autoPush: true } ;
expect( qs.parse( "key=one&key=two&key=three" ) ).to.eql( { key: 'three' } ) ;
expect( qs.parse( "key=one&key=two&key=three" , options ) ).to.eql( { key: [ 'one' , 'two' , 'three' ] } ) ;
} ) ;
it( "Array with the 'brackets' option" , function() {
var options = { brackets: true } ;
expect( qs.parse( "key=[one,two,three]" ) ).to.eql( { key: "[one,two,three]" } ) ;
expect( qs.parse( "key=[one,two,three]" , options ) ).to.eql( { key: [ 'one' , 'two' , 'three' ] } ) ;
} ) ;
it( "Array 'keyPath' option" , function() {
options = { keyPath: true } ;
expect( qs.parse( "a[0]=val&a[1]=val2" ) ).to.eql( { "a[0]": 'val' , "a[1]": 'val2' } ) ;
expect( qs.parse( "a[0]=val&a[1]=val2" , options ) ).to.eql( { a: [ 'val' , 'val2' ] } ) ;
} ) ;
it( "Object 'keyPath' option" , function() {
options = { keyPath: true } ;
expect( qs.parse( "a.b=val" ) ).to.eql( { "a.b": 'val' } ) ;
expect( qs.parse( "a.b=val" , options ) ).to.eql( { a: { b: 'val' } } ) ;
} ) ;
it( "'keyPath' and 'autoPush' option" , function() {
expect( qs.parse( "a.b=val&a.b=val2" ) ).to.eql( { "a.b": "val2" } ) ;
expect( qs.parse( "a.b=val&a.b=val2" , { keyPath: true } ) ).to.eql( { a: { b: "val2" } } ) ;
expect( qs.parse( "a.b=val&a.b=val2" , { autoPush: true } ) ).to.eql( { "a.b": [ "val" , "val2" ] } ) ;
expect( qs.parse( "a.b=val&a.b=val2" , { keyPath: true , autoPush: true } ) ).to.eql( { a: { b: [ "val" , "val2" ] } } ) ;
} ) ;
} ) ;

@@ -63,3 +94,3 @@

it( "Scalar usage" ) ;
it( "Scalar" ) ;
it( "String encoded" ) ;

@@ -72,3 +103,3 @@ } ) ;

it( "Bad query string: =one=two" , function() {
it( "Bad query string" , function() {
// should throw

@@ -75,0 +106,0 @@ expect( function() { qs.parse( "=one=two" ) ; } ).to.throwException() ;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc